我尝试使用此代码Magento: get the lowest price of a grouped product by product ID?进行设置,但似乎无法使其正常工作..
这是我目前的代码,我需要做些什么才能从这个分组产品中获得最低价格?
<?php
$cat_id = 33;
$catagory_model = Mage::getModel('catalog/category')->load($cat_id);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->order('rand()');
$collection->addCategoryFilter($catagory_model);
$collection->addAttributeToSelect(array('name','small_image', 'price')); //add product attribute to be fetched
if(!empty($collection)) {?>
<ul>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($collection->getItems() as $_product): if($i==8){break;}?>
<?php if ($i++%$_columnCount==0): ?>
<?php endif ?>
<li class="span4"><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(420); ?>" width="210" height="180" alt="<?php echo $_product->getName(); ?>" /></a>
<span class="product_name"><?php echo $_product->getName(); ?></span>
<span class="product_price">
<?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(). sprintf('%.2f',$_product[price]) ;?>
<!-- WANT THE LOWEST PRICE HERE -->
</span>
<a class="product_addto" href="<?php echo $_product->getProductUrl() ?>">View Product</a>
</li>
<?php endforeach; ?>
</ul>
<?php } else { echo 'No products exists';} ?>
提前谢谢你。我真的很感激。
答案 0 :(得分:1)
echo round($_product->getPriceModel()->getMinimalPrice($_product),2);
HTH