How to add dropdown attribute for category in magento

12 / Mar / 2013 by amatya 3 comments

Adding attributes from admin is simple in magento. But this feature is only for products. Some times there is requirement to add custom attribute for category to customize magento. Following is the code to add dropdown attribute for category.

[php]
<?php

$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);

$setup->addAttribute(‘catalog_category’, ‘category_color’, array(
‘group’ => ‘General’,
‘input’ => ‘select’,
‘type’ => ‘varchar’,
‘label’ => ‘Border Color’,
‘option’ => array (
‘value’ => array(‘optionone’=>array(0=>’red’),’optiontwo’=>array(0=>’green’),
‘optionthree’=>array(0=>’blue’),’optionfour’=>array(0=>’black’))
),

‘backend’ => ‘eav/entity_attribute_backend_array’,
‘visible’ => 1,
‘required’ => 0,
‘user_defined’ => 1,
‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();
?>
[/php]

If you want to add new tab in category page in admin then what you need to do is just replace following line.

[php]
‘group’ => ‘General’
[/php]

With

[php]
‘group’ => ‘Your Custom Tab’
[/php]

Hope this will help you 🙂


Regards,
Amatya Trivedi
amatya@intelligrape.com

FOUND THIS USEFUL? SHARE IT

comments (3)

  1. Nicolás

    Great tutorial, it works fine, but I have a problem.
    The values beeing saved are not, ‘optionone’, ‘optiontwo’, etc, the select in the admin panel creates some custom values so I don’t know how to access those values then.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *