我正在尝试显示与可配置产品相关的简单产品的库存状态列表。这工作正常,除非当相关属性“大小”不显示时数组的第一个实例。
<?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
关于我错了什么以及如何显示第一个属性的任何指示?