Magento 2 – Bundle Product Options Images

bundle-productgallery-imagemagento2

I am trying to make a couple of things working with bundle products.
But i cant seem to get it working properly.
Also i cant seem to find the correct module that does this with bundle products.

What i am trying to reach is the following:

On the product page of a bundle product you have an image gallery.
I want to add the product option main images to this gallery.

After that i want to be able to select a option and when i do that it updates the selected gallery image to the main image from that option.

However until this point i have searched for a solution online and inside the code. But i cant seem to figure it out how i should approach this correctly to make it all work. I was mostly testing on the gallery.php of the category/view/product folder.

If anyone knows how i can make this work i would appreciate it.
Or if you know a module that does this work i would love to hear that too.

Best Answer

Try this code:

First you need to override below file.

After that you can get bundle option images from below code.

app/design/frontend/Vendor/Theme_Name/Magento_Bundle/templates/catalog/product/view/type/bundle/option/radio.phtml

          <?php foreach ($_selections as $_selection): ?>
              <?php
                 $_imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Catalog\Helper\Image');

                 $image = $_imageHelper->init($_selection, 'small_image', ['type' => 'small_image'])->keepAspectRatio(true)->resize('50', '50')->getUrl(); ?>

                    <label class="label" 
                           for="bundle-option-<?= /* @escapeNotVerified */ $_option->getId() ?>-<?= /* @escapeNotVerified */ $_selection->getSelectionId() ?>">
                        <div class="bundle-option-image"><img src="<?php echo $image; ?>" /></div>
                    </label>
            <?php endforeach; ?>

Hope this will works for you.

Related Topic