How to call stock values of configurable products' simple products

382 views Asked by At

I'm trying to create an availability table for configurable products in magento, so in one column it lists the simple products associated with the configurable product, and in the other column, it calls on the stock level for the simple product (and whether it allows backorders) and displays an appropriate 'in stock' 'out of stock' or whatever the availability option is for the configurable product.

The part i'm stuck on is how to call the inventory levels for each simple product, I've been looking in catalogue\product\view\type\options\configurable.phtml to try and understand how magento calls the different attributes to display sizing options etc but I'm not sure if it's the right approach as it seems to just check if the products are in stock or not...

What would be the best way of achieving this?

2

There are 2 answers

1
MagePal Extensions On

Take a look @ Get product remain quantity in Magento CE 1.7?

Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()

0
Manashvi Birla On

The below code will give all the simple products associated with the configurable product. 877 is the id of the configurable product. The result will give you all the simple products id along with their qty.

    $product = Mage::getModel('catalog/product')->load(877); 
$childProducts = Mage::getModel('catalog/product_type_configurable')
                    ->getUsedProducts(null,$product);

foreach($childProducts as $child) {
    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($child)->getData();
    $productId = $stock['product_id'];
    $qty = $stock['qty'];
    echo $productId." - ".$qty."<br/>"; 
}