private CompletionStage<Cart> setAddressToCart(final Cart cart, final Address shippingAddress, @Nullable final Address billingAddress) { final List<UpdateAction<Cart>> updateActions = new ArrayList<>(); updateActions.add(SetCountry.of(shippingAddress.getCountry())); updateActions.add(SetShippingAddress.of(shippingAddress)); updateActions.add(SetBillingAddress.of(billingAddress)); Optional.ofNullable(shippingAddress.getEmail()) .ifPresent(email -> updateActions.add(SetCustomerEmail.of(email))); final CartUpdateCommand cmd = CartUpdateCommand.of(cart, updateActions); return executeCartUpdateCommandWithHooks(cmd); } }
protected String getDisplayCountry(final Address address) { return address.getCountry().toLocale().getDisplayCountry(userContext.locale()); } }
private Location createLocation(final Address address) { final CountryCode country = address.getCountry(); final Location location; if (address.getState() != null) { location = Location.of(country, address.getState()); } else { location = Location.of(country); } return location; } }
@Test public void testUpdateAddressesToCartUpdateAction() { withFilledCartAndMultipleAddresses(client(), cart -> { final List<Address> addresses = cart.getItemShippingAddresses(); final Address firstAddress = addresses.get(0); assertThat(firstAddress.getCountry()).isNotEqualByComparingTo(CountryCode.CA); final String firstAddressKey = firstAddress.getKey(); final Address updatedAddress = Address.of(CountryCode.CA).withKey(firstAddressKey); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, UpdateItemShippingAddress.of(updatedAddress))); List<Address> newAddresses = updatedCart.getItemShippingAddresses().stream().filter(address -> address.getKey().equals(firstAddressKey)).collect(Collectors.toList()); assertThat(newAddresses).hasSize(1); assertThat(newAddresses.get(0).getCountry()).isEqualByComparingTo(CountryCode.CA); }); }
@Test public void testUpdateAddressesToOrderUpdateAction() { withFilledCartAndMultipleAddresses(client(), cart -> { withCustomer(client(),customer -> { withOrder(client(),customer,cart,order -> { final List<Address> addresses = order.getItemShippingAddresses(); final Address firstAddress = addresses.get(0); assertThat(firstAddress.getCountry()).isNotEqualByComparingTo(CountryCode.CA); final String firstAddressKey = firstAddress.getKey(); final Address updatedAddress = Address.of(CountryCode.CA).withKey(firstAddressKey); final Order updatedOrder= client().executeBlocking(OrderUpdateCommand.of(order, UpdateItemShippingAddress.of(updatedAddress))); List<Address> newAddresses = updatedOrder.getItemShippingAddresses().stream().filter(address -> address.getKey().equals(firstAddressKey)).collect(Collectors.toList()); assertThat(newAddresses).hasSize(1); assertThat(newAddresses.get(0).getCountry()).isEqualByComparingTo(CountryCode.CA); return updatedOrder; }); }); }); }
private void applyShippingAddress(final Address address) { this.titleShipping = address.getTitle(); this.firstNameShipping = address.getFirstName(); this.lastNameShipping = address.getLastName(); this.streetNameShipping = address.getStreetName(); this.additionalStreetInfoShipping = address.getAdditionalStreetInfo(); this.cityShipping = address.getCity(); this.postalCodeShipping = address.getPostalCode(); this.countryShipping = address.getCountry().getAlpha2(); this.regionShipping = address.getRegion(); this.phoneShipping = address.getPhone(); this.emailShipping = address.getEmail(); }
private void applyBillingAddress(final Address address) { this.titleBilling = address.getTitle(); this.firstNameBilling = address.getFirstName(); this.lastNameBilling = address.getLastName(); this.streetNameBilling = address.getStreetName(); this.additionalStreetInfoBilling = address.getAdditionalStreetInfo(); this.cityBilling = address.getCity(); this.postalCodeBilling = address.getPostalCode(); this.countryBilling = address.getCountry().getAlpha2(); this.regionBilling = address.getRegion(); this.phoneBilling = address.getPhone(); this.emailBilling = address.getEmail(); }