예제 #1
0
 /**
  * @param ProductInterface $product
  * @param array $newEntry
  * @return $this
  * @throws InputException
  * @throws StateException
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function processNewMediaGalleryEntry(ProductInterface $product, array $newEntry)
 {
     /** @var ImageContentInterface $contentDataObject */
     $contentDataObject = $newEntry['content'];
     /** @var \Magento\Catalog\Model\Product\Media\Config $mediaConfig */
     $mediaConfig = $product->getMediaConfig();
     $mediaTmpPath = $mediaConfig->getBaseTmpMediaPath();
     $relativeFilePath = $this->imageProcessor->processImageContent($mediaTmpPath, $contentDataObject);
     $tmpFilePath = $mediaConfig->getTmpMediaShortUrl($relativeFilePath);
     if (!$product->hasGalleryAttribute()) {
         throw new StateException(__('Requested product does not support images.'));
     }
     $imageFileUri = $this->getMediaGalleryProcessor()->addImage($product, $tmpFilePath, isset($newEntry['types']) ? $newEntry['types'] : [], true, isset($newEntry['disabled']) ? $newEntry['disabled'] : true);
     // Update additional fields that are still empty after addImage call
     $this->getMediaGalleryProcessor()->updateImage($product, $imageFileUri, ['label' => $newEntry['label'], 'position' => $newEntry['position'], 'disabled' => $newEntry['disabled'], 'media_type' => $newEntry['media_type']]);
     return $this;
 }