Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * @covers \Magento\Catalog\Model\Product\Gallery\ReadHandler::execute
  */
 public function testExecute()
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $product->setId(1);
     $this->readHandler->execute('Magento\\Catalog\\Api\\Data\\ProductInterface', $product);
     $data = $product->getData();
     $this->assertArrayHasKey('media_gallery', $data);
     $this->assertArrayHasKey('images', $data['media_gallery']);
     $this->assertEquals('Image Alt Text', $data['media_gallery']['images'][0]['label']);
 }
 /**
  * @covers \Magento\Catalog\Model\Product\Gallery\ReadHandler::execute
  */
 public function testExecute()
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     /**
      * @var $entityMetadata \Magento\Framework\Model\Entity\EntityMetadata
      */
     $entityMetadata = $this->objectManager->get(MetadataPool::class)->getMetadata(ProductInterface::class);
     $productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
     $linkFieldId = $productRepository->get('simple')->getData($entityMetadata->getLinkField());
     $product->setData($entityMetadata->getLinkField(), $linkFieldId);
     $this->readHandler->execute('Magento\\Catalog\\Api\\Data\\ProductInterface', $product);
     $data = $product->getData();
     $this->assertArrayHasKey('media_gallery', $data);
     $this->assertArrayHasKey('images', $data['media_gallery']);
     $this->assertEquals('Image Alt Text', $data['media_gallery']['images'][0]['label']);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function execute($entityType, $product)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'execute');
     if (!$pluginInfo) {
         return parent::execute($entityType, $product);
     } else {
         return $this->___callPlugins('execute', func_get_args(), $pluginInfo);
     }
 }