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

Magento: Set title, keywords and description in your module

Suppose, you have created a new module or you have an existing module. You have a frontend page for your module. You want to set or change title, keywords, and/or description of your module page. Well, you can do so by adding few lines of code in layout xml file of your module. The layout … Read more

Magento: Get manufacturer name and id from product

Suppose, you have the product data, i.e. you have a loaded product information stored in a variable named ‘$_product‘. Now, when you type $_product->getManufacturer() , you will get the manufacturer ID. To get the manufacturer name, you have to use the following: $_product->getAttributeText(‘manufacturer’). Below is the complete code: Get Manufacturer Name and ID from Product … Read more

Magento: Get list of all manufacturers

Manufacturer is a core product attribute in Magento. This article shows how you can fetch the manufacturer attribute and all it’s option value and id. Here is the code to list all the option values of manufacturer attribute: /** * Get list of all manufacturers */ $_productId = 11; // Your Product ID $_product = … Read more

Magento: How to get controller, module, action and router name?

You can easily get controller name, action name, router name and module name in any template file or class file. IN TEMPLATE FILES $this->getRequest() can be used in template (phtml) files. Here is the code: /** * get Controller name */ $this->getRequest()->getControllerName(); /** * get Action name, i.e. the function inside the controller */ $this->getRequest()->getActionName(); … Read more

Magento: How to filter product collection using 2 or more category filters?

Suppose, you have a product collection and you want to filter it by category. Suppose, you want to filter it by more than one category. You can use addCategoryFilter if you have only one category. But, what if you want to filter by more than one category? Category ids are stored for product in a … Read more

Magento: Create, Read, Delete Cookie

Here is the code to create, read, and delete cookie in Magento. Mage_Core_Model_Cookie class contains functions to set, get and delete cookie. /** * set cookie * name and value are mandatory; other parameters are optional and can be set as null * $period = cookie expire date */ Mage::getModel('core/cookie')->set($name, $value, $period, $path, $domain, $secure, … Read more

Magento: Get current and parent category

This article shows how to get category information (category name, id, description, url, etc.) of the category page you are in. Along with the information of the parent category of the currently viewed category. Get current category // Get current category $currentCategory = Mage::registry('current_category'); Print current category array < pre> $currentCategory = Mage::registry('current_category'); echo " … Read more