Gallery.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Simple product data view
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\ProductVideo\Block\Product\View;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Gallery extends \Magento\Catalog\Block\Product\View\Gallery
  17. {
  18. /**
  19. * @var \Magento\ProductVideo\Helper\Media
  20. */
  21. protected $mediaHelper;
  22. /**
  23. * @param \Magento\Catalog\Block\Product\Context $context
  24. * @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
  25. * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
  26. * @param \Magento\ProductVideo\Helper\Media $mediaHelper
  27. * @param array $data
  28. * @param \Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface|null $imagesConfigFactory
  29. * @param array $galleryImagesConfig
  30. */
  31. public function __construct(
  32. \Magento\Catalog\Block\Product\Context $context,
  33. \Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
  34. \Magento\Framework\Json\EncoderInterface $jsonEncoder,
  35. \Magento\ProductVideo\Helper\Media $mediaHelper,
  36. array $data = [],
  37. \Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface $imagesConfigFactory = null,
  38. array $galleryImagesConfig = []
  39. ) {
  40. parent::__construct(
  41. $context,
  42. $arrayUtils,
  43. $jsonEncoder,
  44. $data,
  45. $imagesConfigFactory,
  46. $galleryImagesConfig
  47. );
  48. $this->mediaHelper = $mediaHelper;
  49. }
  50. /**
  51. * Retrieve media gallery data in JSON format
  52. *
  53. * @return string
  54. */
  55. public function getMediaGalleryDataJson()
  56. {
  57. $mediaGalleryData = [];
  58. foreach ($this->getProduct()->getMediaGalleryImages() as $mediaGalleryImage) {
  59. $mediaGalleryData[] = [
  60. 'mediaType' => $mediaGalleryImage->getMediaType(),
  61. 'videoUrl' => $mediaGalleryImage->getVideoUrl(),
  62. 'isBase' => $this->isMainImage($mediaGalleryImage),
  63. ];
  64. }
  65. return $this->jsonEncoder->encode($mediaGalleryData);
  66. }
  67. /**
  68. * Retrieve video settings data in JSON format
  69. *
  70. * @return string
  71. */
  72. public function getVideoSettingsJson()
  73. {
  74. $videoSettingData[] = [
  75. 'playIfBase' => $this->mediaHelper->getPlayIfBaseAttribute(),
  76. 'showRelated' => $this->mediaHelper->getShowRelatedAttribute(),
  77. 'videoAutoRestart' => $this->mediaHelper->getVideoAutoRestartAttribute(),
  78. ];
  79. return $this->jsonEncoder->encode($videoSettingData);
  80. }
  81. /**
  82. * Return media gallery for product options
  83. * @return string
  84. * @since 100.1.0
  85. */
  86. public function getOptionsMediaGalleryDataJson()
  87. {
  88. return $this->jsonEncoder->encode([]);
  89. }
  90. }