Ejemplo n.º 1
0
 public function viewAction($id, Request $request)
 {
     $query = new GetProductByIdQuery($id);
     $this->queryBus->handle($query);
     /** @var ProductView $product */
     $product = $query->getResult();
     $command = new UpdateProductCommand($product->getId(), $product->getName(), $product->getPrice(), $product->getCategory()->getId(), $product->getDescription(), $product->isAvailable(), $product->getImageUrl());
     $command->setProductOptions(array_map(function (ProductOptionView $optionView) {
         $productOption = new ProductOption();
         $productOption->setOption($optionView->getOption()->getId());
         $productOption->setValue($optionView->getValue());
         return $productOption;
     }, $product->getProductOptions()));
     $form = $this->formFactory->create('Shop\\Presentation\\Form\\ProductType', $command);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $this->commandBus->handle($command);
         return new RedirectResponse($this->router->generate('admin_product', ['id' => $command->getId()]));
     }
     return new Response($this->engine->render(':admin/product:form.html.twig', ['form' => $form->createView()]));
 }