我正在尝试显示与可配置产品相关的简单产品的库存状态列表。 这个功能很好,除了数组的第一个实例未显示相关属性“大小”。
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php $instock = "Next Day"; ?>
<?php $outofstock = "4 to 7 Days"; ?>
<?php $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); ?>
<?php $col = $conf->getUsedProductCollection()->addAttributeToSelect('Size')->addFilterByRequiredOptions(); ?>
<ul>
<?php foreach($col as $simple_product){
$qty = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple_product)->getQty());
$size = Mage::getModel('catalog/product')->load($simple_product->getId())->getAttributeText('Size');
?>
<li>
<?php
if ( $qty >= 1 )
{echo $qty, " ",$size," ",$instock;}
else
{echo $qty, " ",$size," ",$outofstock;} ?>
</li>
<?php } ?>
</ul>
结果集如下所示:
99 Next Day
99 9 Next Day
99 8.5 Next Day
99 8 Next Day
99 7.5 Next Day
0 7 4 to 7 Days
99 12 Next Day
99 11.5 Next Day
99 11 Next Day
99 10.5 Next Day
99 10 Next Day
有没有什么指导可以帮我找出问题并显示第一个属性?