Viktor Hesselbom
« Go back homeMagento: Add custom attributes and tabs to categories
In a recent Magento project I needed to create a custom tab in the Categories admin with some custom attributes. Turns out this is really simple.
You have to add some code to your module's mysql install/upgrade script. If you don't know what those are, read this article: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-6-magento-setup-resources/
Here's what my install script looked like:
startSetup();
$setup->addAttribute('catalog_category', 'custom_attribute', array(
'group' => 'Custom Tab',
'input' => 'text',
'type' => 'varchar',
'label' => 'Custom Attribute',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();Now, the interesting part here is the call to addAttribute:
$setup->addAttribute('catalog_category', 'custom_attribute', array(
'group' => 'Custom Tab',
'input' => 'text',
'type' => 'varchar',
'label' => 'Custom Attribute',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));Notice how 'custom_attribute' is the database fieldname for the attribute, 'Custom Attribute' is the admin label for it, and 'Custom Tab' is the name for the tab.
If we set 'General Information' as the group the attribute would appear under that tab, but because we specify a group that doesn't exist that tab will automatically be created.