public function getCart($locale, $cartId = null, $customerId = null) { $cart = null; $client = $this->getClient(); if ($cartId) { $cartRequest = CartQueryRequest::of(); $predicate = 'id = "' . $cartId . '" and cartState = "' . CartState::ACTIVE . '"'; if (!is_null($customerId)) { $predicate .= ' and customerId="' . $customerId . '"'; } $cartRequest->where($predicate)->limit(1); $cartResponse = $cartRequest->executeWithClient($client); $carts = $cartRequest->mapFromResponse($cartResponse, $this->getMapper($locale)); if (!is_null($carts)) { $cart = $carts->current(); if ($cart->getCustomerId() !== $customerId) { throw new \InvalidArgumentException(); } } } if (is_null($cart)) { $cart = Cart::of($client->getConfig()->getContext()); $this->session->remove(self::CART_ID); $this->session->remove(self::CART_ITEM_COUNT); } else { $this->session->set(self::CART_ID, $cart->getId()); $this->session->set(self::CART_ITEM_COUNT, $cart->getLineItemCount()); } return $cart; }
public function getCart($cartId = null) { $cart = null; if ($cartId) { $cartRequest = CartByIdGetRequest::ofId($cartId); $this->profiler->enter($profile = new Profile('getCart')); $cartResponse = $cartRequest->executeWithClient($this->client); $this->profiler->leave($profile); $cart = $cartRequest->mapResponse($cartResponse); } if (is_null($cart)) { $cart = Cart::of($this->client->getConfig()->getContext()); } return $cart; }