Ejemplo n.º 1
0
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $session = new Session();
     if ($session->isStarted() == true) {
         $session->start();
     }
     $products = $this->getDoctrine()->getRepository('AppBundle:Product')->findAll();
     $prodId = $request->request->get('prod', 'noone');
     $inBasket[] = "Empty Basket, please select a product";
     if ($prodId != 'noone') {
         $product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($prodId);
         $session->set($product->getId(), $product->getName());
         $log = new Log();
         $log->setProdName($product->getName());
         $log->setDate(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($log);
         $em->flush();
         echo "Dev : Log saved to database. Product name - " . $product->getName() . " Current time - " . $log->getDate()->format('H:i:s \\O\\n Y-m-d');
         $inBasket = $session->all();
     } else {
         if ($session->count() != 0) {
             $inBasket = $session->all();
             echo "Please select a Product before submitting !!!";
         }
     }
     return $this->render('default/index.html.twig', ['products' => $products, 'basketProds' => $inBasket]);
 }