Magento--How to add a custom attribute to a product category (category)

Source: Internet
Author: User

In Magento, we can easily add any number of attributes to a product due to the use of a powerful EAV design approach. However, Magento does not provide us with the ability to add attributes to the classification of goods. Although we know that the EAV design method used by Magento is completely achievable, how can we add a property to the Magento classification? For example, we want to add some attributes based on the product classification to apply to the product, or to distinguish the product classification.

If you do not pass the Magento way, directly through the operation of the database, you can follow the following steps to add:

Step 1, insert a record into the Eav_attribute table. The function is to define a new property and specify that the attribute belongs to the category category of the commodity. First find out the corresponding entity_type_id of the Magento Commodity Classification (category entity) and determine the goodattribute_cod, backend_type,frontend_input, frontend_label, default_value, source_mode的值。如果不确定某个字段应该使用什么 值,可以参考一个商品分类其它属性的值来设定。

NSERT INTO eav_attribute
( entity_type_id ,  attribute_code ,  backend_type ,  frontend_input ,  frontend_label , default_value ,  source_model )
VALUES
( 3 ,  ‘category_featured‘ ,  ‘int‘ ,  ‘select‘ ,  ‘Featured Category‘ ,  ‘‘ , ‘eav/entity_attribute_source_boolean‘ );

注意:一定要确认正确的 entity_type_id, do not copy the above SQL statement, if you are not familiar with the phpMyAdmin can be used directly, as far as possible to reference the value of other properties of commodity classification.

Just this sentence adds new attributes to the taxonomy, but those that have already been created will not have these attributes, and for these categories to have new attributes, you also need to insert a record into another table of Magento.

Step 2, insert a record into the eav_entity_attribute. Where entity_type_id is the same as above, attribute_id is the id,sort_order of the newly inserted record above, which is the ordinal of the attribute in this attribute group. The id,attribute_group_id of the Attribute_set_id property set is the ID of the attribute group. The same, if you cannot fully confirm the value of the corresponding field, you can determine it by referring to the value of the other attribute of the product classification.

INSERT into Eav_entity_attribute (entity_type_id, attribute_set_id, attribute_group_id, attribute_id, Sort_order) VALUES (3, 3, 3, <new attribute Id>, <next sort order>)

That way you add a new attribute to the category of the Magento, and the added attribute is the one that has already been completed.

So how can we get the value of this property in the Magento template, or Magento's Model,helper,controller class code? Thanks to Magento's powerful setter,getter, you can get the value of this property directly using $category->getattribute_name ().

Source: http://blog.csdn.net/xinhaozheng/archive/2009/07/30/4395564.aspx

Magento--How to add a custom attribute to a product category (category)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.