Example #1
0
 /**
  * Get get cart products for given $userId
  *
  * @param FrontendUser $user
  *
  * @return Cart|false
  */
 public function getUserCart($user)
 {
     if ($user) {
         return $this->dm->getRepository('Aisel\\CartBundle\\Document\\Cart')->findBy(array('frontenduser.id' => $user->getId()));
     }
     return [];
 }
Example #2
0
 /**
  * Find product in cart
  *
  * @param FrontendUser $user
  * @param Product $product
  *
  * @return Cart $cartItem
  */
 public function findProduct($user, $product)
 {
     $query = $this->getDocumentManager()->createQueryBuilder('Aisel\\CartBundle\\Document\\Cart')->field('product')->equals($product->getId())->field('frontenduser')->equals($user->getId());
     $cartItem = $query->getQuery()->execute()->toArray();
     if ($cartItem) {
         return $cartItem[0];
     }
     return false;
 }
Example #3
0
 /**
  *   Reset and send password by email
  */
 public function resetPassword(FrontendUser $user)
 {
     if ($user) {
         $utility = new PasswordUtility();
         $password = $utility->generatePassword();
         $user->setPlainPassword($password);
         $this->dm->persist($user);
         $this->dm->flush();
         // Send password via email
         try {
             $message = \Swift_Message::newInstance()->setSubject('Password reset')->setFrom($this->websiteEmail)->setTo($user->getEmail())->setBody($this->templating->render('AiselFrontendUserBundle:Email:newPassword.txt.twig', array('username' => $user->getUsername(), 'password' => $password)));
             $response = $this->mailer->send($message);
         } catch (\Swift_TransportException $e) {
             $response = $e->getMessage();
         }
         return $response;
     } else {
         return false;
     }
 }
Example #4
0
 /**
  * Create order for given userId
  *
  * @param FrontendUser $user
  * @param mixed        $orderInfo
  *
  * @throws LogicException
  *
  * @return Order $order
  */
 public function createOrderFromCart(FrontendUser $user, $orderInfo)
 {
     if (!$user) {
         throw new LogicException('User object is missing');
     }
     if (count($user->getCart()) == 0) {
         throw new LogicException('User cart is empty');
     }
     $order = $this->dm->getRepository('AiselOrderBundle:Order')->createOrderFromCartForUser($user, $this->getCurrencyCode($orderInfo['locale']), $orderInfo);
     return $order;
 }
Example #5
0
 /**
  * @param FrontendUser $user
  */
 protected function loginUser(FrontendUser $user)
 {
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->get('security.context')->setToken($token);
     $this->get('session')->set('_security_main', serialize($token));
 }