Magento – How to show image in grouped product

grouped-productsmagento2product-images

For grouped products, I would like to see the picture of the by-products.

I tried several things but without success:

in files : Magento_GroupedProduct\templates\product\view\type
In the loop of associated product, i wrote this code :

$productImage = $block->getImage($_item, 'product_base_image');


<a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
     <?php echo $productImage->toHtml(); ?>
</a>

but it does not work!!
Would anyone have an idea.
Thanks

Best Answer

This is what I have done which might point you in the right direction:

1) It took me forever to get the right path to extend the template from vendor\magento\module-grouped-product\view\frontend\templates\product\view\type\grouped.phtml to my theme directory app\design\frontend\Vendorname\Themename\Magento_GroupedProduct\templates\product\view\type\grouped.html

2) I added the line <?php $productImage = $block->getImage($_item, $image); echo $productImage->toHtml(); ?>

3) the trick now is to figure out how to define what goes in $image - i have created my own definition in my theme app\design\frontend\Vendorname\Themename\etc\view.xml

<?xml version="1.0"?>
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
<media>
<images module="Magento_Catalog">
        <image id="grouped_list_product_thumbnail" type="thumbnail">
            <width>75</width>
            <height>90</height>
        </image>
 </images>            
</media>
</view>

So for me, $image = "grouped_list_product_thumbnail";

This is working for me although it is showing the placeholder and not the thumbnail - it seems my test migration did not copy the thumbnail linkage properly

This might help you solve yours though :)

Related Topic