Last active
August 17, 2020 08:17
-
-
Save Luxato/297d58f02bde113b0d25024f68f57ecf to your computer and use it in GitHub Desktop.
Get Children Configurable Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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