假设我后台创建了一个code为acronym的自定义属性:
第一种:直接使用getAttributeName的方法:
<?php echo $this->htmlEscape($_product->getAcronym())?>第二种:使用辅助类:
<?php echo $_helper->productAttribute($_product, nl2br($_product->getAcronym()), 'acronym')?>第三种:使用getAttribute()方法:
<?php
$attributes = $_product->getAttributes();
$themeAcronym = $attributes['acronym']->getFrontend()->getValue($_product);
echo $themeAcronym;
?>这三种方式都能够在list页输出自定义属性的text value,不过需要注意的是,后台应该设置为:
那么在cart page 获取的方法也差不多:
<?php echo Mage::getModel('catalog/product')->load($this->getProduct()->getId())->getAcronym();?>这样的话,前台才会显示,还有别忘了缓存和索引之类的问题...Done!
本文详细介绍了在Magento中如何通过多种方式获取并展示产品的自定义属性,包括直接使用getAttributeName方法、辅助类和getAttribute方法。同时强调了在设置和获取属性时应注意的细节,如确保缓存和索引问题已解决。
2万+

被折叠的 条评论
为什么被折叠?



