如何在related.phtml中显示相关产品中的自定义属性

时间:2014-07-24 14:32:51

标签: php html magento magento-1.8

我需要在相关产品中显示自定义属性。

我尝试从related.phtml文件获取相关产品中的自定义属性值。

app / design / frontend / base / default / catalog / product / list / related.phtml文件。

但是没有获得打印自定义属性。我的自定义属性名称是“testattr”。

 foreach($this->getItems() as $_item): ?>

// Start tried Displaying custom attribute

echo "Testattr::" . $_item->getTestattr();

// End tried Displaying custom attribute



            <li class="item">
                <?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
                    <?php if (!$_item->getRequiredOptions()): ?>
                        <input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
                    <?php endif; ?>
                <?php endif; ?>
                <div class="product">
                    <a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(50) ?>" width="50" height="50" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
                    <div class="product-details">
                        <p class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></p>
                        <?php echo $this->getPriceHtml($_item, true, '-related') ?>
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
                        <?php endif; ?>
                    </div>
                </div>
            </li>
        <?php endforeach ?>

任何人都可以帮助我吗?我需要在默认的magento中显示相关产品右侧边栏中的自定义属性值。

谢谢

1 个答案:

答案 0 :(得分:0)

试试这个:

$productId = $_item->getProductId();
$_product = Mage::getModel('catalog/product')->load($productId);
$yourCustomeAtt = $_product->getTestattr();
echo $yourCustomeAtt;
相关问题