Grouped Products - is it possible to show out of stock status individually (by each product)?
Magento: 1.9
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityGrouped Products - is it possible to show out of stock status individually (by each product)?
Magento: 1.9
File: template/catalog/product/view/type/grouped.phtml
<?php // If QTY is OUT OF STOCK then display it to user
$_product = Mage::getModel('catalog/product')->load($_item->getId());
$stock = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if($stock < 1 ) {
echo '<p class="out-of-stock-qty">'; echo $this->__(' --- Out of Stock --- '); echo '</p>';
}
?>
$_item->getId() is ID of product and this can be used on any type of product where you need to display qty of product Or just to inform about available stock. This might help someone.
In my Magento instalation, this is the default behaviour and the code responsible for that is located in template/catalog/product/view/type/grouped.phtml
<?php foreach ($_associatedProducts as $_item): ?>
........
<?php if ($_product->isSaleable()): ?>
<div class="qty-wrapper">
<?php if ($_item->isSaleable()) : ?>
<input id="super_group_<?php echo $_item->getId(); ?>" type="text" pattern="\d*" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
<label for="super_group_<?php echo $_item->getId(); ?>" class="qty-label">
<?php echo $this->__('Quantity'); ?>
</label>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
<?php endif; ?>
...........
<?php endforeach; ?>