May 10, 2013

Magento add attribute to category

Adding category attribute in Magento is same as we add for product and customer. Here in this post I will create a custom module which will add your new custom category attribute in Magento. So let’s start with the module:

1.) As usual, create an XML file in app/etc/modules/ directory, I will name it Namespace_Module.xml
Paste below code in it changing the Namespace and Module as you want.

<?xml version="1.0"?>

2.) Second step would be to create a file config.xml in app/code/local/Namespace/Module/etc/ directory. Create all the directories required get there. Paste the below code in it making sure you have changed Namespace and Module with your naming.

<?xml version="1.0"?>

I have only included setup class and connections as those are the only things we will need to execute our script which will insert the custom attribute to category in our Magento project.

3.) Here comes main file, which will actually add attribute to category. We will put below code in app/code/local/Namespace/Module/sql/module_setup/mysql4-install-0.1.0.php

$this->addAttribute('catalog_category', 'your_custom_attribute_here', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'Custom Category attribute label',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

We have used minimal things to create this module and add attribute to category. You can go further and do more additions from this.

After clearing cache, you will see that your new custom attribute appear in Category pages in frontend as well as Manage Categories section in backend. HTH!

1 Comment

  • this is not working on magento 1.7.0 .

Leave a comment


Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!




Magento top 50 contributors

Magento top 50 contributors