Add custom ‘Category’ attributes to your store

As with most things you’ll want to customise your store to your liking. Some of this can be achieved without a developer through the admin area. This is great if you are the only person administering the site but in an enterprise fashion where you want all developers and staging and production sites to be in sync, this isn’t always practical.

The Magento platform has provision to allow you to save custom data via it’s EAV database system through the Category, Product and Customer Level. Although there is no provision to do this for Category and Products this can be achieved programmatically by means of installation scripts.

Let’s add a custom area to store a secondary description for each category. In the comments area for each part of the addAttribute function lists what each part does. Wrap this in a module and add this as an installation script and you should be good to go. In the example below we are creating a category attribute for secondary description that is accessible via the front end and is available globally through out all sites and stores.

// Add Attribute Index attribute to Category
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'secondary_description', array(
  'group'         => 'General',    // What tab to store the data
  'input'         => 'text',       // Specifying an input type field {text, textarea, dropdown}, dropdown requires a renderer
  'type'          => 'text',       // Magento EAV supports {datetime, decimal, int, text, varchar}
  'label'         => 'Secondary Description',      // Label of the attribute
  'backend'       => '',
  'visible'       => true,         // Accessible via the front end when loading a category
  'required'      => false,        // When you save in the admin if it is required to save
  'visible_on_front' => true,      // As described
  'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
   // Saved globally for all stores or store specific