Guest User

Untitled

a guest
Jan 4th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. Magento_Root/vendor/magento/module-catalog/Block/Product/View/Gallery.php
  2.  
  3. public function getGalleryImages()
  4. {
  5. $product = $this->getProduct();
  6. $images = $product->getMediaGalleryImages();
  7. if ($images instanceof MagentoFrameworkDataCollection) {
  8. foreach ($images as $image) {
  9. /* @var MagentoFrameworkDataObject $image */
  10. $image->setData(
  11. 'small_image_url',
  12. $this->_imageHelper->init($product, 'product_page_image_small')
  13. ->setImageFile($image->getFile())
  14. ->getUrl()
  15. );
  16. $image->setData(
  17. 'medium_image_url',
  18. $this->_imageHelper->init($product, 'product_page_image_medium')
  19. ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
  20. ->setImageFile($image->getFile())
  21. ->getUrl()
  22. );
  23. $image->setData(
  24. 'large_image_url',
  25. $this->_imageHelper->init($product, 'product_page_image_large')
  26. ->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
  27. ->setImageFile($image->getFile())
  28. ->getUrl()
  29. );
  30.  
  31. / * Product Name to ImageName (Alt) */
  32.  
  33. $image->setData(
  34. 'img_alt',
  35. $product->getName()
  36. );
  37. / * End Product Name to ImageName (Alt) */
  38.  
  39. }
  40. }
  41.  
  42. return $images;
  43. }
  44.  
  45. public function getGalleryImagesJson()
  46. {
  47. $imagesItems = [];
  48. foreach ($this->getGalleryImages() as $image) {
  49.  
  50. / * add label to image name get */
  51.  
  52. $label = ($image->getLabel()) ? $image->getLabel() : $image->getData("img_alt");
  53.  
  54. $imagesItems[] = [
  55. 'thumb' => $image->getData('small_image_url'),
  56. 'img' => $image->getData('medium_image_url'),
  57. 'full' => $image->getData('large_image_url'),
  58. 'caption' => $label, // to pass the caption lable varible
  59. 'position' => $image->getPosition(),
  60. 'isMain' => $this->isMainImage($image),
  61. ];
  62. }
  63. return json_encode($imagesItems);
  64. }
Add Comment
Please, Sign In to add comment