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

11
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Tomas Novoselic

Team Leader / Senior Developer

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

Other posts from this author

Discussion 11 Comments

Add Comment
  1. clockworkgeek

    Hello,

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

  2. Hi clockworkgeek,
    U R right, I have fixed that, tnx for noticing.
    Somehow I overlooked it when I was pulling code out of the original context XD

  3. Mage guys should create a getBundledProducts() for a product that isBundled(). It would be easier for everyone.

  4. Augusto

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

  5. great post as usual!

  6. vishal lakhani

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

  7. giuseppe

    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

  8. Thank you for this Very usefull code.

    How do you also get the disabled ones as GetSelectionCollection() seems to return only enabled items ?

    regards

  9. charles

    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. Lu Duc Tuan

    How do I know which options is drop-down or select or may be checkbox type?

  11. charles

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

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top