/**
  * TODO: remove this method after the refactoring of the product media manager
  *
  * @param ProductInterface      $product
  * @param ProductValueInterface $fromValue
  * @param ProductValueInterface $toValue
  */
 protected function duplicateMedia(ProductInterface $product, ProductValueInterface $fromValue, ProductValueInterface $toValue)
 {
     if (null === $toValue->getMedia()) {
         $media = $this->mediaFactory->createMedia();
         $toValue->setMedia($media);
     }
     $this->mediaManager->duplicate($fromValue->getMedia(), $toValue->getMedia(), $this->mediaManager->generateFilenamePrefix($product, $fromValue));
 }
 /**
  * Set media in the product value
  *
  * @param AttributeInterface $attribute
  * @param ProductInterface   $product
  * @param UploadedFile|null  $file
  * @param string|null        $locale
  * @param string|null        $scope
  */
 protected function setMedia(AttributeInterface $attribute, ProductInterface $product, UploadedFile $file = null, $locale = null, $scope = null)
 {
     $value = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null === $value) {
         $value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
     }
     if (null === ($media = $value->getMedia())) {
         $media = $this->mediaFactory->createMedia($file);
     } else {
         if (null === $file) {
             $media->setRemoved(true);
         } else {
             $media->setFile($file);
         }
     }
     $value->setMedia($media);
 }
예제 #3
0
 /**
  * Create a media from file path
  *
  * @param string $filePath
  *
  * @return ProductMediaInterface
  */
 public function createFromFilePath($filePath)
 {
     $media = $this->factory->createMedia();
     $fileName = pathinfo($filePath, PATHINFO_BASENAME);
     if ('' !== $fileName) {
         $media->setFilename(pathinfo($filePath, PATHINFO_BASENAME));
     }
     return $media;
 }