Magento: Create Watermark Image

It’s very very easy to create watermark image with Magento code. The Varien_Image class does the magic. The function watermark creates watermark on the image. Here is the code: $mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg'; $watermarkImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'watermark.jpg'; $image = new Varien_Image($mainImage); … Read more

Magento: Easily add breadcrumbs to any page

Breadcrumbs are very useful for user navigation. Breadcrumbs for product page, category page, etc. are created by default Magento code. The following code will show breadcrumbs created by Magento. You can print the following code anywhere in php or phtml files. echo $this->getLayout()->getBlock('breadcrumbs')->toHtml(); You can create you own breadcrumbs as well. Like, you may need … Read more

Magento: How to upload file?

In adminhtml, you might have the following code in any form. Here ‘logo‘ is the name of the input type file. Or, you may have any HTML Form with the File field in the frontend page. Remember that your form’s enctype should be multipart/form-data. $fieldset->addField('logo', 'file', array( 'label' => 'Small Logo', 'required' => false, 'name' … Read more

Magento: How to set and get registry?

Registry means registering or creating a new variable which is to be used later on in the project/code. The registry variable acts as a global variable which can be used anywhere. Here are the functions to register, unregister and fetch a registry variable. register(): register a variable unregister(): unregister a variable registry(‘VARIABLE_NAME’): fetch registry variable … Read more

Magento: Read config XML nodes

Here, I will be showing you how you can read XML nodes from config.xml file of your module. It’s through the Magento way with Mage::getConfig()->getNode() function. :) Here is the XML code of my config.xml file. I will be reading the nodes of this XML file. <default> <catalog> <mypage> <name>myname</name> <age>100</age> <address_one>earth</address_one> </mypage> </catalog> </default> … Read more

Magento: Read Write XML

I will be using Varien_Simplexml_Element class to read write xml nodes. The path to this class file is lib/Varien/Simplexml/Element.php Here is a sample XML file which I am going to read through Magento code. I will also be adding an XML node to the following XML data. <?xml version="1.0"?> <config> <modules> <MyNamespace_MyModule> <version>0.1.0</version> </MyNamespace_MyModule> </modules> … Read more

Magento: Access denied in admin of custom module

I was building a custom module in Magento. I had created a system.xml file for storing configuration data from admin. From the below system.xml file, you can see that I have created a section named ‘My Module Name‘ which can be accessed from Admin –> System –> Configuration. In the file below, I have just … Read more

Magento: Set/Change page layout, title tag, meta keywords and description

Earlier in this blog, I had written about setting title, keywords, and description from xml layout file. In this article, I will be showing, how you can set/change title, keywords and description of any page programmatically. I mean, by php code. Here is the layout XML file. I have set title and template in the … Read more