如何在购物车中显示自定义属性(Magento) [英] How to display custom attribute in cart (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屋!