Magento:getAttributeText('制造商')不起作用

时间:2013-01-14 15:21:18

标签: magento attributes

我非常感谢你的帮助。我是Magento的新手,并探索它的可能性。我有这段代码,它从类别及其属性加载产品:

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>

<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
     <?php // Grid Mode ?>
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
        <?php $_iterator = 0; ?>
        <ul class="products-grid">    
        <?php $i=0; foreach ($_productCollection as $_product): ?>
            <li class="item">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(252); ?>" width="252" height="252" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h3>
                <h4 class="product-name"><?php echo $_product->getAttributeText('manufacturer') ?></h4>                
                <?php echo $this->getPriceHtml($_product, true) ?>
             </li>  
        <?php endforeach ?>
        </ul>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
</div>
<?php endif; ?>

我的问题是:为什么“echo $ _product-&gt; getAttributeText('manufacturer')”在这里不起作用?我尝试了不同代码的无数变种,但制造商参数并没有显示出来。你知道为什么吗?

2 个答案:

答案 0 :(得分:5)

我已经尝试过Adam Moss所建议的并且有效:

需要在admin的属性编辑器中将

'在产品列表中显示'设置为yes。然后echo $ _product-&gt; getAttributeText('manufacturer')工作没有任何问题。

答案 1 :(得分:0)

所以我使用@Shawn_Northrop建议来工作;

<?php 
echo $_product->getData('my_custom_attribute'); 
?>

快乐编码...