Skip to main content

M2- How to get thumbnails of associated products on a grouped product from image cache

I'm trying to bring simple products thumbnails of an product product on product detail page. I can show their thumbnails easily on Magento1 but I am not able to do this on Magento2.

On Magento1, my simple products can be shown like this :

[![enter image description here][1]][1]

So I tried this code

app/design/frontend/[VendorName]/default/Magento_GroupedProduct/templates/product/view/type

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Grouped product data template
 *
 * @var $block \Magento\Catalog\Block\Product\View\BaseImage
 * @var $block \Magento\GroupedProduct\Block\Product\View\Type\Grouped
 */
?>
<?php $block->setPreconfiguredValue(); ?>
<?php $_product = $block->getProduct(); ?>
<?php $_associatedProducts = $block->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); ?>
<?php $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');?>

<!-- add simple products(associated product) thumbnails -->
        <td>
            <?php $image_url = $imageHelper->init($_item, 'grouped_list_product_thumbnail')->setImageFile($_item->getFile())->resize(100, 100)->getUrl(); ?>
            <img src="<?php echo $image_url; ?>">
        </td>

<!-- add simple products(associated product) thumbnails -->

If I run this code, my code get image as placeholder, not from cache. so it doesn't come out. Actually, we did migrate from Magento1 and media folder also was migrated manually. I want to get these image from cache folder. How can I do that?

Thank you [1]: https://i.sstatic.net/AW11j.png

3CE
  • 594
  • 6
  • 27