Facebook fans

Latest from Twitter

Magento – Add custom attributes to category

Posted date: 9 Aug 2011 | Posted by: admin | 0 comments

Sometimes you want to add custom attributes to Magento categories. In this tutorial, I will show you 2 ways to do the job.

Method 1:
Executing sql(s) to insert the attribute directly to database. Depend on which version of magento you’re running, ¬†you’ll need to update several tables.

For magento 1.5, these are:

  • eav_attribute
  • eav_entity_attribute
  • catalog_eav_attribute

Create the new attribute via admin, or via SQL that uses the following sql:

INSERT INTO `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′, ‘view_advice’, null, null, ‘text’, null, null, ‘text’, ‘Link’, null, null, ’0′, ’1′, ”, ’0′, ”);

Create the relationships as following:

  • Replace 623 with the ID from the attribute above and 133 with the next incremented ID in eav_entity_attribute:
INSERT INTO `eav_entity_attribute` (`entity_attribute_id`, `entity_type_id`, `attribute_set_id`, `attribute_group_id`, `attribute_id`, `sort_order`) VALUES (623, 3, 3, 3, 133, 5);
  • Replace 133 with the next incremented ID in eav_entity_attribute:
INSERT INTO `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¬†(’133′, null, ’0′, ’1′, ’0′, ’0′, ’0′, ’1′, ’0′, ’0′, ’0′, ’0′, ’0′, ’0′, ”, ’0′, ’0′, ’0′, ’0′);

Now, you’ve had already the new attribute!

P/s: you still need to add the new attribute to a attribute set before seeing it in the product management page.

Method 2

Another solution is the creation of a module that will add the attribute automatically, and this, whatever the version of magento. In addition, it automates the creation if ever the database were to be re-installed :

In app/loca/#company#/#module_name#/sql/#module_name#_setup/mysql4-install-#version#.php

$setup = $this;
$installer = new Mage_Eav_Model_Entity_Setup(‘core_setup’);

$installer->addAttribute(‘catalog_category’, ‘attribute_code’, array(
‘input’ => ‘text’,
‘type’ => ‘text’,
‘label’ => ‘Attribute label’,
‘visible’ => true,
‘required’ => false,
‘visible_on_front’ => false,
‘searchable’ => false,
‘used_in_product_listing’ => false,

You can check more about the method 2 in the original post: http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/

It's useful? Like this article!

Comments are closed.

Share this

Related posts

Pinterest Fan Box – Add Pinterest Followers to your Magento site image

Pinterest Fan Box, do you know how to add your Pinterest...

7 Apr 2012
Pinterest Feeds – Add Pinterest Pin Board to Magento Site image

Pinterest Feeds to Magento sites, how to do the...

23 Mar 2012
Pinterest Magento Linker image

Pinterest is one of the hottest social networks and is...

14 Mar 2012
Debugging magento templates image

Developing in Magento without these debugging tips can be...

14 Oct 2011

Mirage Design @ 2011 | Web development, Website design, Magento development, Wordpress development

Pinterest Tutorial   Ty so bong da   Tim chung cu