Magento: Get Bundled Items By Bundle Product

Featured Image

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 ^_^


About Tomas Novoselic

Team Leader/Backend Developer

At Inchoo, Tomas is a Team Leader and Certified Magento Developer who handles Magento modifications at any level. He also works closely with clients on Magento projects of any size and difficulty.

Read more posts by Tomas / Visit Tomas's profile

20 comments

  1. 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.

  2. 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?

  3. 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

  4. 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

  5. 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.

  6. 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.

  7. 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) {
    }

    }
    }

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

  9. 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() . ”;
    }

  10. 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

  11. hi i want to show Bundle Product Options on Product Listing page Can any one help me?

  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>.