public AddLineItem withExternalPrice(@Nullable final MonetaryAmount externalPrice) { return new AddLineItem(getProductId(), getVariantId(), getSku(), getQuantity(), getSupplyChannel(), getDistributionChannel(), getCustom(), getExternalTaxRate(), externalPrice, getExternalTotalPrice()); }
public static AddLineItem of(final ProductIdentifiable product, final int variantId, final long quantity) { return of(product.getId(), variantId, quantity); }
public AddLineItem withCustom(final CustomFieldsDraft custom) { return new AddLineItem(getProductId(), getVariantId(), getQuantity(), getSupplyChannel(), getDistributionChannel(), custom); } }
public AddLineItem withSupplyChannel(final Referenceable<Channel> supplyChannel) { return new AddLineItem(getProductId(), getVariantId(), getQuantity(), supplyChannel.toReference(), getDistributionChannel(), getCustom()); }
public AddLineItem withDistributionChannel(final Referenceable<Channel> distributionChannel) { return new AddLineItem(getProductId(), getVariantId(), getQuantity(), getSupplyChannel(), distributionChannel.toReference(), getCustom()); }
public static AddLineItem of(final String productId, final int variantId, final int quantity) { return new AddLineItem(productId, variantId, quantity); }
.subRates(subRates) .build(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity) .withExternalTaxRate(externalTaxRate); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction));
@Test public void addLineItemWithExternalPrice() { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final int quantity = 5; final int variantId = 1; final String productId = product.getId(); final MonetaryAmount externalPrice = EURO_30; final AddLineItem updateAction = AddLineItem.of(productId, variantId, quantity) .withExternalPrice(externalPrice); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction)); final LineItem lineItem = cartWithLineItem.getLineItems().get(0); assertThat(lineItem.getPrice().getValue()).isEqualTo(externalPrice); assertThat(lineItem.getPriceMode()).isEqualTo(EXTERNAL_PRICE); }); }
@Test public void addLineItemWithExternalTotalPrice() { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final int quantity = 5; final int variantId = 1; final String productId = product.getId(); final MonetaryAmount price = EURO_20; final MonetaryAmount totalPrice = EURO_25; final ExternalLineItemTotalPrice externalLineItemTotalPrice = ExternalLineItemTotalPrice.ofPriceAndTotalPrice(price, totalPrice); final AddLineItem updateAction = AddLineItem.of(productId, variantId, quantity) .withExternalTotalPrice(externalLineItemTotalPrice); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction)); final LineItem lineItem = cartWithLineItem.getLineItems().get(0); assertThat(lineItem.getPrice().getValue()).isEqualTo(price); assertThat(lineItem.getTotalPrice()).isEqualTo(totalPrice); assertThat(lineItem.getPriceMode()).isEqualTo(EXTERNAL_TOTAL); }); }
final long quantity = 3; final String productId = product.getId(); final AddLineItem action = AddLineItem.of(productId, MASTER_VARIANT_ID, quantity) .withSupplyChannel(inventorySupplyChannel) .withDistributionChannel(distributionChannel);
@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 Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, AddLineItem.of(product, 1, 1L).withCustom(customFieldsDraft))); assertThat(updatedCart.getLineItems().get(0).getCustom().getField(STRING_FIELD_NAME, TypeReferences.stringTypeReference())).isEqualTo("a value"); return updatedCart; }); return type; }); }
public static AddLineItem of(final String productId, final int variantId, final long quantity) { return new AddLineItem(productId, variantId, quantity, null, null, null); }
@Test public void addLineItemOnPlatformCart() { withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_10)), (Product product) -> { final CartDraft draft = CartDraft.of(EUR);//uses by default platform! withCartDraft(client(), draft, (Cart cart) -> { final int quantity = 3; final int variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final String taxRateName = "special tax"; final double taxRate = 0.20; final List<SubRate> subRates = asList(SubRate.of("foo", 0.11), SubRate.of("bar", 0.09)); final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE) .subRates(subRates) .build(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity) .withExternalTaxRate(externalTaxRate); final Throwable throwable = catchThrowable(() -> client().executeBlocking(CartUpdateCommand.of(cart, updateAction))); //the error message is sth. like "Cannot set an external tax rate on a cart with taxMode 'Platform'." assertThat(throwable).isInstanceOf(ErrorResponseException.class); return cart; }); }); }
@Test public void setLineItemPriceWithoutExternalPrice() { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).hasSize(0); final MonetaryAmount externalPrice = EURO_20; final AddLineItem action = AddLineItem.of(product.getId(), MASTER_VARIANT_ID, 3L).withExternalPrice(externalPrice); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, action)); final LineItem lineItem = cartWithLineItem.getLineItems().get(0); assertThat(lineItem.getQuantity()).isEqualTo(3); assertThat(lineItem.getPriceMode()).isEqualTo(EXTERNAL_PRICE); assertThat(lineItem.getPrice().getValue()).isEqualTo(externalPrice); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cartWithLineItem, SetLineItemPrice.of(lineItem.getId()))); final LineItem updatedLineItem = updatedCart.getLineItems().get(0); assertThat(updatedLineItem.getPriceMode()).isEqualTo(PLATFORM); assertThat(updatedLineItem.getPrice().getValue()).isEqualTo(MoneyImpl.ofCents(1234, EUR)); }); }
@Test public void changeLineItemQuantityWithoutExternalTotalPrice() throws Exception { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).hasSize(0); final MonetaryAmount price = EURO_1; final MonetaryAmount totalPrice = EURO_5; final ExternalLineItemTotalPrice externalTotalPrice = ExternalLineItemTotalPrice.ofPriceAndTotalPrice(price, totalPrice); final AddLineItem action = AddLineItem.of(product.getId(), MASTER_VARIANT_ID, 3L).withExternalTotalPrice(externalTotalPrice); final Cart cartWith3 = client().executeBlocking(CartUpdateCommand.of(cart, action)); final LineItem lineItem = cartWith3.getLineItems().get(0); assertThat(lineItem.getQuantity()).isEqualTo(3); assertThat(lineItem.getPriceMode()).isEqualTo(EXTERNAL_TOTAL); assertThat(lineItem.getTotalPrice()).isEqualTo(totalPrice); assertThat(lineItem.getPrice().getValue()).isEqualTo(price); final Cart cartWith2 = client().executeBlocking(CartUpdateCommand.of(cartWith3, ChangeLineItemQuantity.of(lineItem, 2L))); final LineItem updatedLineItem = cartWith2.getLineItems().get(0); assertThat(updatedLineItem.getQuantity()).isEqualTo(2); assertThat(updatedLineItem.getPriceMode()).isEqualTo(PLATFORM); assertThat(updatedLineItem.getPrice().getValue()).isEqualTo(MoneyImpl.ofCents(1234, EUR)); }); }
public AddLineItem withExternalTotalPrice(@Nullable final ExternalLineItemTotalPrice externalTotalPrice) { return new AddLineItem(getProductId(), getVariantId(), getSku(), getQuantity(), getSupplyChannel(), getDistributionChannel(), getCustom(), getExternalTaxRate(), getExternalPrice(), externalTotalPrice); } }
public static AddLineItem of(final ProductIdentifiable product, final int variantId, final long quantity) { return of(product.getId(), variantId, quantity); }
public static AddLineItem of(final String productId, final int variantId, final long quantity) { return new AddLineItem(productId, variantId, quantity); }
.subRates(subRates) .build(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity) .withExternalTaxRate(externalTaxRate); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction));
public AddLineItem withCustom(final CustomFieldsDraft custom) { return new AddLineItem(getProductId(), getVariantId(), getSku(), getQuantity(), getSupplyChannel(), getDistributionChannel(), custom, getExternalTaxRate(), getExternalPrice(), getExternalTotalPrice()); }