Today I was required to create different “areas” to display categories. This required the creation of a Category Attribute.

After much deliberation and viewing many articles (including an article by my colleague Tom Cafferkey), I found a way.

To start with, create a file within your root (call it anything), containing the following:

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(
'group' => 'General',
'input' => 'select',
'type' => 'int',
'label' => 'Location of featured category',
'backend' => '',
'visible' => true,
'required' => false,
'visible_on_front' => true,

Now for the fun part. Include this following value in your array:

    'option'   => array (
            'values' => array( //Careful here, I learnt the hard way by using 'value' instead of 'values' :-/
                0 => 'None',
                1 => 'Top',
                2 => 'First Line',
                3 => 'Second Line',
                4 => 'Text',
            )
        ),

And then to round it off: (Note I’ve included a quick removal line at the bottom for the clumsy ones out there).


'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
);

$installer->addAttribute('catalog_category', 'category_featured', $attribute);

// $installer->removeAttribute('catalog_category', 'category_featured'); //Unquote this if you mess it up and need to remove it.
 
$installer->endSetup();

And that’s it! I hope this saves someone at least an hour or two.