public static SetCountry of(final CountryCode country) { return of(Optional.of(country)); }
public static SetCountry of(final Optional<CountryCode> country) { return new SetCountry(country); }
public static SetCountry of(final CountryCode country) { return of(Optional.of(country)); }
public static SetCountry of(final Optional<CountryCode> country) { return new SetCountry(country); }
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 SetCountry of(@Nullable final CountryCode country) { return new SetCountry(country); }
/** * 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 SetCountry of(@Nullable final CountryCode country) { return new SetCountry(country); }
private void withCustomerCustomerCartAndAnonymousCart(final BlockingSphereClient client, final Function<Customer, Function<Cart, Consumer<Cart>>> curriedFunctions) { CustomerFixtures.withCustomerAndCart(client(), ((customer, cart) -> { ProductFixtures.withTaxedProduct(client(), product -> { final Cart customerCartWithProduct = client.executeBlocking(CartUpdateCommand.of(cart, asList(SetCountry.of(CountryCode.DE), AddLineItem.of(product, 1, 3L)))); final Cart anonymousCart = CartFixtures.createCartWithCountry(client()); final Cart anonymousCartWithProduct = client.executeBlocking(CartUpdateCommand.of(anonymousCart, asList(SetCountry.of(CountryCode.DE), AddLineItem.of(product, 1, 7L)))); curriedFunctions.apply(customer).apply(customerCartWithProduct).accept(anonymousCartWithProduct); }); })); }
public static SetCountry of(@Nullable final CountryCode country) { return new SetCountry(country); }
@Test public void setCountry() throws Exception { final Cart cart = createCartWithoutCountry(client()); assertThat(cart.getCountry()).isNull(); final Cart cartWithCountry = client().executeBlocking(CartUpdateCommand.of(cart, SetCountry.of(DE))); assertThat(cartWithCountry.getCountry()).isEqualTo(DE); final Cart cartWithoutCountry = client().executeBlocking(CartUpdateCommand.of(cartWithCountry, SetCountry.of(null))); assertThat(cartWithoutCountry.getCountry()).isNull(); }