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; ?>
1 Answer