Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Magento_Root/vendor/magento/module-catalog/Block/Product/View/Gallery.php
- public function getGalleryImages()
- {
- $product = $this->getProduct();
- $images = $product->getMediaGalleryImages();
- if ($images instanceof MagentoFrameworkDataCollection) {
- foreach ($images as $image) {
- /* @var MagentoFrameworkDataObject $image */
- $image->setData(
- 'small_image_url',
- $this->_imageHelper->init($product, 'product_page_image_small')
- ->setImageFile($image->getFile())
- ->getUrl()
- );
- $image->setData(
- 'medium_image_url',
- $this->_imageHelper->init($product, 'product_page_image_medium')
- ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
- ->setImageFile($image->getFile())
- ->getUrl()
- );
- $image->setData(
- 'large_image_url',
- $this->_imageHelper->init($product, 'product_page_image_large')
- ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
- ->setImageFile($image->getFile())
- ->getUrl()
- );
- / * Product Name to ImageName (Alt) */
- $image->setData(
- 'img_alt',
- $product->getName()
- );
- / * End Product Name to ImageName (Alt) */
- }
- }
- return $images;
- }
- public function getGalleryImagesJson()
- {
- $imagesItems = [];
- foreach ($this->getGalleryImages() as $image) {
- / * add label to image name get */
- $label = ($image->getLabel()) ? $image->getLabel() : $image->getData("img_alt");
- $imagesItems[] = [
- 'thumb' => $image->getData('small_image_url'),
- 'img' => $image->getData('medium_image_url'),
- 'full' => $image->getData('large_image_url'),
- 'caption' => $label, // to pass the caption lable varible
- 'position' => $image->getPosition(),
- 'isMain' => $this->isMainImage($image),
- ];
- }
- return json_encode($imagesItems);
- }
Add Comment
Please, Sign In to add comment