Create a custom category attribute in Magento
Feb 8, 2012
I’ve run into a few posts about this thing but none of them was working out of the box so I took all the info and glued them together so…
if you’ve to create a custom attribute for a Magento category but you don’t have a module (and its installer script) simply create a php file in the project’s root with this code:
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'int',
'label'=> 'Your attribute label',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'your_attribute_code', $attribute);
$installer->endSetup();
This attribute is a “text”, more info may come in comments if you need.
Filed in: PHP









Ethhan on Apr 4, 2012 | Reply
Thanks, your blog helped me out a lot. As an FYI for any future readers, if you want to make a multiselect attribute from an existing source model (in my case the customer groups) you’ll need to change input to ‘multiselect’ and have the following values in the attribute array:
‘source’ => ‘customer/customer_attribute_source_group’,
‘backend’ => ‘eav/entity_attribute_backend_array’,
‘frontend’ => ”,
Ethan on Apr 4, 2012 | Reply
Oops, and your type will need to be ‘text’ or ‘varchar’