Magento – Show stock for configurable product

catalogmagento-1.9stock

I have this code:

<?php if($_product->isSaleable()): ?>
    <p><?php echo $this->__('In stock:') ?>
    <?=(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() ?>
    <?php echo $this->__(' stk.') ?></p>
<?php endif; ?> 

It works great for simple products, shows how many left.

But i also use configurable products. How can I get the code to get the stock of the simple product when the parent is a configurable? Now it shows 0.

Best Answer

Use the following for all types of products in order to check the stock:

if ($_product->getTypeInstance(true)->isSalable($_product)) {

}

Haven't checked but you can try this as well:

if ($_product->isAvailable()) {

}