Monday, 26 September 2011

Magento: Adding New attributes in Category General Information

Add Below code to any file and change with my_attribute to your attribute than run that file. so for example if you past it in category/view.phtml file than open any category page from frontside and Attribute was created. see in backend category page. it will be done dont forgot to remove this code from that file after attribute was created.
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', 'my_attribute', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'My Attribute',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
you can use it If it is a text field (textbox or textarea), this is all you have to do:
echo $_product->getMyAttribute()
If you are using a dropdown or a multiple select, you have to call it a little differently:
echo $_product->getAttributeText('my_attribute')

No comments:

Post a Comment