How to add new custom category attribute in Magento

    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:

    Post from 

    Recent Articles


    Related Stories

    Stay on op - Ge the daily news in your inbox