I want to show all images of item(product) of bundled product on product listing page ,is there any Magento function to do so, please guide me way to do it.

I created bundled product with 4 items say a,b,c,d

Now on product listing page I want to show all 4 small_images of these product .

How can I do it ?


Try this:

 $model= Mage::getModel('catalog/product');
 //$product is a product object
 if($product->getTypeId() == 'bundle'){
    $bundles = $product->getTypeInstance(true)->getChildrenIds($product->getId(), false);

    $item = array();
    foreach($bundles as $index => $items){
        foreach($items as $id){
            $item[] = $id;
            //break; //only get first item
            //un-comment above line if you want only one (first) item.

          $child = $model
                    ->addAttributeToSelect(array('name', 'price', 'image', 'small_image'))
                    ->addAttributeToFilter('entity_id', array('in' => $item))
                    ->setOrder('price', 'DESC')

   foreach($child as $item){
        echo $item->getName();
        echo "<br>";
        echo '<img id="image" src="'.$this->helper('catalog/image')->init($item, 'small_image')->keepAspectRatio(true)->keepFrame(false)->resize(120, 100).'" alt="'.$_helper->productAttribute($item, $item->getName(), 'name').'"/>';
        echo "<br>";
        echo "<br>";

Key Points

  1. $product is a product object.

This should work. Good luck.

  • Sorry my mistake, it should be $bundles, I have updated. – Adarsh Khatri Feb 17 '16 at 5:30
  • This means $bundle is not defined. Where exactly did you put this code? – Adarsh Khatri Feb 17 '16 at 5:37
  • on produt listing page – mcoder Feb 17 '16 at 5:37
  • Try now, I have updated. – Adarsh Khatri Feb 17 '16 at 5:41
  • hey bro just one thing is there need of below line foreach($bundles as $index => $items){ – mcoder Feb 17 '16 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.