public final class SetLineItemTaxRate extends UpdateActionImpl<Cart>
AddLineItem
.
See also CartInStoreUpdateCommand.
withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_10)), (Product product) -> {
final CartDraft draft = CartDraft.of(EUR).withTaxMode(TaxMode.EXTERNAL);
withCartDraft(client(), draft, (Cart cart) -> {
final int quantity = 3;
final int variantId = product.getMasterData().getStaged().getMasterVariant().getId();
final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity);
final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction));
final LineItem lineItem = cartWithLineItem.getLineItems().get(0);
assertThat(lineItem.getTaxRate()).isNull();
assertThat(lineItem.getTotalPrice()).isEqualTo(EURO_30);
assertThat(lineItem.getTaxedPrice()).isNull();
//now add the taxes
final String taxRateName = "special tax";
final double taxRate = 0.20;
final ExternalTaxRateDraft externalTaxRate =
ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).includedInPrice(false).build();
final SetLineItemTaxRate setLineItemTaxRate = SetLineItemTaxRate.of(lineItem.getId(), externalTaxRate);
final Cart cartWithTaxedLineItem =
client().executeBlocking(CartUpdateCommand.of(cartWithLineItem, setLineItemTaxRate));
final LineItem taxedLineItem = cartWithTaxedLineItem.getLineItems().get(0);
assertThat(taxedLineItem.getTaxRate().getName()).isEqualTo(taxRateName);
assertThat(taxedLineItem.getTaxRate().isIncludedInPrice()).isEqualTo(false);
assertThat(taxedLineItem.getTotalPrice()).isEqualTo(EURO_30);
assertThat(taxedLineItem.getTaxedPrice().getTotalGross()).isEqualTo(EURO_36);
assertThat(taxedLineItem.getTaxedPrice().getTotalNet()).isEqualTo(EURO_30);
return cartWithTaxedLineItem;
});
});
See the test code.
Modifier and Type | Method and Description |
---|---|
ExternalTaxRateDraft |
getExternalTaxRate() |
String |
getLineItemId() |
static SetLineItemTaxRate |
of(String lineItemId,
ExternalTaxRateDraft externalTaxRate) |
getAction
public static SetLineItemTaxRate of(String lineItemId, @Nullable ExternalTaxRateDraft externalTaxRate)
@Nullable public ExternalTaxRateDraft getExternalTaxRate()
public String getLineItemId()