How to add new custom category attribute in Magento

Featured Image

Sometimes you need to extend functionality of Magento categories. There is several ways to do that, I will show you how it can be done.
You can do that by modifying and adding data into some of tables directly, but it can be waste of time if you don’t know what you are doing.
This post will describe how you can add new custom category attribute in your Magento store via sql_setup script.

MySQL setup script will look something like this, it depends on your needs and how you would like to configure your new attribute:

$installer = $this;
$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('catalog_category', 'new_cat_attrb',  array(
    'type'     => 'int',
    'label'    => 'New Category Attribute',
    'input'    => 'text',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => false,
    'default'           => 0
    '11'					//last Magento's attribute position in General tab is 10
$attributeId = $installer->getAttributeId($entityTypeId, 'new_cat_attrb');
INSERT INTO `{$installer->getTable('catalog_category_entity_int')}`
(`entity_type_id`, `attribute_id`, `entity_id`, `value`)
    SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
        FROM `{$installer->getTable('catalog_category_entity')}`;
//this will set data of your custom attribute for root category
//this will set data of your custom attribute for default category

In your config.xml file of your module you will need to add this part in order to install correctly your new category attribute:


Pay attention on class tag here, class must be: “Mage_Catalog_Model_Resource_Eav_Mysql4_Setup”.

If you did this correctly, you will get something like this:

Enjoy coding!


Care to rate this post?


Vedran Subotic

Ex. Inchooer

Vedran worked in Inchoo from 2009 to 2012 as a backend developer.

Other posts from this author

Discussion 76 Comments

1 2
Add Comment
  1. John

    Just to make sure:









    The mysql setup file:


    Does is look correct?

  2. John

    Sorry, the xml tags didnt seem to render.

    Are the file paths right though?

  3. Haney

    @Senthil: To create a new tabpage, I copied the core/Mage/Adminhtml/Block/Catalog folder to local/Mage/Adminhtml/Block/Catalog. And then under Catalog folder, in Category/Tabs.php, duplicated the ‘Category Products’ as:

    $this->addTab(‘products’, array(
    ‘label’ => Mage::helper(‘catalog’)->__(‘Category Products’),
    ‘content’ => $this->getLayout()->createBlock(‘adminhtml/catalog_category_tab_product’, ‘category.product.grid’)->toHtml(),


    $this->addTab(‘categories’, array(
    ‘label’ => Mage::helper(‘catalog’)->__(‘Associated Categories.’),
    ‘content’ => $this->getLayout()->createBlock(‘adminhtml/catalog_category_tab_category’, ‘category.category.grid’)->toHtml(),

    At the end, I literally duplicate the local/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php to local/Mage/Adminhtml/Block/Catalog/Category/Tab/Category.php. In Category.php, instead of:

    $collection = Mage::getModel(‘catalog/product’)->getCollection()
    I am loading category collection as:

    $collection = Mage::getModel(‘catalog/category’)->getCollection()

    Now it is showing me ‘Associated Categories tabpage under categories and it loads categories but they don’t load as I’m expecting. When I click on add new category, it shows all the categories under ‘Associated Categories’ but when I click on any of the categories, they disappear. I want to be able to link any category to any other category. Also on clicking ‘Reset Filter’ button, it loads the products.

  4. Konstantin Ivanov

    And how can I do so in this category, the products have no prices, but to make a client request. I have install question extensions in products, if you can help me for other things – the abolition of purchase button and paste text and only for this category. Thank you in advance.

  5. shubh

    How can i get attribute value of attribute

  6. @shubh

    Could you pls expalin somewhat clear.

  7. sunil

    I need a help regarding custom category attribute
    I want to add select dropdown as a custom category attribute
    can you tell me the how to do that ?
    how to assign values to that dropdown?


  8. prasad

    Hi, i am new to Magento . I am try to add custom attribute to product. I need help to create a custom attribute in product using sql setup.

  9. Hy,

    To create a new attribute for a product you could use the following snippet inside your install script

    $this->addAttribute('catalog_product', 'id_of_attribute', array(
        'group'                    => 'General',
        'type'                     => 'int',
        'input'                    => 'select',
        'label'                    => 'Attribute_Label',
        'global'                   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // or other scope
        'visible'                  => 1,
        'required'                 => 0,
        'visible_on_front'         => 0,
        'is_html_allowed_on_front' => 0,
        'is_configurable'          => 0,
        'source'                   => 'eav/entity_attribute_source_boolean', //select the appropriate source
        'searchable'               => 0,
        'filterable'               => 0,
        'comparable'               => 0,
        'unique'                   => false,
        'user_defined'             => true,
        'is_user_defined'          => true,
        'used_in_product_listing'  => true

    I hope it helps you

  10. Iwo

    I copied all the example and it didn’t work :-( Nothing new shown up in ‘General Information’ tab. I only managed to create text attribute in “General” tab (NOT “General Information”):

    $installer = $this;
    $installer->addAttribute('catalog_category', 'priority', array(
        'type' => 'varchar',
        'label' => 'Priority',
        'input' => 'text',
        'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'visible' => true,
        'required' => false,
        'user_defined' => false,
        'default' => ''
  11. Yaroslav

    Hi, I’m new in magento, as many more and I was looking through the code to see if can fits my needs but for what I see seems to me that it does not. I asked already on Magento forums and on StackOverflow, I post here the link to the question to see if anyone can help:

  12. Anshuman

    For all who have problem in adding attribute to General Information Tab
    go eav_entity_attribute table find your attribute id and change attribute_group_id from 3 to 4

  13. Lee

    Really useful, thanks. Is is possible to use this to allow adding of a file upload.

    I need to assign a downloadable PDF to each category. Any ideas greatly appreciated.

  14. Tom

    certainly useful. thank you. I am also looking for a solution to assign an attribute of downloadable PDF to each product.

  15. Many thnx. This info helped big time. Not all info is correct, id’s have changed in Magento many times over but all in all good info.

  16. Dimitris

    is there a way to work with this extra field through REST API?
    Coz i give a try with no success.

  17. i have create a module and i create a attribute in manage category that is maltipalselect but i don’t know that where can i change save acction

  18. Dimitris

    what do you Mean Punnet?
    what action to change?
    its not very clear to me at least

  19. Jeremy Bass

    Any chance that you could post the example files? Trying to follow this is requiring a lot of fill in the blanks. Personally I’m a learn from seeing the whole thing kind of guy. Really interested in learning what to do. Thanks for the how to here. Cheers -Jeremy

  20. Jeremy Bass

    Got it to work but it’s not like the suggested code here.. This is what I had to do but I’d like to know why this is off from the post. Cheers

    Making a highlight category yes/no bool

    CompanyName = Pleasures
    ModuleName = Catattributes

    in app\code\local\Pleasures\Catattributes\etc\config.xml

    &lt;?xml version=&quot;1.0&quot;?&gt;

    in app\code\local\Pleasures\Catattributes\sql\catattributes_setup\mysql4-upgrade-0.1-1.0.php
    (note i had to use upgrade so that i could get it installed on the existing site)

    $installer = $this;
    $installer-&gt;addAttribute('catalog_category', 'highlight_cat',  array(
        'type'     =&gt; 'int',
        'label'    =&gt; 'Highlight',
        'input'    =&gt; 'select',
        'source'   =&gt; 'eav/entity_attribute_source_boolean',
        'global'   =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'required' =&gt; false,
        'default'  =&gt; 0

    in app\etc\modules\Pleasures_Catattributes.xml

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;

    Than .. it worked but never could i get any combo with the posted to work. and if you want to access it you can do this

    if ($category instanceof Mage_Catalog_Model_Category) {
                $url = $category-&gt;getData('highlight_cat');
            } else {
                $url = Mage::getModel('catalog/category')-&gt;load($category-&gt;getId())

    I’m only saying what it took to get a stable set of file to upload to a 1.7.2 version of magneto CE not that I warranty anything anyone does of the feedback I’m providing

  21. Lampix

    If you just want to add an attribute to a category tab you don’t have to use a module (testet in Paste the following code (adapt it to your needs… look at Mage_Catalog_Model_Resource_Setup at line 87+ for reference) at the beginning of any .phtml file and call it once. (I used catalog/category/view.phtml so the code gets executed when I view a category in the frontend, but the choice is really up to you… Delete the code afterwards)

    $setup = Mage::getModel(‘catalog/resource_setup’, ‘core/resource’);

    $setup->addAttribute(“catalog_category”, “default_sort_dir”, array(

    ‘type’ => ‘varchar’,
    ‘label’ => ‘Default Product Listing Sort Direction’,
    ‘input’ => ‘select’,
    ‘source’ => ‘catalog/category_attribute_source_sortdir’,
    ‘required’ => false,
    ‘sort_order’ => 51,
    ‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    ‘group’ => ‘Display Settings’

  22. Vishal

    I need to create hidden attribute and I am setting ‘visibility’ = false, but attribute is created as visible.

    Please help me out.

  23. ADD below code in app\code\local\Meteorify\Customcatattrb\sql\customcatattrb_setup\mysql4-install-0.0.1.php
    $attribute = array(
    ‘type’ => ‘text’,
    ‘label’=> ‘Bottom Description’,
    ‘input’ => ‘textarea’,
    ‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    ‘visible’ => true,
    ‘required’ => false,
    ‘user_defined’ => true,
    ‘default’ => “”,
    ‘group’ => “General Information”
    $installer->addAttribute(‘catalog_category’, ‘bottom_description’, $attribute);








  24. Ruvini

    Thanks Lampix.
    Your code works like a charm and I wish I found this a couple of days ago.
    This is the quickets way to add a new category attribute.

  25. Vishal

    i would like to add custom category attribute in ‘Sort by’.
    Can i do that .

  26. zarana

    wordfull article..!
    but I want to add wisywig editor.
    Please see following code:

    $attribute1  = array(
        'group'         =&gt; 'General',
         'input'         =&gt; 'textarea',
         'type'          =&gt; 'text',
         'label'         =&gt; 'Custom attribute',
         'backend'       =&gt; '',
         'visible'       =&gt; true,
         'required'      =&gt; false,
         'wysiwyg_enabled' =&gt; true,
         'visible_on_front' =&gt; true,
         'is_html_allowed_on_front' =&gt; true,
         'global'        =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    $installer-&gt;addAttribute('catalog_category', 'news', $attribute1);

    but its not working for me. :(
    please help…

1 2

Add Your Comment

Please wrap all source codes with [code][/code] tags.