/** * Return cart from session * * If session has a cart, retrieves it and checks if exists * If exists, returns it * Otherwise, creates new one * If session has not a cart, creates a new one and returns it * * @return CartInterface|null Cart */ public function getCartFromSession() { $cartIdInSession = $this->cartSessionManager->get(); if (!$cartIdInSession) { return null; } return $this->cartRepository->findOneBy(['id' => $cartIdInSession, 'ordered' => false]); }
/** * Get cart from session * * @return CartInterface|null Cart loaded from session */ protected function loadCartFromSession() { $cartIdInSession = $this->cartSessionManager->get(); if (!$cartIdInSession) { return null; } $cart = $this->cartRepository->findOneBy(['id' => $cartIdInSession, 'ordered' => false]); return $cart instanceof CartInterface ? $cart : null; }
/** * Stores cart id in HTTP session when this is saved * * @param CartOnLoadEvent $event Event */ public function saveCartInSession(CartOnLoadEvent $event) { $this->cartSessionManager->set($event->getCart()); }
/** * Stores cart id in HTTP session when this is saved * * @param CartOnLoadEvent $event Event */ public function onCartLoad(CartOnLoadEvent $event) { $this->cartSessionManager->set($event->getCart()); }