How to add custom attribute to category in Magento

This blog will guide you on How to add custom attribute to category in Magento.  The example mentioned bellow are quick and easy steps.
I will keep on adding different type of examples here. Let me know if you need more example/ help.

IMP: The sql statement mentioned bellow will work with mysql command line otherwise you have to modify the sql statement mentioned bellow.

Example 1: Select list Add custom attribute to category in Magento
Lets say I want to add select list attribute that will appear for each category and will allow me to mark category as a featured category or not.
The set  of SQL statements are test on Magento (ver 1.5  CE) . You can change the attribute code, label, etc flag values as per the requirement.

Step 1:  Add attribute

INSERT INTO `mage_eav_attribute` (`entity_type_id`, `attribute_code`, `backend_model`, `backend_type`, `frontend_input`, `frontend_label`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`) VALUES ('4', 'featured', NULL, 'int', 'boolean', 'Featured', 'eav/entity_attribute_source_boolean', '0', '1', '0', '0');

Step 2:  Add Attribute reference and  Option Values
// Now get the  “entity_type_id” for previous sql statement.

select last_insert_id() into @lid;
INSERT INTO `mage_eav_attribute_label` (`attribute_id`, `store_id`, `value`) VALUES (@lid, '1', 'Is Featured Product');
INSERT INTO `mage_catalog_eav_attribute` (`attribute_id`, `is_global`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_html_allowed_on_front`, `is_filterable_in_search`, `used_in_product_listing`, `used_for_sort_by`, `is_configurable`, `apply_to`, `is_visible_in_advanced_search`, `is_used_for_promo_rules`) VALUES (@lid, '1', '0', '0', '0', '1', '1', '0', '0', '0', '0', '', '1', '0');

 

Example 2: Add select list custom attribute to category in Magento with multiple options

Step 1:  Add attribute

INSERT INTO `mage_eav_attribute` (`entity_type_id`, `attribute_code`, `backend_model`, `backend_type`, `frontend_input`, `frontend_label`, `source_model`, `is_required`, `is_user_defined`, `is_unique`) VALUES ('4', 'byfitting', NULL, 'int', 'select', 'Fitting', 'eav/entity_attribute_source_table', '0', '1', '0');

Step 2:  Add Attribute reference and  multiple Option Values

select last_insert_id() into @lid;
INSERT INTO `mage_eav_attribute_label` (`attribute_id`, `store_id`, `value`) VALUES (@lid, '1', 'Fitting');
INSERT INTO `mage_catalog_eav_attribute` (`attribute_id`, `is_global`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_html_allowed_on_front`, `is_filterable_in_search`, `used_in_product_listing`, `used_for_sort_by`, `is_configurable`, `apply_to`, `is_visible_in_advanced_search`, `is_used_for_promo_rules`) VALUES (@lid, '0', '1', '0', '1', '1', '1', '1', '1', '1', '0', '', '1', '0');
INSERT INTO `mage_eav_attribute_option` (`attribute_id`, `sort_order`) VALUES (@lid, '1');
select last_insert_id() into @optid;
INSERT INTO `mage_eav_attribute_option_value` (`option_id`, `store_id`, `value`) VALUES (@optid, '0', 'Skinny');
INSERT INTO `mage_eav_attribute_option_value` (`option_id`, `store_id`, `value`) VALUES (@optid, '1', 'Skinny');
INSERT INTO `mage_eav_attribute_option` (`attribute_id`, `sort_order`) VALUES (@lid, '2');
select last_insert_id() into @optid;
INSERT INTO `mage_eav_attribute_option_value` (`option_id`, `store_id`, `value`) VALUES (@optid, '0', 'Slim');
INSERT INTO `mage_eav_attribute_option_value` (`option_id`, `store_id`, `value`) VALUES (@optid, '1', 'Slim');
INSERT INTO `mage_eav_attribute_option` (`attribute_id`, `sort_order`) VALUES (@lid, '3');
select last_insert_id() into @optid;
INSERT INTO `mage_eav_attribute_option_value` (`option_id`, `store_id`, `value`) VALUES (@optid, '0', 'Regular');
INSERT INTO `mage_eav_attribute_option_value` (`option_id`, `store_id`, `value`) VALUES (@optid, '1', 'Regular');

Example 3: Add text field custom attribute for category in magento.

Step 1:  Add attribute

INSERT INTO `mage_eav_attribute` (`entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES (3, 'display_order', NULL, '', 'varchar', '', '', 'text', 'Display order for featured category', '', '', 0, 0, '1', 0, '');

Step 2:  Add  text field Attribute.

SELECT last_insert_id() INTO @lid;
INSERT INTO `mage_eav_entity_attribute` (`entity_type_id`, `attribute_set_id`, `attribute_group_id`, `attribute_id`, `sort_order`) VALUES (3, 3, 3, @lid, 7);
INSERT INTO `mage_catalog_eav_attribute` (`attribute_id`, `frontend_input_renderer`, `is_global`, `is_visible`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_html_allowed_on_front`, `is_used_for_price_rules`, `is_filterable_in_search`, `used_in_product_listing`, `used_for_sort_by`, `is_configurable`, `apply_to`, `is_visible_in_advanced_search`, `position`, `is_wysiwyg_enabled`, `is_used_for_promo_rules`) VALUES (@lid, '', 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, '', 0, 0, 0, 0);
Share this nice post:

11 thoughts on “How to add custom attribute to category in Magento

  1. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit, but other than that, this is magnificent blog. A great read. I’ll certainly be back.

  2. I just want to say I am just beginner to blogs and absolutely loved your web blog.
    Almost certainly I’m want to bookmark your blog . You amazingly have fantastic posts. Many thanks for revealing your web site.

  3. Thank you for your current piece. It theme needs myself greatly in addition to as a result of everyone, Write-up acquired different details. Previously very worthwhile. Site. Bravo.

Leave a Reply

Your email address will not be published. Required fields are marked *