/** * @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); } }
/** * @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); }