您好,我已閱讀了許多關於此的帖子,雖然它的工作原理尚未完成。在list.phtml中顯示產品屬性 - Magento
例如;屬性1 =鞋子和屬性2 =鞋子顏色。 兩者都處於下拉菜單中,我想列出類別頁面中每個產品的所有可能的屬性顏色。
問題:當我測試代碼時,它將只顯示第一隻鞋的顏色,而不是所有的posibilites。我在這裏做錯了什麼?
這裏是我的3個例子。所有代碼都可以工作,但只顯示第一個屬性顏色。 實施例1:
<!-- Find the following loop -->
<?php foreach ($_productCollection as $_product): ?>
<!-- Inside it insert one of the following codes as needed -->
<!-- Use this for regular text attributes -->
<?php echo $_product->getMyAttribute() ?>
<?php echo $_product->getAnotherCustomAttribute() ?>
<!-- Use this for dropdown attributes -->
<?php echo $_product->getAttributeText('shoecolor') ?>
<?php endforeach?>
<!-- ... -->
實施例2
<?php echo $_product->getResource()->getAttribute('shoecolor')->getFrontend()->getValue($_product) ?>
實施例3
<?php $type = "simple"; $p = "0" ?>
<?php foreach ($_productCollection as $_product): ?>
<?php $custom = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); ?>
<?php $col = $custom->getUsedProductCollection()->addAttributeToSelect('shoecolor')->addFilterByRequiredOptions(); ?>
<?php foreach($col as $simple_product) { $p=$simple_product->getId(); $type="configurable"; } ?>
<?php if($type == "configurable"): ?>
<h5><?php echo $_product->load($p)->getAttributeText('shoecolor'); ?><?php $type="simple" ?></h5>
<?php endif; ?>
我不明白你的問題。你的意思是「列出所有可能的attibute顏色」?您應該看到您在產品頁面中設置了可能的值。 – 2011-12-22 18:30:57