/**
  * @param $cartId
  * @param $currency
  * @param $country
  * @return Cart|null
  */
 public function createCart($locale, $currency, $country, LineItemDraftCollection $lineItems, $customerId = null)
 {
     $client = $this->getClient();
     $shippingMethodResponse = $this->shippingMethodRepository->getByCountryAndCurrency($locale, $country, $currency);
     $cartDraft = CartDraft::ofCurrency($currency)->setCountry($country)->setShippingAddress(Address::of()->setCountry($country))->setLineItems($lineItems);
     if (!is_null($customerId)) {
         $cartDraft->setCustomerId($customerId);
     }
     if (!$shippingMethodResponse->isError()) {
         /**
          * @var ShippingMethodCollection $shippingMethods
          */
         $shippingMethods = $shippingMethodResponse->toObject();
         $cartDraft->setShippingMethod($shippingMethods->current()->getReference());
     }
     $cartCreateRequest = CartCreateRequest::ofDraft($cartDraft);
     $cartResponse = $cartCreateRequest->executeWithClient($client);
     $cart = $cartCreateRequest->mapFromResponse($cartResponse, $this->getMapper($locale));
     $this->session->set(self::CART_ID, $cart->getId());
     $this->session->set(self::CART_ITEM_COUNT, $cart->getLineItemCount());
     return $cart;
 }
 /**
  * @param $cartId
  * @param $currency
  * @param $country
  * @return Cart|null
  */
 public function createCart($currency, $country, LineItemDraftCollection $lineItems)
 {
     $shippingMethodResponse = $this->shippingMethodRepository->getByCountryAndCurrency($country, $currency);
     $cartDraft = CartDraft::ofCurrency($currency)->setCountry($country)->setShippingAddress(Address::of()->setCountry($country))->setLineItems($lineItems);
     if (!$shippingMethodResponse->isError()) {
         /**
          * @var ShippingMethodCollection $shippingMethods
          */
         $shippingMethods = $shippingMethodResponse->toObject();
         $cartDraft->setShippingMethod($shippingMethods->current()->getReference());
     }
     $cartCreateRequest = CartCreateRequest::ofDraft($cartDraft);
     $this->profiler->enter($profile = new Profile('createCart'));
     $cartResponse = $cartCreateRequest->executeWithClient($this->client);
     $this->profiler->leave($profile);
     $cart = $cartCreateRequest->mapResponse($cartResponse);
     return $cart;
 }
 /**
  * @return Address
  */
 public function toCTPAddress()
 {
     $newAddress = Address::of();
     $newAddress->setTitle($this->getTitle());
     $newAddress->setSalutation($this->getSalutation());
     $newAddress->setCompany($this->getCompany());
     $newAddress->setFirstName($this->getFirstName());
     $newAddress->setLastName($this->getLastName());
     $newAddress->setEmail($this->getEmail());
     $newAddress->setStreetName($this->getStreetName());
     $newAddress->setStreetNumber($this->getStreetNumber());
     $newAddress->setBuilding($this->getBuilding());
     $newAddress->setApartment($this->getApartment());
     $newAddress->setPostalCode($this->getPostalCode());
     $newAddress->setCity($this->getCity());
     $newAddress->setCountry($this->getCountry());
     $newAddress->setRegion($this->getRegion());
     $newAddress->setState($this->getState());
     $newAddress->setPOBox($this->getPOBox());
     $newAddress->setAdditionalAddressInfo($this->getAdditionalAddressInfo());
     $newAddress->setAdditionalStreetInfo($this->getAdditionalStreetInfo());
     $newAddress->setPhone($this->getPhone());
     $newAddress->setMobile($this->getMobile());
     $newAddress->setDepartment($this->getDepartment());
     return $newAddress;
 }