/** * @Route("/order/checkout") */ public function checkoutAction(Request $request) { $session = $request->getSession(); $cart = $session->get('cart', []); $order = new Order(); $order->setDate(new \DateTime()); $order->setStatus(Order::STATUS_PENDING); $order->setCustomer($this->get('security.token_storage')->getToken()->getUser()); $service = $this->get('ProductService'); $items = new ArrayCollection(); foreach ($cart as $product) { $item = new Item(); $item->setProduct($service->getProduct($product['id'])); $item->setQuantity($product['quantity']); $items->add($item); } $order->setItems($items); $em = $this->getDoctrine()->getEntityManager(); $em->persist($order); $em->flush(); $session->remove('cart'); return $this->render('order/checkout.html.twig', ['order' => $order]); }
/** * {@inheritDoc} */ public function setDate($date) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setDate', array($date)); return parent::setDate($date); }