public static AddCustomLineItem of(final LocalizedString name, final String slug, final MonetaryAmount money, final Referenceable<TaxCategory> taxCategory, final long quantity) { return of(name, slug, money, taxCategory, quantity, null); }
public static AddCustomLineItem of(final LocalizedString name, final String slug, final MonetaryAmount money, final Referenceable<TaxCategory> taxCategory, final long quantity) { return of(name, slug, money, taxCategory, quantity, null); }
public static AddCustomLineItem of(final LocalizedString name, final String slug, final MonetaryAmount money, final Referenceable<TaxCategory> taxCategory, final long quantity) { return of(name, slug, money, taxCategory, quantity, null); }
public static AddCustomLineItem of(final CustomLineItemDraft draft) { return of(draft.getName(), draft.getSlug(), draft.getMoney(), draft.getTaxCategory(), draft.getQuantity()); }
public static AddCustomLineItem of(final CustomLineItemDraft draft) { return of(draft.getName(), draft.getSlug(), draft.getMoney(), draft.getTaxCategory(), draft.getQuantity()); }
public static AddCustomLineItem of(final CustomLineItemDraft draft) { return of(draft.getName(), draft.getSlug(), draft.getMoney(), draft.getTaxCategory(), draft.getQuantity(), draft.getCustom()); }
@Test public void changeCustomLineItemQuantity() throws Exception { withTaxCategory(client(), taxCategory -> { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomLineItems()).hasSize(0); final CustomLineItemDraft draftItem = createCustomLineItemDraft(taxCategory); final Cart cartWithCustomLineItem = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(draftItem))); assertThat(cartWithCustomLineItem.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWithCustomLineItem.getCustomLineItems().get(0); assertThat(customLineItem.getQuantity()).isEqualTo(5L); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cartWithCustomLineItem, ChangeCustomLineItemQuantity.of(customLineItem, 12L))); assertThat(updatedCart.getCustomLineItems().get(0).getQuantity()).isEqualTo(12L); }); }
@Test public void removeCustomLineItem() throws Exception { withTaxCategory(client(), taxCategory -> { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomLineItems()).hasSize(0); final CustomLineItemDraft draftItem = createCustomLineItemDraft(taxCategory); final Cart cartWithCustomLineItem = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(draftItem))); assertThat(cartWithCustomLineItem.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWithCustomLineItem.getCustomLineItems().get(0); final Cart emptyCart = client().executeBlocking(CartUpdateCommand.of(cartWithCustomLineItem, RemoveCustomLineItem.of(customLineItem))); assertThat(emptyCart.getCustomLineItems()).hasSize(0); }); }
@Test public void changeCustomLineItemMoney() throws Exception { withTaxCategory(client(), taxCategory -> { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomLineItems()).hasSize(0); final CustomLineItemDraft draftItem = createCustomLineItemDraft(taxCategory);//money=MoneyImpl.ofCents(2350, EUR) final Cart cartWithCustomLineItem = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(draftItem))); assertThat(cartWithCustomLineItem.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWithCustomLineItem.getCustomLineItems().get(0); assertThat(customLineItem.getMoney()).isEqualTo(MoneyImpl.ofCents(2350, EUR)); final MonetaryAmount newAmount = MoneyImpl.ofCents(1234, EUR); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cartWithCustomLineItem, ChangeCustomLineItemMoney.of(customLineItem, newAmount))); assertThat(updatedCart.getCustomLineItems().get(0).getMoney()).isEqualTo(newAmount); }); }
public static void withLineItemAndCustomLineItemFilledCart(final BlockingSphereClient client, final UnaryOperator<Cart> op) { withTaxedProduct(client, product -> { final Cart cart = createCartWithShippingAddress(client); assertThat(cart.getLineItems()).hasSize(0); final long quantity = 3; final String productId = product.getId(); final AddLineItem addLineItemAction = AddLineItem.of(productId, 1, quantity); assertThat(cart.getCustomLineItems()).hasSize(0); final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-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 Cart updatedCart = client.executeBlocking(CartUpdateCommand.of(cart, asList(addLineItemAction, addCustomLineItemAction))); assertThat(updatedCart.getLineItems()).hasSize(1); final LineItem lineItem = updatedCart.getLineItems().get(0); assertThat(lineItem.getName()).isEqualTo(product.getMasterData().getStaged().getName()); assertThat(lineItem.getQuantity()).isEqualTo(quantity); final Cart cartToDelete = op.apply(updatedCart); client.executeBlocking(CartDeleteCommand.of(cartToDelete)); }); }
@Ignore @Test public void addMergesSameCustomLineItems() throws Exception { withTaxCategory(client(), taxCategory -> { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomLineItems()).isEmpty(); final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-slug";//you handle to identify the custom line item final LocalizedString name = en("thing"); final long quantity = 5; final CustomLineItemDraft item = CustomLineItemDraft.of(name, slug, money, taxCategory, quantity, null); final Cart cartWith5 = client().executeBlocking(CartUpdateCommand.of(cart, Arrays.asList(AddCustomLineItem.of(item), AddCustomLineItem.of(item)))); assertThat(cartWith5.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWith5.getCustomLineItems().get(0); assertThat(customLineItem.getMoney()).isEqualTo(money); assertThat(customLineItem.getName()).isEqualTo(name); assertThat(customLineItem.getQuantity()).isEqualTo(quantity * 2); assertThat(customLineItem.getSlug()).isEqualTo(slug); final Set<ItemState> state = customLineItem.getState(); assertThat(state).hasSize(1); assertThat(state).extracting("quantity").containsOnly(quantity * 2); assertThat(customLineItem.getTaxCategory()).isEqualTo(taxCategory.toReference()); final CartQuery cartQuery = CartQuery.of() .withPredicates(m -> m.customLineItems().slug().is(customLineItem.getSlug()) .and(m.id().is(cart.getId()))); assertThat(client().executeBlocking(cartQuery).head().get().getId()).isEqualTo(cart.getId()); }); }
@Test public void addCustomLineItem() throws Exception { withTaxCategory(client(), taxCategory -> { final Cart cart = createCartWithCountry(client()); assertThat(cart.getCustomLineItems()).isEmpty(); final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-slug";//you handle to identify the custom line item final LocalizedString name = en("thing"); final long quantity = 5; final CustomLineItemDraft item = CustomLineItemDraft.of(name, slug, money, taxCategory, quantity, null); final Cart cartWith5 = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(item))); assertThat(cartWith5.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWith5.getCustomLineItems().get(0); assertThat(customLineItem.getMoney()).isEqualTo(money); assertThat(customLineItem.getName()).isEqualTo(name); assertThat(customLineItem.getQuantity()).isEqualTo(quantity); assertThat(customLineItem.getSlug()).isEqualTo(slug); final Set<ItemState> state = customLineItem.getState(); assertThat(state).hasSize(1); assertThat(state).extracting("quantity").containsOnly(quantity); assertThat(customLineItem.getTaxCategory()).isEqualTo(taxCategory.toReference()); final CartQuery cartQuery = CartQuery.of() .withPredicates(m -> m.customLineItems().slug().is(customLineItem.getSlug()) .and(m.id().is(cart.getId()))); assertThat(client().executeBlocking(cartQuery).head().get().getId()).isEqualTo(cart.getId()); }); }
public static void withOrderOfCustomLineItems(final BlockingSphereClient client, final Consumer<Order> f) { withTaxCategory(client, taxCategory -> { final Cart cart = createCartWithShippingAddress(client); final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-slug"; final LocalizedString name = en("thing"); final long quantity = 5; final CustomLineItemDraft item = CustomLineItemDraft.of(name, slug, money, taxCategory, quantity, null); final Cart cartWith5 = client.executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(item))); final Order order = client.executeBlocking(OrderFromCartCreateCommand.of(cartWith5)); f.accept(order); }); }
@Test public void addCustomLineItem() { final CartDraft draft = CartDraft.of(EUR) .withTaxMode(TaxMode.EXTERNAL) .withShippingAddress(Address.of(DE)); withCartDraft(client(), draft, (Cart cart) -> { final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-slug"; final LocalizedString name = en("thing"); final long quantity = 5; final String taxRateName = "special tax"; final double taxRate = 0.20; final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).build(); final CustomLineItemDraft item = CustomLineItemDraft.ofExternalTaxCalculation(name, slug, money, externalTaxRate, quantity); final Cart cartWithCustomLineItems = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(item))); assertThat(cartWithCustomLineItems.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWithCustomLineItems.getCustomLineItems().get(0); assertThat(customLineItem.getTaxCategory()).isNull(); assertThat(customLineItem.getTaxedPrice().getTotalNet()).isEqualTo(MoneyImpl.of("117.50", EUR)); assertThat(customLineItem.getTaxedPrice().getTotalGross()).isEqualTo(MoneyImpl.of("141.00", EUR)); assertThat(customLineItem.getTaxRate().getName()).isEqualTo(taxRateName); return cartWithCustomLineItems; }); }
final CustomLineItemDraft item = CustomLineItemDraft.ofExternalTaxCalculation(name, slug, money, quantity); final Cart cartWithCustomLineItem = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(item))); assertThat(cartWithCustomLineItem.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWithCustomLineItem.getCustomLineItems().get(0);
@Test public void creation() { withUpdateableType(client(), type -> { withCartAndTaxedProduct(client(), (cart, product) -> { final CustomFieldsDraft customFieldsDraft = CustomFieldsDraftBuilder .ofType(type) .addObject(STRING_FIELD_NAME, "a value") .build(); final AddCustomLineItem updateAction = AddCustomLineItem.of(en("custom line item"), "foo", EURO_30, product.getTaxCategory(), 3L).withCustom(customFieldsDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, updateAction)); final CustomFields customFields = updatedCart.getCustomLineItems().get(0).getCustom(); assertThat(customFields.getFieldAsString(STRING_FIELD_NAME)).isEqualTo("a value"); return updatedCart; }); return type; }); }
public static void withCustomLineItemFilledCartWithTaxMode(final BlockingSphereClient client, final TaxMode taxMode, final UnaryOperator<Cart> op) { withTaxedProduct(client, product -> { final Cart cart = client.executeBlocking(CartUpdateCommand.of(createCartWithShippingAddress(client), ChangeTaxMode.of(taxMode))); final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-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 Cart updatedCart = client.executeBlocking(CartUpdateCommand.of(cart, asList(addCustomLineItemAction))); final Cart cartToDelete = op.apply(updatedCart); client.executeBlocking(CartDeleteCommand.of(cartToDelete)); }); }
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; }); }); }); }); }