public static SetShippingAddress of(final Address address) { return of(Optional.of(address)); }
public static SetShippingAddress of(final Optional<Address> address) { return new SetShippingAddress(address); }
public static SetShippingAddress of(final Address address) { return of(Optional.of(address)); }
public static SetShippingAddress of(final Optional<Address> address) { return new SetShippingAddress(address); }
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); } }
public static SetShippingAddress of(@Nullable final Address address) { return new SetShippingAddress(address); }
/** * Updates the country of the cart, both {@code country} and {@code shippingAddress} country fields. * This is necessary in order to obtain prices with tax calculation. * @param cart the cart which country needs to be updated * @param country the country to set in the cart * @param expansionPathContainer expansion paths to be honored * @return the completionStage of a cart with the given country */ private CompletionStage<Cart> updateCartCountry(final Cart cart, final CountryCode country, final ExpansionPathContainer<Cart> expansionPathContainer) { // TODO Handle case where some line items do not exist for this country final Address shippingAddress = Optional.ofNullable(cart.getShippingAddress()) .map(address -> address.withCountry(country)) .orElseGet(() -> Address.of(country)); final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, asList(SetShippingAddress.of(shippingAddress), SetCountry.of(country))) .withExpansionPaths(expansionPathContainer); return injector.getInstance(SphereClient.class).execute(updateCommand); } }
public static SetShippingAddress of(@Nullable final Address address) { return new SetShippingAddress(address); }
public static Cart createCartWithShippingAddress(final BlockingSphereClient client) { final Cart cart = createCartWithCountry(client); return client.executeBlocking(CartUpdateCommand.of(cart, SetShippingAddress.of(GERMAN_ADDRESS))); }
public static SetShippingAddress of(@Nullable final Address address) { return new SetShippingAddress(address); }
@Test public void execution() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCart(client(), cart -> { final Cart cartWithShippingAddress = client().executeBlocking(CartUpdateCommand.of(cart, SetShippingAddress.of(GERMAN_ADDRESS))); final SphereRequest<List<ShippingMethod>> sphereRequest = new VrapRequestDecorator<>(ShippingMethodsByCartGet.of(cartWithShippingAddress).plusExpansionPaths(exp -> exp.taxCategory()), "response"); final List<ShippingMethod> shippingMethods = client().executeBlocking(sphereRequest); assertThat(shippingMethods).isNotEmpty(); for (final ShippingMethod cartShippingMethod : shippingMethods) { final List<ShippingRate> shippingRates = cartShippingMethod.getZoneRates().stream() .flatMap(zoneRate -> zoneRate.getShippingRates().stream()) .collect(Collectors.toList()); assertThat(shippingRates).areExactly(1, new Condition<>(ShippingRate::isMatching, "Shipping rate is matching")); assertThat(cartShippingMethod.getTaxCategory().getObj()).isNotNull(); } return cartWithShippingAddress; }); }); }
@Test public void shouldReturnShippingMethodWithMatchingPredicate() throws Exception { final CartPredicate cartPredicate = CartPredicate.of("customer.email=\"john@example.com\""); withUpdateableDynamicShippingMethodForGermany(client(), cartPredicate, shippingMethod -> { withCart(client(), cart -> { final List<UpdateActionImpl<Cart>> updateActions = Arrays.asList(SetShippingAddress.of(GERMAN_ADDRESS), SetCustomerEmail.of("john@example.com")); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, updateActions)); final SphereRequest<List<ShippingMethod>> sphereRequest = new VrapRequestDecorator<>(ShippingMethodsByCartGet.of(updatedCart), "response"); final List<ShippingMethod> shippingMethods = client().executeBlocking(sphereRequest); assertThat(shippingMethods).isNotEmpty(); for (final ShippingMethod cartShippingMethod : shippingMethods) { final List<ShippingRate> shippingRates = cartShippingMethod.getZoneRates().stream() .flatMap(zoneRate -> zoneRate.getShippingRates().stream()) .collect(Collectors.toList()); assertThat(shippingRates).areExactly(1, new Condition<>(ShippingRate::isMatching, "Shipping rate is matching")); } return updatedCart; }); return shippingMethod; }); } }
@Test public void setShippingAddress() throws Exception { final Cart cart = createCartWithCountry(client()); assertThat(cart.getShippingAddress()).isNull(); final Address address = AddressBuilder.of(DE).build(); final Cart cartWithAddress = client().executeBlocking(CartUpdateCommand.of(cart, SetShippingAddress.of(address))); assertThat(cartWithAddress.getShippingAddress()).isEqualTo(address); //you can query by shippingAddress fields final CartQuery query = CartQuery.of() .withPredicates(m -> m.shippingAddress().country().is(DE).and(m.id().is(cart.getId()))); assertThat(client().executeBlocking(query).head()).contains(cartWithAddress); final Cart cartWithoutAddress = client().executeBlocking(CartUpdateCommand.of(cartWithAddress, SetShippingAddress.of(null))); assertThat(cartWithoutAddress.getShippingAddress()).isNull(); }
withCustomer(client(), customer -> { withCartHavingDiscountedCustomLineItem(client(),relativeCartDiscountValue, cart -> { client().executeBlocking(CartUpdateCommand.of(cart, Arrays.asList(SetShippingAddress.of(Address.of(CountryCode.DE)),SetShippingMethod.of(shippingMethod)))); withCartDiscount(client(), builder -> builder .value(relativeCartDiscountValue)