Skip to content

Instantly share code, notes, and snippets.

@Luxato
Last active August 17, 2020 07:57
Show Gist options
  • Save Luxato/8cd440a3488fe940a1662330f1ee74bd to your computer and use it in GitHub Desktop.
Save Luxato/8cd440a3488fe940a1662330f1ee74bd to your computer and use it in GitHub Desktop.
Magento 1 get Bundle product children qty
<?php
$product = Mage::getModel('catalog/product')
->load(9275);
$collection = $product->getTypeInstance(true)
->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
$children_ids = [];
foreach ($collection as $product) {
$children_ids[] = $product->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) {
echo "Qty of the product " . $product->getID() . " is " . $product->getQty();
$total_qty += $product->getQty();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment