/**
  * Returns product photo model
  *
  * @param MediaInterface   $media
  * @param ProductInterface $modelData
  * @param array            $values
  *
  * @return ProductPhoto
  */
 protected function getProductPhoto(MediaInterface $media, ProductInterface $modelData, $values)
 {
     $mainPhoto = $this->isMainPhoto($media, $values['main']);
     $productPhoto = new ProductPhoto();
     $productPhoto->setPhoto($media);
     $productPhoto->setMainPhoto($mainPhoto);
     $productPhoto->setProduct($modelData);
     if ($mainPhoto) {
         $modelData->setPhoto($media);
     }
     return $productPhoto;
 }
Ejemplo n.º 2
0
 protected function getPhotos(Product $product, ObjectManager $manager)
 {
     $productPhotos = new ArrayCollection();
     $mediaFiles = $this->randomizeSamples('photo', LoadMediaData::$samples, 3);
     $isMainPhoto = true;
     foreach ($mediaFiles as $media) {
         $productPhoto = new ProductPhoto();
         $productPhoto->setHierarchy(0);
         $productPhoto->setMainPhoto($isMainPhoto);
         $productPhoto->setPhoto($media);
         $productPhoto->setProduct($product);
         $manager->persist($productPhoto);
         if ($isMainPhoto) {
             $product->setPhoto($media);
             $isMainPhoto = false;
         }
         $productPhotos->add($productPhoto);
     }
     return $productPhotos;
 }