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

Magento: Get sub categories and product count

This article shows how to get sub categories of a particular category and the number of products (product count) present in the sub categories. Suppose, you have a category named Furniture. The sub categories under Furniture are Living Room and Bedroom. Now, you want to show the sub categories under Funiture and the products associated … Read more

Magento: How to enable backorders?

Difference between backorder and pre-order A backorder is for an item that was in stock previously but is temporarily out of stock. A pre-order is for an item that has not been released yet. Scenario for backorder: For example, a customer orders 3 items. One item is not in stock. Shouldn’t I be able to … Read more