1

In grouped.phtml, i'd like to show all simple products image (not only thumbnail, small, basic images but also other images)

So my coded looks like

<?php $collection = $this->getProduct()->getMediaGalleryImages();
foreach ($collection as $_image): ?>
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize(300); ?>" width="300" height="300" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>" />
<?php endforeach;?>

But these images show "group product images" not "associated products images".

Please help me.

sv3n
  • 11,657
  • 7
  • 40
  • 73
Diny Na
  • 59
  • 5

2 Answers2

1
<?php
$_product=$this->getProduct();
$grouped_product_images=array();
if ($_product->getTypeId() == 'grouped'){
    $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
    foreach ($associatedProducts as $_item):
        $name=$_item->name;
        $image=strval(Mage::helper('catalog/image')
            ->init($_item, 'image', NULL)
            ->resize(265, 265));
        $image_thumb=strval(Mage::helper('catalog/image')
            ->init($_item, 'image', NULL)
            ->resize(56, 56));
        $image_large=strval(Mage::helper('catalog/image')
            ->init($_item, 'image', NULL)
            ->resize(600, 600));
        array_push($grouped_product_images,array($name,$image,$image_thumb,$image_large));
    endforeach;
}
?>

Hope it will help. Thanks :)

Abhishek Panchal
  • 4,948
  • 3
  • 21
  • 38
0

getImage() function only able to give you base image of a product.

If want to get all images of product then you should to call media gallery.

<?php 
    $mediaGallery = $product->getMediaGalleryImages();
    /* get Image one by  using loop*/
    foreach ($mediaGallery as $image) {
        echo ($image->getUrl());
    $productMediaConfig->getMediaUrl($image->getUrl());
    } 
?>

or

faster way to load media images in the product collection, check url: Faster way to load media images in a product collection

Hassan Ali Shahzad
  • 2,330
  • 18
  • 35
Abhinav Singh
  • 2,592
  • 15
  • 14