コード例 #1
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;
     }
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function setUser(\AppBundle\Entity\User $user = NULL)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUser', array($user));
     return parent::setUser($user);
 }
コード例 #3
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;
 }
コード例 #4
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;
 }