public static SetCustomerId of(final String customerId) { return of(Optional.of(customerId)); }
public static SetCustomerId of(final Optional<String> customerId) { return new SetCustomerId(customerId); }
@Test public void setCustomerId() throws Exception { withCustomer(client(), customer -> { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomerId()).isNull(); final Cart cartWithCustomerId = client().executeBlocking(CartUpdateCommand.of(cart, SetCustomerId.ofCustomer(customer))); assertThat(cartWithCustomerId.getCustomerId()).contains(customer.getId()); final Cart cartWithoutCustomerId = client().executeBlocking(CartUpdateCommand.of(cartWithCustomerId, SetCustomerId.empty())); assertThat(cartWithoutCustomerId.getCustomerId()).isNull(); }); }
withCustomer(client(), customer -> { withFilledCart(client(), cart -> { final Cart cartWithCustomer = client().executeBlocking(CartUpdateCommand.of(cart, SetCustomerId.ofCustomer(customer)));
public static SetCustomerId ofCustomer(@Nullable final Referenceable<Customer> customer) { return of(Optional.ofNullable(customer).map(c -> c.toReference().getId()).orElse(null)); }
public static SetCustomerId empty() { return new SetCustomerId(null); }
public static SetCustomerId ofCustomer(@Nullable final Referenceable<Customer> customer) { return of(Optional.ofNullable(customer).map(c -> c.toReference().getId()).orElse(null)); }
public static SetCustomerId empty() { return new SetCustomerId(null); }
public static SetCustomerId ofCustomer(@Nullable final Referenceable<Customer> customer) { return of(Optional.ofNullable(customer).map(c -> c.toReference().getId()).orElse(null)); }
public static SetCustomerId empty() { return new SetCustomerId(null); }
public static SetCustomerId of(final Referenceable<Customer> customer) { return of(Optional.of(customer.toReference().getId())); }
public static SetCustomerId of(@Nullable final String customerId) { return new SetCustomerId(customerId); }
public static void withCustomerAndFilledCart(final BlockingSphereClient client, final BiConsumer<Customer, Cart> consumer) { withCustomer(client, customer -> { withFilledCart(client, cart -> { final Cart cartForCustomer = client.executeBlocking(CartUpdateCommand.of(cart, SetCustomerId.of(customer.getId()))); consumer.accept(customer, cartForCustomer); }); }); }
public static SetCustomerId of(@Nullable final String customerId) { return new SetCustomerId(customerId); }
public static void withCartHavingCartDiscountedLineItem(final BlockingSphereClient client, final RelativeCartDiscountValue relativeCartDiscountValue, final UnaryOperator<Cart> op) { withTaxedProduct(client, product -> { withCustomer(client, (customer) -> { CartDiscountFixtures.withCartDiscount(client, builder -> builder .cartPredicate(CartPredicate.of("customer.id=\"" + customer.getId() + "\"")) .value(relativeCartDiscountValue) .target(LineItemsTarget.of("product.id=\"" + product.getId() + "\"")), cartDiscount -> { withCart(client, (cart) -> { assertThat(cart.getLineItems()).hasSize(0); final long quantity = 3; final String productId = product.getId(); final AddLineItem addLineItemAction = AddLineItem.of(productId, 1, quantity); final List<UpdateAction<Cart>> updateActions = asList(addLineItemAction, SetCustomerId.of(customer.getId()), Recalculate.of().withUpdateProductData(true)); final Cart updatedCart = client.executeBlocking(CartUpdateCommand.of(cart, updateActions)); final Cart cartToDelete = op.apply(updatedCart); return cartToDelete; }); }); }); }); }
public static SetCustomerId of(@Nullable final String customerId) { return new SetCustomerId(customerId); }
public static void withCartHavingDiscountedCustomLineItem(final BlockingSphereClient client, final RelativeCartDiscountValue relativeCartDiscountValue, final UnaryOperator<Cart> op) { withTaxedProduct(client, product -> { withCustomer(client, (customer) -> { CartDiscountFixtures.withCartDiscount(client, builder -> builder .cartPredicate(CartPredicate.of("customer.id=\"" + customer.getId() + "\"")) .value(relativeCartDiscountValue) .target(CustomLineItemsTarget.of("slug =\"thing-discounted-slug\"")), cartDiscount -> { withCart(client, (cart) -> { assertThat(cart.getCustomLineItems()).hasSize(0); final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-discounted-slug"; final LocalizedString name = en("thing"); final CustomLineItemDraft item = CustomLineItemDraft.of(name, slug, money, product.getTaxCategory(), 5L, null); final AddCustomLineItem addCustomLineItemAction = AddCustomLineItem.of(item); final List<UpdateAction<Cart>> updateActions = asList(addCustomLineItemAction, SetCustomerId.of(customer.getId()), Recalculate.of().withUpdateProductData(true)); final Cart updatedCart = client.executeBlocking(CartUpdateCommand.of(cart, updateActions)); final Cart cartToDelete = op.apply(updatedCart); return cartToDelete; }); }); }); }); }