Add Image to the product object


Hy ,
how to add an image to the product object ?I see that there is an addImage method inSylius\Component\Core\Model\Product , but I can not use it

public function addImage(ImageInterface $image): void

thanks for help


Hi, how did you try to add an object?

you can do this, for example:

    $uploadedImage = new UploadedFile($imagePath, basename($imagePath));

    /** @var ImageInterface $productImage */
    $productImage = $this->productImageFactory->createNew();
    $productImage->setType(end($image) ?: null);




^ this should work! :slight_smile:


thanks you , its clear now


How do I acquire the productImageFactory class?


you can inject a service sylius.factory.product_image


Thank you!:+1: that worked