Skip to content

Instantly share code, notes, and snippets.

@shyim
Created February 26, 2020 13:01
Show Gist options
  • Select an option

  • Save shyim/2a112e76aa58a9dbeaa6afa6250d0d6d to your computer and use it in GitHub Desktop.

Select an option

Save shyim/2a112e76aa58a9dbeaa6afa6250d0d6d to your computer and use it in GitHub Desktop.
Create media in shopware 6
$mediaId = Uuid::randomHex();
$mediaRepository->create([['id' => $mediaId]], Context::createDefaultContext());
$request = new Request();
$request->headers->set('content_type', 'application/json');
$request->query->set('extension', 'png');
$request->request->set('url', 'https://placekitten.com/200/287');
$mediaFile = $mediaService->fetchFile($request);
$fileSaver->persistFileToMedia(
$mediaFile,
'kitten',
$mediaId,
Context::createDefaultContext()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment