Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Getting the products that make up a bundled product
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

I am writing an API to expose bundled products. I need to also return all the products that make up a bundled product. Currently I am going down the path of getting the options in a loop and creating a pseudo product (using code I found in the bundle view) like:

$optionCollection $product->getTypeInstance()->getOptionsCollection();
$selectionCollection $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
$options $optionCollection->appendSelections($selectionCollection);
foreach( 
$options as $option )
{
    $_selections 
$option->getSelections();
    foreach( 
$_selections as $selection )
    
{
        
echo  $selection->getName();
    
}
}
Except instead of “echo"-ing the options and selection I add them to a “products” array that I append to my bundled product.

Is there a nicer way to do this? I notice that I can get the product details in a getOptions() call, but they are protected and I can’t see how to get them out. Is there a simpler way, or a way to get magento to treat “selections” as products?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

Ahh, I just realised that the “selection” in the inner loop is actually of type catalog/product. Which is great… but the “options” in the outerloop is of type Mage_Bundle_Model_Option, and if I do:
echo $option->getTitle, I get nothing.

Is there away to grab the default title assigned in the admin section?

And also, is there a way to get all the images associated with the simple products in the inner loop (it only seems to return the thumbnail/image/small image - no any extra images… and getMediaGalleryImages() is “not a function") ?

And and, my original question still stands: is this the best way to return the products?!

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

Ok, so the selections from $option->getSelections() are kind of a product - but not quite… they have all the regular methods like getSku() and getName() etc… but don’t have getMediaGalleryImages().

So I have had to “load” the product to get the real product in the inner loop like so:

$product_simple Mage::getModel('catalog/product')->load($selection->getId());

then the $product_simple has getMediaGalleryImages() and what-not.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top