Esempio n. 1
0
 /**
  * Get all product images
  *
  * @param \Magento\Framework\Object $product
  * @param int $storeId
  * @return array
  */
 protected function _getAllProductImages($product, $storeId)
 {
     $product->setStoreId($storeId);
     $gallery = $this->_mediaAttribute->loadGallery($product, $this->_getMediaGalleryModel());
     $imagesCollection = [];
     if ($gallery) {
         $productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
         foreach ($gallery as $image) {
             $imagesCollection[] = new \Magento\Framework\Object(['url' => $productMediaPath . $image['file'], 'caption' => $image['label'] ? $image['label'] : $image['label_default']]);
         }
     }
     return $imagesCollection;
 }
 /**
  * {@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
 /**
  * {@inheritdoc}
  */
 public function getList($productSku)
 {
     $result = array();
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->productRepository->get($productSku);
     $galleryAttribute = $this->attributeFactory->create()->loadByCode($this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY), 'media_gallery');
     $container = new \Magento\Framework\Object(array('attribute' => $galleryAttribute));
     $gallery = $this->mediaGallery->loadGallery($product, $container);
     $productImages = $this->getMediaAttributeValues($product);
     foreach ($gallery as $image) {
         $this->galleryEntryBuilder->setId($image['value_id']);
         $this->galleryEntryBuilder->setLabel($image['label_default']);
         $this->galleryEntryBuilder->setTypes(array_keys($productImages, $image['file']));
         $this->galleryEntryBuilder->setDisabled($image['disabled_default']);
         $this->galleryEntryBuilder->setPosition($image['position_default']);
         $this->galleryEntryBuilder->setFile($image['file']);
         $result[] = $this->galleryEntryBuilder->create();
     }
     return $result;
 }