Beispiel #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]);
 }
Beispiel #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;
 }