We use several bundled products, and I'm having trouble displaying the stock value on the product grid. I don't even need values, just in stock or out of stock.

Take the following example:

  • iPhone, Black, $400, 2 in stock
  • iPhone, White, $410, 0 in stock
  • iPhone, Blue, $420, 1 in stock

With the following code I can get the prices of the bundled products and select the lowest price ($400). I thought I could use this to get the available quantities as well. I found the value of stock items in the field qty, so I tried getQty() instead of getPrice(). That returns the stock for the bundle product, the container, which is 0. I need the sum of the stock (3), or the stock value of the bundle item with the highest stock (2).

How can I get the stock value for each bundled product?

if ($_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
    $optionCol= $_product->getTypeInstance(true)->getOptionsCollection($_product);
    $selectionCol= $_product->getTypeInstance(true)
    $price = $_product->getPrice();

    foreach ($optionCol as $option) {
        if($option->required) {
            $selections = $option->getSelections();
            $minPrice = min(array_map(function ($s) {
                return $s->price;
            }, $selections));
            if($_product->getSpecialPrice() > 0) {
                $minPrice *= $_product->getSpecialPrice()/100;

            $price += round($minPrice,2);

2 Answers 2


Here is an example how to access the is salable state or the stock quantity of all associated child products.
this first method is simply to fetch the child product ids from the bundled product.

function getBundledProductChildIds(Mage_Catalog_Model_Product $product)
    $childrenIds = [];
    if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
        $childrenIds = array_reduce(
            function (array $reduce, $value) {
                return array_merge($reduce, $value);
            }, []);
    return $childrenIds;

The next example gives you the in stock or out of stock for each child product.

$bundledProduct = Mage::getModel('catalog/product')->load(BUNDLED_PRODUCT_ID);

// Just get the is salable state of the child products
$childProducts = Mage::getResourceModel('catalog/product_collection')
foreach ($childProducts as $child) {
    printf("%s -> %s stock\n", $child->getId(), ($child->getIsSalable() ? 'in' : 'out of'));

The final example gives you the stock qty of each child product.
Note that the key difference is that the require_stock_items flag is set on the collection before it is loaded.

$bundledProduct = Mage::getModel('catalog/product')->load(BUNDLED_PRODUCT_ID);    

// Get the inventory qty of each child item
$childProducts = Mage::getResourceModel('catalog/product_collection')
    ->setFlag('require_stock_items', true);
foreach ($childProducts as $child) {
    printf("%s -> stock qty: %d\n", $child->getId(), $child->getStockItem()->getQty());

printf("Total stock item qty sum: %d\n", array_reduce(
    function ($sum, $child) {
        return $sum + $child->getStockItem()->getQty();
    }, 0));

printf("Highest stock qty: %d\n", array_reduce(
    function ($max, $child) {
        return max($max, $child->getStockItem()->getQty();
    }, 0));

That should hopefully enable you to get what you need.

  • Great answer! Thanks for the excellent code. In the first function you use [], which caused an error because of my older version of PHP. In that case you can replace those two characters with array() and it should work. I haven't used the third part, but I guess that will work as well.
    – SPRBRN
    Feb 3, 2015 at 15:59

I'll post some code that works for me. Hopefully you can customize to your fit :D

$bundled_product = Mage::getModel('catalog/product');       

$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
    $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product

$bundled_items = array();
foreach($selectionCollection as $option) 
    $bundled_items[] = $option->product_id;

foreach($bundled_Items as $itemId){
    $product = $this->getProductById($itemId);
    $productquantity = $product->getQty();
  • Where does this code go I’m trying to list the stock status of each bundled item and do the same for configurable and grouped products Mar 30, 2020 at 23:02
  • @user3677211 put it wherever you want bro. I have no idea what your codebase even looks like lol. Apr 2, 2020 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.