网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > Magento
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 199.115.98.60
Old 2016-10-02, 07:09 PM
Sahuarita Sahuarita is offline
初级会员
 
Join Date: 2012-03-27
Posts: 2
Sahuarita 现在声名狼藉
Default magento cagegory如何添加自定义属性

在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;
?>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Magento performace optimization, Catalog URL Rewrite Management Ratcliff Magento 0 2015-04-24 04:43 AM
Migrate magento to new server / domain / database / host Raquette Lake Magento 0 2015-04-24 04:41 AM
Magento filter products by status Rapid City Magento 0 2015-04-24 04:41 AM
Magento Special price products page Rankin Magento 0 2015-04-24 04:39 AM
magento产品类别优化 topvip 代码交流 0 2010-10-26 01:25 PM

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 09:12 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.