Php – Get All simple product from a Configurable Product in Magento Product View

magentoPHP

How can I get all the simple products associated with a configurable product? I found how to do the opposite (get a product configurable from a simple product) but that's not what I need.

I want to show how many units I have in stock for the selected product (configurable attribute). My initial idea is to print all quantities of stock and control the display with jQuery. Any idea?

Best Answer

Use this below code

Code to get the the full product information (where 3 is the configurable product Id)

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

foreach($childProducts as $child) {
    print_r($child->getName());  // You can use any of the magic get functions on this object to get the value
}

Another code to get the Children Product Ids

$childProducts = Mage::getModel('catalog/product_type_configurable')
                    ->getChildrenIds(3);

Hope this helps!!

Related Topic