Magento: Adding category attributes

Here, I will be showing you how you can add attributes for your categories in Magento.

From the admin panel, you can only add attributes to product. To add attributes to category, you need to write sql query in your phpmyadmin or a better way would be creating a new custom module and adding attributes to category from the mysql setup file of the module.

By mysql setup file, I mean the file inside the directory YourNamespace/YourModule/sql/yourmodule_setup/

Create a new module and write the following in your module’s mysql setup file.


$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

$setup->addAttribute('catalog_category', 'my_attribute', array(
	'group'     	=> 'General',
	'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'My Attribute',		  
	'backend'       => '',
	'visible'       => 1,	
	'required'		=> 0,
	'user_defined' => 1,	
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,   	
));

$installer->endSetup();

The above code will create a category with the code ‘my_attribute‘ and lable ‘My Attribute‘. You can view it under Admin Panel –> Catalog –> Manage Categories –> General Information

Hope this helps. Thanks.