Magento: Rotate image

Here is a quick tip to rotate image to any degree of your choice in Magento. The rotate function of Varien_Image does the magic :) Here goes the code: $mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg'; $image = new Varien_Image($mainImage); // rotate image with the angle of your choice // rotate($angle) … Read more

Magento: Admin Controller Override

I had to override adminhtml controller class (Mage_Adminhtml_System_ConfigController) with my module’s controller class (MyNamespace_MyModule_ConfigController). It was really tough to find the right solution. I googled, searched in magentocommerce forum and found a lot of solutions. But they didn’t work for me. After searching & trying more, I got some work done with the following piece … Read more

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