1

The zoom_in and zoom_out buttons are not working in the product pop-up gallery, however, while clicking the image, the image gets zoomed on the first double click and gets zoomed out on the second double click. any suggestion for the solution? 2

5
  • Did you ever come up with a cause? I've been seeing this happen intermittently between different themes.
    – Eirik
    Commented Mar 26, 2021 at 19:28
  • 1
    @Eirik, for me it was because the values were not fetched in the gallery.phtml from view.xml. I have provided the values in json in gallery.phtml and it worked. Commented Mar 27, 2021 at 9:08
  • @ReshadZazai I am facing the same problem, Can you share the gallery.phtml file code? Commented May 31, 2021 at 10:46
  • @ReshadZazai Brother! please guide me on this, how you fixed this problem? Commented Jun 1, 2021 at 7:28
  • 1
    @FaisalSheikh I have passed the options in json for "magnifierOpts": { "enabled": true, "fullscreenzoom":20, "mode": "outside", "eventType": "hover" }, Commented Jun 1, 2021 at 8:28

1 Answer 1

1

/**
 * Product media data template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Gallery
 */
?>

<?php
$images = $block->getGalleryImages()->getItems();
$mainImage = current(array_filter($images, function ($img) use ($block) {
    return $block->isMainImage($img);
}));

if (!empty($images) && empty($mainImage)) {
    $mainImage = $block->getGalleryImages()->getFirstItem();
}

$helper = $block->getData('imageHelper');
$mainImageData = $mainImage ?
    $mainImage->getData('medium_image_url') :
    $helper->getDefaultPlaceholderUrl('image');

?>

<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
    <img
        alt="main product photo"
        class="gallery-placeholder__image"
        src="<?= /* @noEscape */ $mainImageData ?>"
    />
</div>

<script type="text/x-magento-init">
    {
        "[data-gallery-role=gallery-placeholder]": {
            "mage/gallery/gallery": {
                "mixins":["magnifier/magnify"],
                "magnifierOpts": {
                "enabled": true,
                "fullscreenzoom":20,
                "mode": "outside",
                "eventType": "hover"
                },
                "data": <?= /* @noEscape */ $block->getGalleryImagesJson() ?>,
                "options": <?= /* @noEscape */ $block->getGalleryOptions()->getOptionsJson() ?>,
                "fullscreen": <?= /* @noEscape */ $block->getGalleryOptions()->getFSOptionsJson() ?>,
                 "breakpoints": <?= /* @noEscape */ $block->getBreakpoints() ?>
            }
        }
    }
</script>
4
  • Thank you brother, I am going to try this... Commented Jun 1, 2021 at 8:32
  • Thank you so much brother! after applying you solution, Zoom functionality is working fine now. Commented Jun 1, 2021 at 9:09
  • I also posted a question here on stackexchange: magento.stackexchange.com/questions/338064/… if you want then you can give same answer there also Commented Jun 1, 2021 at 9:09
  • @FaisalSheikh glad it helped. Commented Jun 1, 2021 at 9:19

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.