I’m using a custom template I created, and I’m trying to display “Only X left Threshold” set at 1 on the category list(grid) page.
Magento ver. 1.4.1 -
Can anyone help me out?
EDIT
Thanks Alan, solved.
To those who need this for configurable products, here is the code for 'Less 开发者_开发问答than 4 products remaining"
<?php if($_product->getTypeId() == "configurable"):
$total = 0;
$ids = $_product->getTypeInstance()->getUsedProductIds(); ?>
<ul>
<?php foreach ($ids as $id) :
$simpleproduct = Mage::getModel('catalog/product')->load($id); ?>
<li><?php $simpleproduct->getName()." - ".(int)Mage::getModel('cataloginventory/stock_item')
->loadByProduct($simpleproduct)->getQty(); ?>
</li>
<?php $total = $total + (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty(); ?>
<?php endforeach; ?>
<li><?php if ($total < 4) {
echo ("Only ".$total." Left!");
}?></li>
</ul>
<?php endif; ?>
if($product->getQty() < $some_num)
{
echo 'Only' . $product->getQty() . ' left';
}
$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if($qtyStock < 10) {
echo 'Only' . $qtyStock . ' left';
}
精彩评论