I want to create custom category attributes dynamically in admin. I mean, how can I create custom category attributes in my Model class? Please suggest me proper solution to resolve this issue.

  • are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
    – Shathish
    Sep 26, 2013 at 10:53
  • Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest. Sep 26, 2013 at 10:53
  • what do you mean by the word "dynamically"? do you want to create it from a form or what?
    – Shathish
    Sep 26, 2013 at 11:05
  • Yes, exactly I want to create attributes through form. Sep 26, 2013 at 11:08
  • now I've posted answer which will create it programatically. I'll post the answer using form later :)
    – Shathish
    Sep 26, 2013 at 11:25

2 Answers 2


create a module Yournamespace_CategoryAttribute.

in app/etc/Yournamespace_CategoryAttribute.xml



now if you want to use form, in the same module:

in config.xml

<?xml version="1.0"?>
            <!-- removed eav_entity_setup rewrite -->

in YourNamespace/CategoryAttribute/Model/Setup.php

class Yournamespace_CategoryAttribute_Model_Setup{

    public function setAdminAttribute($params){
        $setup = new Mage_Eav_Model_Entity_Setup('core_setup');

        $setup->addAttribute('catalog_category', $params['attr_code'], array(
            'group'         => $params['section'],
            'input'         => $params['input_type'],
            'type'          => $params['db_type'],
            'label'         => $params['attr_label'],
            'backend'       => '',
            'visible'       => 1,
            'required'      => 0,
            'user_defined' => 1,
            'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,



in your controllers/IndexController.php

class Yournamespace_CategoryAttribute_IndexController extends Mage_Core_Controller_Front_Action{

    public function indexAction(){
    public function createAction(){
        $formParams = $this->getRequest()->getParams();


in Yournamspace/CategoryAttribute/Block/CategoryAttribute.php

class Yournamespace_CategoryAttribute_Block_CategoryAttribute extends Mage_Core_Block_Template


in app/design/frontend/your_theme/default/layout/yournamespace_categoryattribute.xml

<?xml version="1.0"?>
<layout version="0.1.0">
        <reference name="content">
            <block type="categoryattribute/categoryattribute" name="categoryattribute" template="categoryattribute/categoryattribute.phtml" />

in app/design/frontend/your_theme/default/template/categoryattribute/categoryattribute.phtml

put your form and the form-action should be $baseurl/categoryattribute/

Note: This can be organised from Admin panel, by adding a admin grid and post these from admin form.

  • I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object" Sep 26, 2013 at 13:15
  • I've made changes to config.xml as suggested.
    – Shathish
    Sep 27, 2013 at 4:09
  • Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file. Sep 27, 2013 at 5:23
  • can you post the full errror?
    – Shathish
    Sep 27, 2013 at 8:18
  • "Fatal error: Call to a member function select() on a non-object in app\code\core\Mage\Core\Model\Resource\Setup.php on line 734 " Sep 27, 2013 at 8:43

Run this script in your magento root folder to create Attribute



$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);

if (!$installer->getAttributeId($entityTypeId, 'shipping_content')) {
    $installer->addAttribute('catalog_category', 'shipping_content', array(
         'type'              => 'text',
'backend'           => '',
'frontend'          => '',
'label'             => 'Short description',
'input'             => 'textarea',
'class'             => '',
'source'            => '',
'global'            => '0',
'visible'           => true,
'required'          => false,
'user_defined'      => true,
'default'           => '',
'searchable'        => false,
'filterable'        => false,
'comparable'        => false,
'visible_on_front'  => true,
'used_in_product_listing' => false,
'unique'            => false,
'wysiwyg_enabled'   => true,
'apply_to'          => '',
'is_configurable'   => true

    $installer->updateAttribute($entityTypeId, 'shipping_content', 'is_wysiwyg_enabled', 1);
    $installer->updateAttribute($entityTypeId, 'shipping_content', 'is_html_allowed_on_front', 1);




For Remove Category Attribute



 $installer = new Mage_Sales_Model_Mysql4_Setup;
 $installer->removeAttribute('catalog_category', 'shipping_content');


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.