/** * @Secure(roles="ROLE_USER") * * @Route("/order", name="car_order") * @Template() */ public function orderAction() { $cart = $this->get('cart'); $cars = $cart->getCars(); if (count($cars) < 1) { // samochód jest już w koszyku $this->addFlash('error', "Nie możesz złożyć zamówienia - koszyk jest pusty."); } $user = $this->getUser(); $order = new CarOrder(); $order->setUser($user); foreach ($cars as $car) { $order->addCar($car); // aktualizuj liczbę zamówień dla samochodu $car->setNbOrders($car->getNbOrders() + 1); } $em = $this->getDoctrine()->getManager(); $em->persist($order); $em->flush(); // wyczyść koszyk $cart->clear(); // wyślij miala ze szczegółami płatności $mailer = $this->get('mailer'); $message = $mailer->createMessage()->setSubject('CarShop.pl - potwierdzenie zamówienia')->setFrom('*****@*****.**')->setTo($user->getEmail())->setBody($this->renderView('AppBundle:Car:emailConfirmation.html.twig', array('user' => $user)), 'text/html'); $mailer->send($message); $this->addFlash('notice', "Zamówienie zostało zapisane. Na podany adres e-mail zostały wysłane informacje na temat płatności."); return $this->redirectToRoute('order_confirm', array('id' => $order->getId())); }
/** *tworzenie zamowienia * @param Entity\Car $car * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function rentAction(Entity\Car $car) { $user = $this->get('security.token_storage')->getToken()->getUser(); $order = new Entity\CarOrder(); $order->setCar($car); $order->setUser($user); $order->setDateFrom(new \DateTime()); $order->setDateTo((new \DateTime())->add(new \DateInterval('P1D'))); $em = $this->getDoctrine()->getManager(); $em->persist($order); $em->flush(); return $this->redirectToRoute('app_orders'); }