Ejemplo n.º 1
0
 public function load(ObjectManager $manager)
 {
     $productFirst = new Cart();
     $productFirst->setName('produkt A');
     $manager->persist($productFirst);
     $productSecond = new Cart();
     $productSecond->setName('produkt B');
     $manager->persist($productSecond);
     $productThird = new Cart();
     $productThird->setName('produkt C');
     $manager->persist($productThird);
     $manager->flush();
 }
Ejemplo n.º 2
0
 /**
  * Get count of product in the cart
  *
  * @return mixed
  */
 public function getCart()
 {
     $user = $this->user;
     if ($user instanceof User) {
         $cart = $this->em->getRepository("AppBundle:Cart")->findOneBy(array('user' => $user->getId()));
         if (!$cart) {
             $cart = new Cart();
             $cart->setUser($user);
             $this->em->persist($cart);
             $this->em->flush();
         }
         return count($cart->getDishes());
     } else {
         return 0;
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getUser()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getUser', array());
     return parent::getUser();
 }
Ejemplo n.º 4
0
 /**
  * Gets cart from User object or creates new
  * @return Cart
  */
 private function getCart()
 {
     $user = $this->getUser();
     dump($user);
     die;
     if (!$user) {
         return $this->redirectToRoute('login');
     }
     $cart = $user->getActiveCart();
     if (!$cart) {
         $cart = new Cart();
         $cart->setUser($user);
         $em = $this->getDoctrine()->getManager();
         $em->persist($cart);
         $em->flush();
     }
     return $cart;
 }
Ejemplo n.º 5
0
 /**
  * Gets cart from User object or creates new
  * @return Cart
  */
 private function getCart()
 {
     $user = $this->getUser();
     $cart = $user->getActiveCart();
     if ($cart === false) {
         $cart = new Cart();
         $cart->setUser($user);
         $em = $this->getDoctrine()->getManager();
         $em->persist($cart);
         $em->flush();
     }
     return $cart;
 }