【发布时间】:2012-01-26 02:45:40
【问题描述】:
您好,我已经阅读了很多关于此的帖子,虽然它有效但并不完整。
例如;属性 1 = 鞋码,属性 2 = 鞋颜色。 两者都在下拉列表中,我想在类别页面中列出每个产品的所有可能属性颜色。
问题:当我测试代码时,它只会显示第一个鞋子颜色,而不是所有可能的颜色。我在这里做错了什么?
以下是我所拥有的 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; ?>
【问题讨论】:
-
我不明白你的问题。你的意思是“列出所有可能的属性颜色”?您应该看到您在产品页面中设置了可能的值。
标签: php arrays magento for-loop configurable-product