How to add Category Attributes in Magento

Sunday, September 23, 2012
We can add attributes to categories by running sql query in our database ,but this is not a good way of doing. We can use better way that is, set up scripts feature of magento.
We can create a custom module and add a mysql set up file inside below location:
CustomNamespace/CustomModule/sql/custommodule_setup/
Add the following code inside it to add category attributes :
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$setup->addAttribute('catalog_category', 'custom_category_attribute', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'Custom New Category Attribute',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();

This code will create a attribute code "custom_category_attribute" and label "Custom New Category Attribute" in Manage Category section of admin panel. If you have any further queries,feel free to commenting.

0 comments:

Post a Comment