Magento: Get Bundled Items By Bundle Product

Magento: Get Bundled Items By Bundle Product

This post is just a small snippet that will help you to get all products that are used do construct any bundle product.

Of course, I’m not sure how useful can it be as is, so if you need optimized version of it, you will need to play with it for a while.

You will need some basic knowledge of PHP language in order to fix formatting issues that you may (not saying that you will) encounter due strange behavior of code display plugin in wordpress.

I tried to find it on google few days ago and I had no luck, so if anybody has better solution, please comment.

Here we go:

< ?php
 
	$bundled_product = new Mage_Catalog_Model_Product();		
	$bundled_product->load(YOUR_BUNDLED_PRODUCT_ID);
 
 
	$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;
	}
 
	print_r($bundled_items);
 
?>

That easy ^_^

You made it all the way down here so you must have enjoyed this post! You may also like:

How To Connect Google Analytics 4 To Magento 2 Bojan Mareljic
Bojan Mareljic, | 35

How To Connect Google Analytics 4 To Magento 2

3 best open-source eCommerce platforms in 2021 Zrinka Antolovic
Zrinka Antolovic, | 7

3 best open-source eCommerce platforms in 2021

Programmatically create bundle products in Magento Petar Sambolek
Petar Sambolek, | 5

Programmatically create bundle products in Magento

23 comments

  1. Found this on SO

    $id = 10;//bundled product id
             $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($id);
             $collection = $product->getTypeInstance(true)
                ->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
    
             $itemIds = array();
    
             foreach ($collection as $item) {
                $itemIds[] = $item->getId();
               // echo "<pre>";
               // print_r($item->getData());
               // echo "</pre>";
             }
             var_dump($itemIds);
  2. How can i display weight of a bundle product in cart like price showing, how can i dynamically get updated the weight based on configuration.

  3. I played around with default bundle function and I have the weird error, that only the options that are multiselect or dropdown are shown on frontend view page. checkboxes and radiobuttons are not. Can anybody throw in an idea why this could happen?

  4. Found an issue with this; if there are no associated bundle items, then it returns many simple products. No idea why it is happening so !? Magento ver. 1.12.0.2

  5. Hi,
    This helped me a lot but i want to how to get the image of the bundle item.I tried with $option->getImageUrl().But that did not get the image and also i tried all the other ways i know if any one can help me please

  6. It would be really useful to make a single product from groups of bundled products (Bundle A + Bundle B= Product C) as per the comment from Johnny. In the front end Product C will have an MSRP = to the sum of Bundle A + Bundle B. In the front end There will be two lines one for Bundle A and one For Bundle B. The use case in my industry is a full bathroom suite.

  7. hi, im totally new to magento and i was wondering if its possible to bundle the bundled products together. example would be bundle A and bundle B and then i’ll bundle them together to make Bundle C.

  8. found this piece of code as an alternative

    $product=$_product->getTypeInstance();
    $options=$product->getOptions();
    foreach($options as $option)
    {
    $selections=$option->getSelections();
    foreach($selections as $selection)
    {
    try {
    $test = $selection->getAttributeText(‘some_attribute’);
    } catch (Exception $e) {
    }

    }
    }

  9. Not sure really I guess there would be something in the $option model? Use print_r to see what is in there

  10. Hi was just reading this as I was desperate to find a solution, had the options but not the quantities and product names so I used this:

    // For bundle product

    $options = $selectionCollection = $_product->getTypeInstance(true)
    ->getSelectionsCollection(
    $_product->getTypeInstance(true)->getOptionsIds($_product),
    $_product
    );

    foreach($options as $option){
    echo $option->getSelectionQty()*1 . ‘ x ‘ . $option->getName() . ”;
    }

  11. Hi guys, is possible to add a non simple product in a bundle product in magento?

    that is necessary for my work .

    F.e. I sell football shirt

    I sell letters and number for printings

    So i create ( f.e. ) grouped product for a name of player ( eg. Lampard 8 is composed by 1 L – 2 A – 1 M – 1 P – 1 R – 1 D and 1 x number 8 ) and all chelsea players , so I can control stock of letters

    Then I create a chelsea shirt, with sizes apart and include players by adding the previous grouped product or another bundle with all players

    Thanks for any help

  12. if($product->hasCustomOptions()){
    $customOption = $product->getCustomOption(‘bundle_selection_ids’);
    $selectionIds = unserialize($customOption->getValue());
    $selections = $this->getSelectionsByIds($selectionIds, $product);
    foreach ($selections->getItems() as $selection)
    $ids[] = $selection->getId();
    }

  13. Hello,

    What is the purpose of $option_collection? Is it important to call getOptionsCollection()? The result is assigned and never used.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.