コード例 #1
0
ファイル: CartWrapper.php プロジェクト: hd-deman/elcodi
 /**
  * Resolve carts given customer cart and session cart
  *
  * @param CustomerInterface $customer         Customer
  * @param CartInterface     $cartFromCustomer Customer Cart
  * @param CartInterface     $cartFromSession  Cart loaded from session
  *
  * @return CartInterface Cart resolved
  */
 protected function resolveCarts(CustomerInterface $customer, CartInterface $cartFromCustomer = null, CartInterface $cartFromSession = null)
 {
     if ($cartFromCustomer) {
         return $cartFromCustomer;
     } else {
         if (!$cartFromSession) {
             /**
              * Customer has any cart not ordered, and there is no cart in
              * session.
              *
              * We create a new Cart
              */
             $cart = $this->cartFactory->create();
         } else {
             /**
              * Customer has any cart not ordered, and there is a cart loaded
              * in session.
              *
              * If customer exists as a persisted entity, we save this cart
              * as Customer cart
              */
             $cart = $cartFromSession;
             if ($customer->getId()) {
                 $cart->setCustomer($customer);
                 $customer->addCart($cart);
             }
         }
         return $cart;
     }
 }
コード例 #2
0
ファイル: CartWrapper.php プロジェクト: pramoddas/elcodi
 /**
  * Resolves a cart given a customer cart and a session cart.
  *
  * @param CustomerInterface  $customer         Customer
  * @param CartInterface|null $cartFromCustomer Customer Cart
  * @param CartInterface|null $cartFromSession  Cart loaded from session
  *
  * @return CartInterface Cart resolved
  */
 private function resolveCarts(CustomerInterface $customer, CartInterface $cartFromCustomer = null, CartInterface $cartFromSession = null)
 {
     if ($cartFromCustomer) {
         return $cartFromCustomer;
     } else {
         if (!$cartFromSession) {
             /**
              * Customer has no pending carts, and there is no cart in
              * session.
              *
              * We create a new Cart
              */
             $cart = $this->cartFactory->create();
         } else {
             /**
              * Customer has no pending carts, and there is a cart loaded
              * in session.
              *
              * If customer is not a pristine entity since it has already
              * been flushed, we associate this cart with customer
              */
             $cart = $cartFromSession;
             if ($customer->getId()) {
                 $cart->setCustomer($customer);
                 $customer->addCart($cart);
             }
         }
         return $cart;
     }
 }