Adding a category attribute in Magento

I was looking for a code in order to create category attributes in Magento and found a post from Mukesh Chapagain where he explains in a really easy way how to do so. But it didn’t work for me. I’m supposing that the problem is the way how we call the installer in the mysql php file. So I want to explain here, step by step, how I did to make it work:

Create the module

Create a file YourCompany_CategoryAttribute.xml file with the following code and place it in your app/etc/modules folder:


Now create the folder structure for your module. Basically, you need to create the folders: app/code/local/YourCompany/etc and app/code/local/YourCompany/sql/categoryattributesetup. In the first one you have to place a config.xml with this content:

<?xml version=&quot;1.0&quot;?>

Finally, create the mysql php file that is going to create the category attribute:



$this->addAttribute('catalog_category', 'new_attribute', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'New attribute',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined'  => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,



This will create a new tab on the category edit page named «General» and inside it you’ll find the new attribute name «New attribute».

Leave a Reply

Your email address will not be published.