/**
  * @param Product $product
  * @param array $rowData
  * @return ProductAttributeMediaGalleryEntryInterface $entry
  */
 public function convertTo(Product $product, array $rowData)
 {
     $image = $rowData;
     $productImages = $product->getMediaAttributeValues();
     if (!isset($image['types'])) {
         $image['types'] = array_keys($productImages, $image['file']);
     }
     $entry = $this->mediaGalleryEntryFactory->create();
     $this->dataObjectHelper->populateWithArray($entry, $image, '\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
     if (isset($image['value_id'])) {
         $entry->setId($image['value_id']);
     }
     return $entry;
 }
 /**
  * {@inheritdoc}
  */
 public function getList($sku)
 {
     $result = [];
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->productRepository->get($sku);
     /** @var \Magento\Catalog\Api\Data\ProductAttributeInterface $galleryAttribute */
     $galleryAttribute = $this->attributeRepository->get('media_gallery');
     $container = new \Magento\Framework\Object(['attribute' => $galleryAttribute]);
     $gallery = $this->mediaGallery->loadGallery($product, $container);
     $productImages = $this->getMediaAttributeValues($product);
     foreach ($gallery as $image) {
         /** @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry */
         $entry = $this->entryFactory->create();
         $entry->setId($image['value_id'])->setLabel($image['label_default'])->setTypes(array_keys($productImages, $image['file']))->setDisabled($image['disabled_default'])->setPosition($image['position_default'])->setFile($image['file']);
         $result[] = $entry;
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @param array $mediaGallery
  * @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
  */
 protected function convertToMediaGalleryInterface(array $mediaGallery)
 {
     $productImages = $this->getMediaAttributeValues();
     $entries = [];
     foreach ($mediaGallery as $image) {
         if (!isset($image['types'])) {
             $image['types'] = array_keys($productImages, $image['file']);
         }
         $entry = $this->mediaGalleryEntryFactory->create();
         $this->dataObjectHelper->populateWithArray($entry, $image, '\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
         if (isset($image['value_id'])) {
             $entry->setId($image['value_id']);
         }
         $entries[] = $entry;
     }
     return $entries;
 }