Clear Magento cache is essential after layout xml update

说来懊恼,为了让Magento product list能够显示自定义属性的值,我查看了magento wiki 和 forum 上几十个帖子,众说纷纭,我也不知道哪个是对的,或者哪个针对当前1.1.8可用。一个个实验下来,排列组合了不下100种可能,比如:

  • 有人说layout add this line: my_attribute,另有人说是my_attribute
  • 有人说要用$_product->getMyAttribute(),也有人说用$_product->getAttribute(‘my_attribute’),也有人说用$_product->getData(‘my_attribute’),也有人说用$_product->getAdditionalData(‘my_attribute’),还有人说用$_product->getResource()->getAttribute(‘my_attribute’)->getFrontend()->getValue($_product))
  • 还有人说Create separate module for your customization, Name it ‘Mycustomization’
    (can be changed).
    Then do this:
    1. Create file app/etc/modules/Mycustomization.xml

    <?xml version="1.0"?>
    <config>
    <modules>
    <Mycustomization>
    <active>
    true
    </active>
    <codePool>
    local
    </codePool>
    </Mycustomization>
    </modules>
    </config>
    

    2. Create folder app/code/local/Mycustomization and inside it app/code/local/Mycustomization/etc/

    3. Create file
    app/code/local/Mycustomization/etc/config.xml

    <?xml version="1.0"?>
    <config>
    <modules>
    <Mycustomization>
    <version>
    0.0.1
    </version>
    </Mycustomization>
    </modules>
    <frontend>
    <product>
    <collection>
    <attributes>
    <designer/>
    </attributes>
    </collection>
    </product>
    </frontend>
    </config>
    

    Once done on the frontend in all product collections you will have designer attribute loaded automatically.

  • 还有Create a file app/etc/modules/category_product_attributes.xml with the following:
    <?xml version="1.0"?>
    <config>
    <frontend>
    <product>
    <collection>
    <attributes>
    <attributeyouwant/>//This is your attribute
    </attributes>
    </collection>
    </product>
    </frontend>
    </config>
    
  • 等等

最后发现所有组合都不起作用,除非清除magento cache 让 layout xml 生效。

2 Replies to “Clear Magento cache is essential after layout xml update”

  1. 你好啊,请问你知道这样在购物车列表里显示我们自定义的属性的值啊,我试了很久,查了很多资料都不知道,先谢谢了啊

Leave a Reply

Your email address will not be published. Required fields are marked *