public function testOfAddress()
 {
     $address = Address::fromArray(['title' => 'mr', 'salutation' => 'mr', 'firstName' => 'Piet', 'lastName' => 'Fiets', 'email' => '*****@*****.**', 'streetName' => 'Akelei', 'streetNumber' => '23', 'building' => 'a', 'Apartment' => 'c', 'postalCode' => '7676dc', 'city' => 'westerhaar', 'country' => 'netherlands', 'region' => 'drenthe', 'state' => 'honkie kong', 'POBox' => '49824', 'AdditionalAddressInfo' => 'null', 'AdditionalStreetInfo' => 'null', 'phone' => '0546659948', 'mobile' => '0620923399', 'department' => '1']);
     $userAddress = UserAddress::ofAddress($address);
     $this->assertInstanceOf('\\Commercetools\\Symfony\\CtpBundle\\Entity\\UserAddress', $userAddress);
     $this->assertSame($address->getTitle(), $userAddress->getTitle());
     $this->assertSame($address->getSalutation(), $userAddress->getSalutation());
     $this->assertSame($address->getFirstName(), $userAddress->getFirstName());
     $this->assertSame($address->getLastName(), $userAddress->getLastName());
     $this->assertSame($address->getEmail(), $userAddress->getEmail());
     $this->assertSame($address->getStreetName(), $userAddress->getStreetName());
     $this->assertSame($address->getStreetNumber(), $userAddress->getStreetNumber());
     $this->assertSame($address->getBuilding(), $userAddress->getBuilding());
     $this->assertSame($address->getApartment(), $userAddress->getApartment());
     $this->assertSame($address->getPostalCode(), $userAddress->getPostalCode());
     $this->assertSame($address->getCity(), $userAddress->getCity());
     $this->assertSame($address->getCountry(), $userAddress->getCountry());
     $this->assertSame($address->getRegion(), $userAddress->getRegion());
     $this->assertSame($address->getState(), $userAddress->getState());
     $this->assertSame($address->getPOBox(), $userAddress->getPOBox());
     $this->assertSame($address->getAdditionalAddressInfo(), $userAddress->getAdditionalAddressInfo());
     $this->assertSame($address->getAdditionalStreetInfo(), $userAddress->getAdditionalStreetInfo());
     $this->assertSame($address->getPhone(), $userAddress->getPhone());
     $this->assertSame($address->getMobile(), $userAddress->getMobile());
     $this->assertSame($address->getDepartment(), $userAddress->getDepartment());
 }
 public function testOfeditAddress()
 {
     $this->markTestIncomplete();
     $addressId = '';
     $addressChange = CustomerChangeAddressAction::ofAddressIdAndAddress($addressId);
     $address = Address::fromArray(['title' => 'mr', 'salutation' => 'mr', 'firstName' => 'Piet', 'lastName' => 'Fiets', 'email' => '*****@*****.**', 'streetName' => 'Akelei', 'streetNumber' => '23', 'building' => 'a', 'Apartment' => 'c', 'postalCode' => '7676dc', 'city' => 'westerhaar', 'country' => 'netherlands', 'region' => 'drenthe', 'state' => 'honkie kong', 'POBox' => '49824', 'AdditionalAddressInfo' => 'null', 'AdditionalStreetInfo' => 'null', 'phone' => '0546659948', 'mobile' => '0620923399', 'department' => '1']);
     //        $userAddress = User
 }
 public function editAddressAction(Request $request, $addressId)
 {
     /**
      * @var User $user
      */
     $customerId = $this->get('security.token_storage')->getToken()->getUser()->getId();
     $repository = $this->get('commercetools.repository.customer');
     $customer = $repository->getCustomer($request->getLocale(), $customerId);
     $address = $customer->getAddresses()->getById($addressId);
     $entity = UserAddress::ofAddress($address);
     $form = $this->createFormBuilder(['address' => $entity->toArray()])->add('address', AddressType::class)->add('Submit', SubmitType::class)->getForm();
     $form->handleRequest($request);
     if ($form->isValid() && $form->isSubmitted()) {
         $address = Address::fromArray($form->get('address')->getData());
         $submit = $repository->setAddresses($request->getLocale(), $customer, $address, $addressId);
     }
     return $this->render('CtpBundle:User:editAddress.html.twig', ['form_address' => $form->createView()]);
 }
 /**
  * @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;
 }
 public function setAddressAction(Request $request)
 {
     $user = $this->getUser();
     if (!is_null($user)) {
         $customerId = $this->get('security.token_storage')->getToken()->getUser()->getId();
         $customer = $this->get('commercetools.repository.customer')->getCustomer($request->getLocale(), $customerId);
     } else {
         $customerId = null;
         $customer = null;
     }
     $session = $this->get('session');
     $cartId = $session->get(CartRepository::CART_ID);
     $cart = $this->get('commercetools.repository.cart')->getCart($request->getLocale(), $cartId, $customerId);
     if (is_null($cart->getId())) {
         return $this->redirect($this->generateUrl('_ctp_example_cart'));
     }
     $entity = CartEntity::ofCart($cart);
     if (!is_null($customer) && count(array_diff_key($cart->getShippingAddress()->toArray(), ['country' => true])) == 0) {
         $address = $customer->getDefaultShippingAddress();
         $entity->shippingAddress = $address->toArray();
     }
     $form = $this->createFormBuilder($entity)->add('check', CheckboxType::class, ['required' => false, 'label' => 'Shipping and Billing addresses are the same ', 'empty_data' => NULL])->add('shippingAddress', AddressType::class)->add('billingAddress', AddressType::class)->add('Submit', SubmitType::class)->getForm();
     $form->handleRequest($request);
     $repository = $this->get('commercetools.repository.cart');
     if ($form->isValid() && $form->isSubmitted()) {
         $check = $form->get('check')->getData();
         $shippingAddress = Address::fromArray($form->get('shippingAddress')->getData());
         $billingAddress = null;
         if ($check !== true) {
             $billingAddress = Address::fromArray($form->get('billingAddress')->getData());
         }
         $cart = $repository->setAddresses($request->getLocale(), $cartId, $shippingAddress, $billingAddress, $customerId);
         if (!is_null($cart)) {
             return $this->redirect($this->generateUrl('_ctp_example_checkout_shipping'));
         }
     }
     return $this->render('CtpBundle:checkout:checkout.html.twig', ['form' => $form->createView()]);
 }
 /**
  * @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;
 }
 /**
  * @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;
 }