46 private $galleryImagesConfig;
51 private $galleryImagesConfigFactory;
56 private $imageUrlBuilder;
73 array $galleryImagesConfig = [],
79 ->get(ImagesConfigFactoryInterface::class);
80 $this->galleryImagesConfig = $galleryImagesConfig;
92 $images =
$product->getMediaGalleryImages();
97 foreach ($images as
$image) {
98 $galleryImagesConfig = $this->getGalleryImagesConfig()->getItems();
99 foreach ($galleryImagesConfig as $imageConfig) {
101 $imageConfig->getData(
'data_object_key'),
102 $this->imageUrlBuilder->getUrl(
$image->getFile(), $imageConfig[
'image_id'])
117 return $this->jsonEncoder->encode($this->
getVar(
'magnifier'));
127 return $this->jsonEncoder->encode($this->
getVar(
'breakpoints'));
135 public function getGalleryImagesJson()
141 'thumb' =>
$image->getData(
'small_image_url'),
142 'img' =>
$image->getData(
'medium_image_url'),
143 'full' =>
$image->getData(
'large_image_url'),
145 'position' => $image->getData(
'position'),
147 'type' => str_replace(
'external-',
'',
$image->getMediaType()),
148 'videoUrl' =>
$image->getVideoUrl(),
150 foreach ($this->getGalleryImagesConfig()->getItems() as $imageConfig) {
152 $imageConfig->getData(
'json_object_key'),
153 $image->getData($imageConfig->getData(
'data_object_key'))
156 $imagesItems[] = $imageItem->toArray();
158 if (empty($imagesItems)) {
160 'thumb' => $this->_imageHelper->getDefaultPlaceholderUrl(
'thumbnail'),
161 'img' => $this->_imageHelper->getDefaultPlaceholderUrl(
'image'),
162 'full' => $this->_imageHelper->getDefaultPlaceholderUrl(
'image'),
170 return json_encode($imagesItems);
197 return $product->getImage() == $image->getFile();
211 $this->getConfigView()->getMediaAttributes(
'Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
220 private function getConfigView()
222 if (!$this->configView) {
223 $this->configView = $this->_viewConfig->getViewConfig();
233 private function getGalleryImagesConfig()
235 if (
false === $this->
hasData(
'gallery_images_config')) {
236 $galleryImageConfig = $this->galleryImagesConfigFactory->create($this->galleryImagesConfig);
237 $this->
setData(
'gallery_images_config', $galleryImageConfig);
240 return $this->
getData(
'gallery_images_config');
getData($key='', $index=null)
getVar($name, $module=null)
__construct(Context $context, ArrayUtils $arrayUtils, EncoderInterface $jsonEncoder, array $data=[], ImagesConfigFactoryInterface $imagesConfigFactory=null, array $galleryImagesConfig=[], UrlBuilder $urlBuilder=null)
getUrl($route='', $params=[])
getImageAttribute($imageId, $attributeName, $default=null)
getGalleryUrl($image=null)
setData($key, $value=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]