Skip to content

Instantly share code, notes, and snippets.

@Luxato
Last active August 17, 2020 08:17
Show Gist options
  • Save Luxato/297d58f02bde113b0d25024f68f57ecf to your computer and use it in GitHub Desktop.
Save Luxato/297d58f02bde113b0d25024f68f57ecf to your computer and use it in GitHub Desktop.
Get Children Configurable Products
<?php
$product = Mage::getModel('catalog/product')
->load(11925);
$children = $product->getTypeInstance()->getUsedProducts($product);
$children_ids = [];
foreach ($children as $child){
$children_ids[] = $child->getID();
}
$childrenCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('entity_id', array('in' => $children_ids))
->addAttributeToSelect('*')
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
)
->load();
$total_qty = 0;
foreach ( $childrenCollection as $product) {
$total_qty += $product->getQty();
}
echo "Total QTY is $total_qty";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment