/** * The cart token is not saved in a cookie, if the cart is present in session, we just change the customer id * if needed or create duplicate the current cart if the customer is not the same as customer already present in * the cart. * * @param CartRestoreEvent $cartRestoreEvent * @return CartModel * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ private function manageNonPersistentCookie(CartRestoreEvent $cartRestoreEvent) { $cart = $cartRestoreEvent->getCart(); if (null === $cart) { $cart = $cart = $this->dispatchNewCart($cartRestoreEvent->getDispatcher()); } else { 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())); } } else { $cart->setCustomerId(null)->save(); } } return $cart; }
/** * The cart token is not saved in a cookie, if the cart is present in session, we just change the customer id * if needed or create duplicate the current cart if the customer is not the same as customer already present in * the cart. * * @param CartRestoreEvent $cartRestoreEvent * @return CartModel * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ protected function manageNonPersistentCookie(CartRestoreEvent $cartRestoreEvent) { $cart = $cartRestoreEvent->getCart(); if (null === $cart) { $cart = $this->dispatchNewCart($cartRestoreEvent->getDispatcher()); } else { $cart = $this->manageCartDuplicationAtCustomerLogin($cart, $cartRestoreEvent->getDispatcher()); } return $cart; }