diff --git a/app/code/Magento/ConfigurableProduct/Block/Plugin/Product/Media/Gallery.php b/app/code/Magento/ConfigurableProduct/Block/Plugin/Product/Media/Gallery.php deleted file mode 100644 index a4390bf94865084fd27d401e47982c3bdb3cabbf..0000000000000000000000000000000000000000 --- a/app/code/Magento/ConfigurableProduct/Block/Plugin/Product/Media/Gallery.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\ConfigurableProduct\Block\Plugin\Product\Media; - -use Magento\ConfigurableProduct\Model\Product\Type\Configurable; - -/** - * Class Gallery - */ -class Gallery extends \Magento\Catalog\Block\Product\View\AbstractView -{ - /** - * @var \Magento\Catalog\Model\Product\Gallery\ReadHandler - */ - private $productGalleryReadHandler; - - /** - * @var \Magento\Framework\Json\EncoderInterface - */ - private $jsonEncoder; - - /** - * @var \Magento\Framework\Json\DecoderInterface - */ - private $jsonDecoder; - - /** - * Gallery constructor. - * @param \Magento\Catalog\Block\Product\Context $context - * @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils - * @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $productGalleryReadHandler - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Magento\Framework\Json\DecoderInterface $jsonDecoder - * @param array $data - */ - public function __construct( - \Magento\Catalog\Block\Product\Context $context, - \Magento\Framework\Stdlib\ArrayUtils $arrayUtils, - \Magento\Catalog\Model\Product\Gallery\ReadHandler $productGalleryReadHandler, - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Magento\Framework\Json\DecoderInterface $jsonDecoder, - array $data = [] - ) { - $this->productGalleryReadHandler = $productGalleryReadHandler; - $this->jsonEncoder = $jsonEncoder; - $this->jsonDecoder = $jsonDecoder; - parent::__construct($context, $arrayUtils, $data); - } - - /** - * @param \Magento\Catalog\Block\Product\View\Gallery $subject - * @param string $result - * @return string - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterGetOptionsMediaGalleryDataJson( - \Magento\Catalog\Block\Product\View\Gallery $subject, - $result - ) { - $result = $this->jsonDecoder->decode($result); - if ($this->getProduct()->getTypeId() == 'configurable') { - /** @var Configurable $productType */ - $productType = $this->getProduct()->getTypeInstance(); - $products = $productType->getUsedProducts($this->getProduct()); - $attributes = $productType->getConfigurableAttributesAsArray($this->getProduct()); - /** @var \Magento\Catalog\Model\Product $product */ - foreach ($attributes as $attribute) { - foreach ($products as $product) { - $attributeValue = $product->getData($attribute['attribute_code']); - if ($attributeValue) { - $key = $attribute['attribute_code'] . '_' . $attributeValue; - $result[$key] = $this->getProductGallery($product); - } - } - } - } - return $this->jsonEncoder->encode($result); - } - - /** - * @param \Magento\Catalog\Model\Product $product - * @return array - */ - private function getProductGallery($product) - { - $result = []; - $this->productGalleryReadHandler->execute($product); - $images = $product->getMediaGalleryImages(); - foreach ($images as $image) { - $result[] = [ - 'mediaType' => $image->getMediaType(), - 'videoUrl' => $image->getVideoUrl(), - 'isBase' => $product->getImage() == $image->getFile(), - ]; - } - return $result; - } -} diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Plugin/Product/Media/GalleryTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Plugin/Product/Media/GalleryTest.php deleted file mode 100644 index 60aa30c8d40784796192d8c1b7a2ea871e505a25..0000000000000000000000000000000000000000 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Block/Plugin/Product/Media/GalleryTest.php +++ /dev/null @@ -1,111 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\ConfigurableProduct\Test\Unit\Block\Plugin\Product\Media; - -/** - * Class GalleryTest - */ -class GalleryTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery - */ - private $plugin; - - /** - * @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $jsonEncoder; - - /** - * @var \Magento\Framework\Json\DecoderInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $jsonDecoder; - - /** - * @var \Magento\Catalog\Model\Product\Gallery\ReadHandler - */ - private $galleryHandler; - - protected function setUp() - { - $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->galleryHandler = $this->getMockBuilder(\Magento\Catalog\Model\Product\Gallery\ReadHandler::class) - ->disableOriginalConstructor() - ->setMethods(['execute']) - ->getMock(); - - $this->jsonEncoder = $this->getMock(\Magento\Framework\Json\EncoderInterface::class); - $this->jsonDecoder = $this->getMock(\Magento\Framework\Json\DecoderInterface::class); - - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['getTypeId', 'getTypeInstance']) - ->disableOriginalConstructor() - ->getMock(); - - $variationProduct = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['setMediaGalleryEntries', 'getSku', 'getMediaGalleryImages', 'getImage', 'getData']) - ->disableOriginalConstructor() - ->getMock(); - $image = new \Magento\Framework\DataObject( - ['media_type' => 'type', 'video_url' => 'url', 'file' => 'image.jpg'] - ); - $variationProduct->expects($this->any())->method('setMediaGalleryEntries')->willReturn([]); - $variationProduct->expects($this->any())->method('getSku')->willReturn('sku'); - $variationProduct->expects($this->any())->method('getMediaGalleryImages')->willReturn([$image]); - $variationProduct->expects($this->any())->method('getImage')->willReturn('image.jpg'); - $variationProduct->expects($this->any())->method('getData')->with('configurable_attribute')->willReturn(1); - - $this->galleryHandler->expects($this->once())->method('execute')->with($variationProduct); - - $configurableType = $this->getMockBuilder(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::class) - ->disableOriginalConstructor() - ->setMethods(['getUsedProducts', 'getConfigurableAttributesAsArray']) - ->getMock(); - $configurableType->expects($this->any())->method('getUsedProducts')->with($productMock) - ->willReturn([$variationProduct]); - $configurableType->expects($this->any())->method('getConfigurableAttributesAsArray')->with($productMock) - ->willReturn([['attribute_code' => 'configurable_attribute']]); - - $productMock->expects($this->any())->method('getTypeId')->willReturn('configurable'); - $productMock->expects($this->any())->method('getTypeInstance')->willReturn($configurableType); - - $this->plugin = $helper->getObject( - \Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery::class, - [ - 'productGalleryReadHandler' => $this->galleryHandler, - 'jsonEncoder' => $this->jsonEncoder, - 'jsonDecoder' => $this->jsonDecoder - ] - ); - $this->plugin->setData('product', $productMock); - } - - public function testAfterGetOptions() - { - $resultJson = '[]'; - $this->jsonDecoder->expects($this->once())->method('decode')->with('[]')->willReturn([]); - $expected = [ - 'configurable_attribute_1' => [ - [ - 'mediaType' => 'type', - 'videoUrl' => 'url', - 'isBase' => true - ] - ] - ]; - $this->jsonEncoder->expects($this->any())->method('encode')->with($expected) - ->willReturn(json_encode($expected)); - - $blockMock = $this->getMockBuilder(\Magento\ProductVideo\Block\Product\View\Gallery::class) - ->disableOriginalConstructor() - ->getMock(); - - $result = $this->plugin->afterGetOptionsMediaGalleryDataJson($blockMock, $resultJson); - $this->assertEquals(json_encode($expected), $result); - } -} diff --git a/app/code/Magento/ConfigurableProduct/etc/di.xml b/app/code/Magento/ConfigurableProduct/etc/di.xml index b4d63d9d0245f84b3ecbae128e5254e8f9bf213a..ca06ce5cc974bbab05232bdee33920ba87918ade 100644 --- a/app/code/Magento/ConfigurableProduct/etc/di.xml +++ b/app/code/Magento/ConfigurableProduct/etc/di.xml @@ -143,9 +143,6 @@ <type name="Magento\Catalog\Model\Product\Attribute\Backend\Price"> <plugin name="configurable" type="Magento\ConfigurableProduct\Model\Plugin\PriceBackend" sortOrder="100" /> </type> - <type name="\Magento\ProductVideo\Block\Product\View\Gallery"> - <plugin name="product_video_gallery" type="\Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery" /> - </type> <type name="Magento\ConfigurableProduct\Model\Product\Type\Configurable"> <arguments> <argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Collection</argument>