pom*_*aaa 16 html php custom-attributes magento
我尝试了很多stuf,但没有一个工作.我想我可以在产品页面上获取自定义属性,但我想知道:如何在购物车页面中获取它们?(该属性只是一个简单的书面文字)
And*_*ler 50
$_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>
</sales>
</global>
Run Code Online (Sandbox Code Playgroud)
完成此操作后,您无需其他数据库查询即可访问自定义属性.
$_item->getProduct()->getAnotherCustomAttributeCode();
Run Code Online (Sandbox Code Playgroud)
这是一篇关于此的文章:https://www.atwix.com/magento/accessing-custom-attribute-at-checkout-or-cart/
Ant*_*ore 24
你在谈论自定义选项还是简单属性?
简单属性(文本):(
在你的default.phtml中)
<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); ?>
Run Code Online (Sandbox Code Playgroud)
我用过这个
(中app/design/frontend/default/your_theme/template/checkout/cart/item/default.phtml)
对于我的(textfield)属性:
<?php
$_item = $this->getItem();
$_product = $_item->getProduct()->load();
?>
<?php echo $_product->getCustomAttribute(); ?>
Run Code Online (Sandbox Code Playgroud)