public static SetCustomerEmail of(final String email) { return new SetCustomerEmail(email); }
private List<UpdateAction<Cart>> actionsToUpdateCartOnSignIn(final Cart cart, final Customer customer) { final List<UpdateAction<Cart>> updateActions = new ArrayList<>(); if (cart.getCustomerEmail() == null) { updateActions.add(SetCustomerEmail.of(customer.getEmail())); } return updateActions; }
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 SetCustomerEmail of(final String email) { return new SetCustomerEmail(email); }
@Test public void setCustomerEmail() throws Exception { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomerEmail()).isNull(); final String email = "info@commercetools.de"; final Cart cartWithEmail = client().executeBlocking(CartUpdateCommand.of(cart, SetCustomerEmail.of(email))); assertThat(cartWithEmail.getCustomerEmail()).contains(email); }
public static SetCustomerEmail of(final String email) { return new SetCustomerEmail(email); }
@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; }); } }
public static SetCustomerEmail of(final String email) { return new SetCustomerEmail(email); }
public static void withCustomerAndCart(final BlockingSphereClient client, final BiConsumer<Customer, Cart> consumer) { withCustomer(client, customer -> { final CartDraft cartDraft = CartDraft.of(EUR).withCustomerId(customer.getId()); final Cart cart = client.executeBlocking(CartCreateCommand.of(cartDraft)); consumer.accept(customer, client.executeBlocking(CartUpdateCommand.of(cart, SetCustomerEmail.of(customer.getEmail())))); }); }
public static SetCustomerEmail of(final String email) { return new SetCustomerEmail(email); }
@Test public void shouldChangeShippingMethodStateWithNonMatchingShippingMethod() throws Exception { withTaxedProduct(client(), product -> { withDynamicShippingMethodForGermany(client(), CartPredicate.of("customer.email=\"john@example.com\""), shippingMethod -> { final CartDraft cartDraft = CartDraftBuilder.of(DefaultCurrencyUnits.EUR) .country(CountryCode.DE).shippingAddress(GERMAN_ADDRESS) .customerEmail("john@example.com") .shippingMethod(shippingMethod) .lineItems(Arrays.asList(LineItemDraft.of(product.getId(), 1, 1))) .build(); withCartDraft(client(), cartDraft, cart -> { assertThat(cart.getShippingInfo().getShippingMethodState()).isEqualTo(ShippingMethodState.MATCHES_CART); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, SetCustomerEmail.of("jon@doe.com"))); final OrderFromCartCreateCommand orderCreateCommand = OrderFromCartCreateCommand.of(updatedCart); assertThatThrownBy(() -> client().executeBlocking(orderCreateCommand)) .isInstanceOf(ErrorResponseException.class) .hasMessageContaining("does not match"); final Cart cartWitUpdatedState = client().executeBlocking(CartByIdGet.of(updatedCart)); assertThat(cartWitUpdatedState.getShippingInfo().getShippingMethodState()).isEqualTo(ShippingMethodState.DOES_NOT_MATCH_CART); return cartWitUpdatedState; }); }); }); }
public static void withNonUpdatedOrder(final BlockingSphereClient client, final Customer customer, final UnaryOperator<Order> op) { withFilledCart(client, cart -> { final TaxCategory taxCategory = TaxCategoryFixtures.defaultTaxCategory(client); final SetCustomShippingMethod shippingMethodAction = SetCustomShippingMethod.of("custom shipping method", ShippingRate.of(EURO_10), taxCategory); final SetCustomerEmail emailAction = SetCustomerEmail.of(CUSTOMER_EMAIL); final Cart updatedCart = client.executeBlocking(CartUpdateCommand.of(cart, asList(shippingMethodAction, emailAction))); final CustomerSignInCommand signInCommand = CustomerSignInCommand.of(customer.getEmail(), CustomerFixtures.PASSWORD, cart.getId()); final CustomerSignInResult signInResult = client.executeBlocking(signInCommand); final Order order = client.executeBlocking(OrderFromCartCreateCommand.of(signInResult.getCart())); final Order orderToDelete = op.apply(order); client.executeBlocking(OrderDeleteCommand.of(orderToDelete)); }); }
private static Order createOrderFromCart(BlockingSphereClient client, Customer customer, Cart cart) { final TaxCategory taxCategory = TaxCategoryFixtures.defaultTaxCategory(client); final SetCustomShippingMethod shippingMethodAction = SetCustomShippingMethod.of("custom shipping method", ShippingRate.of(EURO_10), taxCategory); final SetCustomerEmail emailAction = SetCustomerEmail.of(CUSTOMER_EMAIL); client.executeBlocking(CartUpdateCommand.of(cart, asList(shippingMethodAction, emailAction))); final CustomerSignInCommand signInCommand = CustomerSignInCommand.of(customer.getEmail(), CustomerFixtures.PASSWORD, cart.getId()); final CustomerSignInResult signInResult = client.executeBlocking(signInCommand); final Order order = client.executeBlocking(OrderFromCartCreateCommand.of(signInResult.getCart())); return client.executeBlocking(OrderUpdateCommand.of(order, asList( ChangeShipmentState.of(ShipmentState.READY), ChangePaymentState.of(PaymentState.PENDING) ))); }