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 ^_^
23 comments
how to export all the bundle product with associative product via CSV ?
Found this on SO
hi,
how to get only enabled bundle associated products from the collection.
Hi ,
i Want to know how to add any bundle product through code.
I love you!
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.
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?
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
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
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.
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.
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) {
}
}
}
Not sure really I guess there would be something in the $option model? Use print_r to see what is in there
How do I know which options is drop-down or select or may be checkbox type?
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() . ”;
}
Thank you for this Very usefull code.
How do you also get the disabled ones as GetSelectionCollection() seems to return only enabled items ?
regards
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
hi i want to show Bundle Product Options on Product Listing page Can any one help me?
great post as usual!
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();
}
Mage guys should create a getBundledProducts() for a product that isBundled(). It would be easier for everyone.
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
Hello,
What is the purpose of $option_collection? Is it important to call getOptionsCollection()? The result is assigned and never used.