Skip to content

Instantly share code, notes, and snippets.

@Zayon
Last active January 31, 2019 10:43
Show Gist options
  • Save Zayon/5e58e3201c68507a12d8d35f46469a41 to your computer and use it in GitHub Desktop.
Save Zayon/5e58e3201c68507a12d8d35f46469a41 to your computer and use it in GitHub Desktop.
AddProductAction - Step 2
<?php
/** .... */
class AddProductAction
{
/** .... */
public function __invoke(Request $request)
{
$payload = json_decode($request->getContent(), true);
$category = $this->productCategoryRepository->find($payload['category']);
$product = (new Product())
->setName($payload['name'])
->setPrice($payload['price'])
->setCategory($category);
$this->entityManager->persist($product);
$this->entityManager->flush();
return new Response('Product created');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment