Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
?>

<?php
// If block argument "gallery_options" is not set in xml layout file, then fallback
// to an instance of \Magento\Catalog\Block\Product\View\GalleryOptions class manually
if ($block->getGalleryOptions() === null) {
$block->setData(
'gallery_options',
\Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Block\Product\View\GalleryOptions::class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we obtain it from layout somehow or it's not present? Using ObjectManager in template is quite messy approach.

);
}

$images = $block->getGalleryImages()->getItems();
$mainImage = current(array_filter($images, function ($img) use ($block) {
return $block->isMainImage($img);
Expand Down Expand Up @@ -45,7 +55,7 @@ $mainImageData = $mainImage ?
"data": <?= /* @noEscape */ $block->getGalleryImagesJson() ?>,
"options": <?= /* @noEscape */ $block->getGalleryOptions()->getOptionsJson() ?>,
"fullscreen": <?= /* @noEscape */ $block->getGalleryOptions()->getFSOptionsJson() ?>,
"breakpoints": <?= /* @noEscape */ $block->getBreakpoints() ?>
"breakpoints": <?= /* @noEscape */ $block->getBreakpoints() ?>
}
}
}
Expand Down