How to add custom field/attribute in magento category?

Posted: July 19, 2012 in Magento, Version 1.3.*, Version 1.4.*, Version 1.6.*

Add custom Field/attribute to category using script in magento
$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);
// below code will add text attribute
$setup->addAttribute(‘catalog_category’, ‘attribute_code’, array(
‘group’         => ‘General’,//if you add custom group name than it will show attribute in custom tab
‘input’         => ‘text’,
‘type’          => ‘varchar’,
‘label’         => ‘Attribute label’,
‘backend’       => ”,
‘visible’       => 1,
‘required’      => 0,
‘user_defined’ => 1,
‘global’        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

// below code will add yes/no attribute

$setup->addAttribute(‘catalog_category’, ‘attribute_code’,  array(
‘type’     => ‘int’,
‘label’    => ‘Attribute label’,
‘input’    => ‘select’,
‘source’   => ‘eav/entity_attribute_source_boolean’,
‘global’   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
‘required’ => false,
‘default’  => 1,
‘user_defined’  => 1,
‘default’  => 0

// below code will use to add image attribute

$setup->addAttribute(‘catalog_category’, ‘attribute_code’,  array(
‘group’         => ‘General’,
‘type’     => ‘varchar’,
‘label’    => ‘Attribute Label’,
‘input’    => ‘image’,
‘source’   => ‘eav/entity_attribute_source_boolean’,
‘global’        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
‘required’ => false,
‘backend’ => ‘catalog/category_attribute_backend_image’,
‘frontend_input’ =>”,
‘default’  => 1,
‘visible’       => 1,
‘user_defined’  => 1,


‘attribute_code’ will be replace with your own attribute code and same way ‘Attribute Label’ will be replace with attribute label.

Once you execute above script, it will automatically creates attribute.
Don’t forget to do re-index. Else it will not show in frontend.


Bijal Bhavsar 🙂


  1. karan yadav says:

    I Try But Not Work….

    Please Help Me……

  2. Gareth says:

    Hi thanks for this, it’s very helpful. Can you tell me if this is the best practice method for future compatibility? It uses the Magento API I presume so should be but was wondering if you knew if it was the Magento approved, stable method?

    I am using it from a separate file in the Magento root dir with:

    require_once ‘app/Mage.php’;

    at the top if that has any bearing on my question.

    Many thanks.

    • Bijal Bhavsar says:

      Thanks for reading my post.

      If you create seperate file in magento root dir, It will be wrong practice, you need to create module to run sql script, like magento do. I need to check for Magento API, but its an attribute, so i guess it will work in API as well.

      Bijal Bhavsar 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s