zoukankan      html  css  js  c++  java
  • 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;
    ?>

  • 相关阅读:
    uva10986 堆优化单源最短路径(pas)
    动态规划②——线性动态规划(背包)
    UVA567
    动态规划①——记忆化搜索
    网络号与主机号的区分与计算(转)
    故障处理-ORA-00376/ORA-01110
    Oracle的自动统计信息不收集直方图的信息
    Oracle 11g的Redo Log和Archive Log的分析方法
    SQL优化 1
    oracle 11g 通过在线重定义方式修改表结构
  • 原文地址:https://www.cnblogs.com/focai/p/4170112.html
Copyright © 2011-2022 走看看