function it_uses_image_uploader_to_upload_taxon_image(GenericEvent $event, Taxon $taxon, ImageUploaderInterface $uploader)
 {
     $event->getSubject()->willReturn($taxon);
     $uploader->upload($taxon)->shouldBeCalled();
     $taxon->hasFile()->willReturn(true);
     $this->uploadTaxonImage($event);
 }
 function it_uses_image_uploader_to_upload_images(GenericEvent $event, ImageAwareInterface $subject, ImageInterface $image, ImageUploaderInterface $uploader)
 {
     $event->getSubject()->willReturn($subject);
     $subject->getImages()->willReturn([$image]);
     $image->hasFile()->willReturn(true);
     $image->getPath()->willReturn('some_path');
     $uploader->upload($image)->shouldBeCalled();
     $this->uploadImage($event);
 }
 /**
  * @param ProductVariantInterface $productVariant
  */
 private function uploadProductVariantImages(ProductVariantInterface $productVariant)
 {
     $images = $productVariant->getImages();
     foreach ($images as $image) {
         if ($image->hasFile()) {
             $this->uploader->upload($image);
         }
         // Upload failed? Let's remove that image.
         if (null === $image->getPath()) {
             $images->removeElement($image);
         }
     }
 }
 /**
  * @param ImageAwareInterface $subject
  */
 private function uploadImages(ImageAwareInterface $subject)
 {
     $images = $subject->getImages();
     foreach ($images as $image) {
         if ($image->hasFile()) {
             $this->uploader->upload($image);
         }
         // Upload failed? Let's remove that image.
         if (null === $image->getPath()) {
             $images->removeElement($image);
         }
     }
 }
Beispiel #5
0
 /**
  * @Given /^the ("[^"]+" taxon) has(?:| also) an image "([^"]+)" with a code "([^"]+)"$/
  */
 public function theTaxonHasAnImageWithACode(TaxonInterface $taxon, $imagePath, $imageCode)
 {
     $filesPath = $this->getParameter('files_path');
     $taxonImage = $this->taxonImageFactory->createNew();
     $taxonImage->setFile(new UploadedFile($filesPath . $imagePath, basename($imagePath)));
     $taxonImage->setCode($imageCode);
     $this->imageUploader->upload($taxonImage);
     $taxon->addImage($taxonImage);
     $this->objectManager->flush($taxon);
 }
 /**
  * {@inheritdoc}
  */
 public function create(array $options = [])
 {
     $options = $this->optionsResolver->resolve($options);
     /** @var ProductInterface $product */
     $product = $this->productFactory->createNew();
     $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH);
     $product->setCode($options['code']);
     $product->setEnabled($options['enabled']);
     $product->setMainTaxon($options['main_taxon']);
     $product->setCreatedAt($this->faker->dateTimeBetween('-1 week', 'now'));
     foreach ($this->getLocales() as $localeCode) {
         $product->setCurrentLocale($localeCode);
         $product->setFallbackLocale($localeCode);
         $product->setName($options['name']);
         $product->setShortDescription($options['short_description']);
         $product->setDescription($options['description']);
     }
     foreach ($options['taxons'] as $taxon) {
         $product->addTaxon($taxon);
     }
     foreach ($options['channels'] as $channel) {
         $product->addChannel($channel);
     }
     foreach ($options['product_options'] as $option) {
         $product->addOption($option);
     }
     foreach ($options['product_attributes'] as $attribute) {
         $product->addAttribute($attribute);
     }
     try {
         $this->variantGenerator->generate($product);
     } catch (\InvalidArgumentException $exception) {
         /** @var ProductVariantInterface $productVariant */
         $productVariant = $this->productVariantFactory->createNew();
         $product->addVariant($productVariant);
     }
     $i = 0;
     /** @var ProductVariantInterface $productVariant */
     foreach ($product->getVariants() as $productVariant) {
         $productVariant->setAvailableOn($this->faker->dateTimeThisYear);
         $productVariant->setPrice($this->faker->randomNumber(4));
         $productVariant->setCode(sprintf('%s-variant#%d', $options['code'], $i));
         $productVariant->setOnHand($this->faker->randomNumber(1));
         ++$i;
     }
     foreach ($options['images'] as $imageCode => $imagePath) {
         /** @var ImageInterface $productImage */
         $productImage = $this->productImageFactory->createNew();
         $productImage->setCode($imageCode);
         $productImage->setFile(new UploadedFile($imagePath, basename($imagePath)));
         $this->imageUploader->upload($productImage);
         $product->addImage($productImage);
     }
     return $product;
 }
 /**
  * @param ProductInterface $product
  * @param array $options
  */
 private function createImages(ProductInterface $product, array $options)
 {
     foreach ($options['images'] as $imageCode => $imagePath) {
         /** @var ImageInterface $productImage */
         $productImage = $this->productImageFactory->createNew();
         $productImage->setCode($imageCode);
         $productImage->setFile(new UploadedFile($imagePath, basename($imagePath)));
         $this->imageUploader->upload($productImage);
         $product->addImage($productImage);
     }
 }
Beispiel #8
0
 /**
  * @Given /^(this product) has(?:| also) an image "([^"]+)" with a code "([^"]+)"$/
  * @Given /^the ("[^"]+" product) has(?:| also) an image "([^"]+)" with a code "([^"]+)"$/
  */
 public function thisProductHasAnImageWithACode(ProductInterface $product, $imagePath, $imageCode)
 {
     $filesPath = $this->getParameter('files_path');
     /** @var ImageInterface $productImage */
     $productImage = $this->productImageFactory->createNew();
     $productImage->setFile(new UploadedFile($filesPath . $imagePath, basename($imagePath)));
     $productImage->setCode($imageCode);
     $this->imageUploader->upload($productImage);
     $product->addImage($productImage);
     $this->objectManager->flush($product);
 }