How to create products with media using Shopware 6 Admin API PHP SDK?
Shopware 6 Management API PHP SDK
I know how to create a product using the following code snippet.
$productRepository->create([ 'id' => Uuid::randomHex(), 'name' => 'New Product', 'taxId' => $product->taxId, 'price' => $product->price, 'productNumber' => $product->productNumber . random_int(10, 1000), 'stock' => $product->stock, 'media' => $product->media, //Not working ], $context);
And how to upload media from a URL containing the following code snippet.
$mediaService->uploadMediaFromUrl($mediaId, $url, 'jpg', 'test-media');
But how do I add media to the product?
media
An association is a collection ofproduct_media
entities that act as a mapping tomedia
entities. After uploading a file to create amedia
entity based on a URL, you can use that ID to create aproduct_media
mapping when creating a product.