如何在购物车中显示自定义属性(Magento) [英] How to display custom attribute in cart (Magento)

查看:86
本文介绍了如何在购物车中显示自定义属性(Magento)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多stuf,但没有一个能够工作。我想我可以在产品页面上获得自定义属性,但我想知道:如何让他们进入购物车页面? (该属性只是一个简单的书面文本)

谢谢。 解决方案

$ _ item-> getProduct() - > load()将重新加载数据库中的所有产品数据。虽然这会起作用,但请记住,每次调用 load()时,Magento都会执行数据库查询。



通过加载属性和报价项目,可以获得更好的性能。只需创建一个自定义模块并将其添加到config.xml中即可。

 < global> 
< sales>
< quote>
< item>
< product_attributes>
< one_custom_attribute_code />
< another_custom_attribute_code />
< / product_attributes>
< / item>
< / quote>
< /销售>
< / global>

完成此操作后,您可以访问自定义属性而无需额外的数据库查询。

  $ _ item-> getProduct() - > getAnotherCustomAttributeCode(); 

这里有一篇关于这方面的文章:https://www.atwix.com/magento/accessing-custom-attribute-at-checkout-or-cart/


I have tried a lot of stuf but none of them work. I think I can get the custom attributes on the product page, but I was wondering: how to get them in shopping cart page? (the attribute is just a simple written text)

Thank you.

解决方案

$_item->getProduct()->load() will reload all product data from the database. While this will work, bear in mind that every time you call load() Magento will execute a database query.

The same can be done with much better performance by loading the attribute along with the quote item. Just create a custom module and add this to the config.xml

<global>
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <one_custom_attribute_code />
                    <another_custom_attribute_code />
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>

Having done that, you can access your custom attribute without additional database queries.

$_item->getProduct()->getAnotherCustomAttributeCode();

Here is an article about this: https://www.atwix.com/magento/accessing-custom-attribute-at-checkout-or-cart/

这篇关于如何在购物车中显示自定义属性(Magento)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆