user3737881
user3737881

Reputation: 37

Get the configurable child products

Here comes a new challenge! I already tried everything to get the child products of a configurable product, but nothing works. The thing is, I need to get the stock quantity of a simple product which is inside a configurable product, which is inside a grouped product, so, first of all I loaded the grouped product and got it's product id according to the code.

$product = Mage::getModel('catalog/product')->load($product);
$productId = $product->getId();

then i got the configurable product which is inside the product I just loaded.

$groupedAssociatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);

this code is returning an array for me, with all details of the configurable product, and I can't get the products that are associated to this product and so it's stock quantity. Does anyone can give me a help? Thanks in advance

Upvotes: 0

Views: 85

Answers (1)

user3737881
user3737881

Reputation: 37

The code below is the answer to my own question.

$product = Mage::getModel('catalog/product')->load($product);
$productId = $product->getId();

$groupedAssociatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
foreach ($groupedAssociatedProducts as $value) {
    $idConfigurableProduct = $value->getId();
}    

$configurableProduct = Mage::getModel('catalog/product')->load($idConfigurableProduct);
$configurableAssociatedProduct = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $configurableProduct);
foreach ($configurableAssociatedProduct as $child) {
    $finalSimpleProduct = $child->getId();
}

$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($finalSimpleProduct)->getQty();

Upvotes: 0

Related Questions