/** * * The cart token is saved in a cookie so we try to retrieve it. Then the customer is checked. * * @param CartRestoreEvent $cartRestoreEvent * @param $cookieName * @return CartModel * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ private function managePersistentCart(CartRestoreEvent $cartRestoreEvent, $cookieName) { // The cart cookie exists -> get the cart token $token = $this->request->cookies->get($cookieName); // Check if a cart exists for this token if (null !== ($cart = CartQuery::create()->findOneByToken($token))) { if (null !== ($customer = $this->session->getCustomerUser())) { // A customer is logged in. if (null === $cart->getCustomerId()) { // The cart created by the customer when it was not yet logged in // is assigned to it after login. $cart->setCustomerId($customer->getId())->save(); } elseif ($cart->getCustomerId() != $customer->getId()) { // The cart does not belongs to the current customer // -> clone it to create a new cart. $cart = $this->duplicateCart($cartRestoreEvent->getDispatcher(), $cart, CustomerQuery::create()->findPk($customer->getId())); } } elseif ($cart->getCustomerId() != null) { // Just duplicate the current cart, without assigning a customer ID. $cart = $this->duplicateCart($cartRestoreEvent->getDispatcher(), $cart); } } return $cart; }
/** * * The cart token is saved in a cookie so we try to retrieve it. Then the customer is checked. * * @param CartRestoreEvent $cartRestoreEvent * @param $cookieName * @return CartModel * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ protected function managePersistentCart(CartRestoreEvent $cartRestoreEvent, $cookieName) { // The cart cookie exists -> get the cart token $token = $this->request->cookies->get($cookieName); // Check if a cart exists for this token if (null !== ($cart = CartQuery::create()->findOneByToken($token))) { $cart = $this->manageCartDuplicationAtCustomerLogin($cart, $cartRestoreEvent->getDispatcher()); } return $cart; }