예제 #1
0
 /**
  * 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]);
 }
예제 #2
0
 /**
  * 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());
 }
예제 #4
0
 /**
  * Stores cart id in HTTP session when this is saved
  *
  * @param CartOnLoadEvent $event Event
  */
 public function onCartLoad(CartOnLoadEvent $event)
 {
     $this->cartSessionManager->set($event->getCart());
 }