magento添加分类属性

在magento中给产品添加自定义属性是很容易实现在后台就可以很轻易添加,但是给分类就不行了,magento本身没有提供给category添加自定义属性。在实际的运用过程中我们想给cagegory添加属性就得自己想办法了。在这里说说我是怎么添加的。

思路:通过建立一个产品属性->通过数据库把这个属性更改为cagegory的属性

具体操作:1.建立一个产品属性 网站后台->catalog->Attribute->Manage Attribute 在这里新建好自己想要的属性。

     2.通过sql:SELECT attribute_id FROM `eav_attribute` where attribute_code='cus_category_description' 这里的attribute_code 这个值是你刚才新建的属性code 得到attribute_id。

     3.通过sql:SELECT entity_type_id FROM `eav_entity_type` where entity_type_code='catalog_category';找到entity_type_id。

     3.通过sql:update `eav_attribute` set entity_type_id=(第3步得到的 entity_type_id) where attribute_id=(第2步得到的 attribute_id)。这样就已经把第一步新建的产品属性更改为分类的属性了,这步做了之后再后台你还是看不到你刚才添加的那个属性的,还需要一个 步骤就是向eav_entity_attribute这个表中新增一条记录。

              4.通过sql:insert into `eav_entity_attribute`(entity_type_id,attribute_set_id,attribute_group_id,attribute_id,sort_order) values(第3步得到的 entity_type_id,attribute_set_id(参照第5 步),attribute_group_id(参照第5步),attribute_id(第2步得到),sort_order(根据自己需要显示的顺序写 个值就行))。

               5.如何得到 attribute_set_id 和 attribute_group_id:到网站后台分类管理的页面通过火狐或者谷歌浏览器查看元素的功能可以找到填写分类关键词那个属性的code值如 name="general[meta_keywords] ,这个meta_keywords值就是分类关键词的属性code了。通过第2步 就可以查到 meta_keywords这个code的attribute_id。通过这个attribute_id在表中 eav_entity_attribute 就可以查到相应的 attribute_set_id 和 attribute_group_id 。

               6.刷新网站缓存 ok 在分类管理页面就可以看到刚才添加的那个属性了。

      7.获取分类自定义属性:     

<?php
$cat_attr = $_category->getAttributes();
if(array_key_exists('cus_category_id', $cat_attr)):
$_shortDescription=$cat_attr['cus_category_id']->getFrontend()->getValue($_category);
echo $_shortDescription;
endif;
?>

原文地址:https://www.cnblogs.com/focai/p/4170112.html