Ejemplo n.º 1
0
 /**
  * @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]);
 }
Ejemplo n.º 2
0
 /**
  * @Route("/basket-save", name="basket_save", options={"expose" = true})
  * @Template()
  */
 public function saveBasketAction(Request $request)
 {
     $session = $request->getSession();
     $lists = $session->get('lists');
     $group = hash('sha256', time());
     $em = $this->getDoctrine()->getManager();
     foreach ($lists as $id => $list) {
         $banner = $this->getDoctrine()->getRepository('AppBundle:banner')->findOneById($id);
         $order = new Order();
         $order->setBanner($banner);
         $order->setClient($this->getUser());
         $order->setPrice($banner->getPrice());
         $order->setOrderGroup($group);
         $order->setStatus(0);
         $order->setEnabled(true);
         $em->persist($order);
         $em->flush($order);
         $em->refresh($order);
         $months = unserialize($lists[$id]['months']);
         foreach ($months as $date => $val) {
             if ($val) {
                 $month = new OrderMonth();
                 $date = new \DateTime($date . '-01 00:00:00');
                 $month->setDate($date);
                 $month->setOrder($order);
                 $month->setEnabled(1);
                 $em->persist($month);
                 $em->flush($month);
                 $em->refresh($month);
             }
         }
     }
     $banners = $this->getDoctrine()->getRepository('AppBundle:Order')->findByOrderGroup($group);
     return array('banners' => $banners, 'group' => $group);
 }