December 31, 2009

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

$option_collection = $bundled_product->getTypeInstance(true)->getOptionsCollection($bundled_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;
}

print_r($bundled_items);

?>

That easy ^_^

9 comments:

  1. You stole this from inchoo

    ReplyDelete
  2. You stole this from inchoo You stole this from inchoo You stole this from inchoo You stole this from inchoo You stole this from inchoo You stole this from inchoo You stole this from inchoo

    ReplyDelete
  3. You even stole

    That easy ^_^

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. achat d'un produit par un particulier

    ReplyDelete
  6. I cannot wait to dig deep and kickoff utilizing resources that I received from you. Your exuberance is refreshing. ikinci el satış

    ReplyDelete
  7. I am incapable of reading articles online very often, but I’m happy I did today.It is very well written, and your points are well-expressed.I request you warmly, please, don’t ever stop writing. astrology

    ReplyDelete