Last active
January 31, 2019 10:43
-
-
Save Zayon/5e58e3201c68507a12d8d35f46469a41 to your computer and use it in GitHub Desktop.
AddProductAction - Step 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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