/** * @Route("/panier/commander", name="commander_panier") * @Template() */ public function commanderAction(Request $request) { $em = $this->getDoctrine()->getManager(); $panier = $request->getSession()->get('panier'); if ($panier == null || empty($panier)) { die; } $chewingGumRepo = $this->getDoctrine()->getRepository('AppBundle:ChewingGums'); $commande = new Commande(); $commande->setDate(new \DateTime("now"))->setUser($this->getUser()); $em->persist($commande); $em->flush(); foreach ($panier as $CG => $qtt) { $chewingGum = $chewingGumRepo->findOneBy(['id' => $CG]); $lnkCommandeCG = new LnkCommandeChewingGums(); $lnkCommandeCG->setQuantite($qtt)->setCommande($commande)->setChewingGums($chewingGum); $em->persist($lnkCommandeCG); $em->flush(); } $request->getSession()->set('panier', null); $this->get('session')->getFlashBag()->add('notice', 'Votre commande a bien été enregistrée. Un mail récapitulatif vous a été envoyé. Vous serez livré sous peu!'); return $this->redirectToRoute('home'); }
/** * Creates a form to delete a Commande entity. * * @param Commande $commande The Commande entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Commande $commande) { return $this->createFormBuilder()->setAction($this->generateUrl('commande_delete', array('id' => $commande->getId())))->setMethod('DELETE')->getForm(); }