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?
-
Did you ever come up with a cause? I've been seeing this happen intermittently between different themes.– EirikCommented 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.– Reshad ZazaiCommented Mar 27, 2021 at 9:08
-
@ReshadZazai I am facing the same problem, Can you share the gallery.phtml file code?– Faisal SheikhCommented May 31, 2021 at 10:46
-
@ReshadZazai Brother! please guide me on this, how you fixed this problem?– Faisal SheikhCommented 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" },– Reshad ZazaiCommented Jun 1, 2021 at 8:28
Add a comment
|
1 Answer
/**
* 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>
-
-
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
-