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