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.

2 Answers 2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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