public final class ChangeLineItemQuantity extends UpdateActionImpl<Cart>
ChangeLineItemQuantity
does not support changing the shipping details
like RemoveLineItem
and AddLineItem
because in the case of not sending the shippingDetails
field
it would not be clear if the shipping details should be removed at all (possible data loss) or remain unchanged.
Use SetLineItemShippingDetails
in combination with this update action in one
cart update command to change the line item quantity and shipping details altogether.
See also CartInStoreUpdateCommand.
withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).hasSize(0); final AddLineItem action = AddLineItem.of(product.getId(), MASTER_VARIANT_ID, 3L); final Cart cartWith3 = client().executeBlocking(CartUpdateCommand.of(cart, action)); final LineItem lineItem = cartWith3.getLineItems().get(0); assertThat(lineItem.getQuantity()).isEqualTo(3); final Cart cartWith2 = client().executeBlocking(CartUpdateCommand.of(cartWith3, ChangeLineItemQuantity.of(lineItem, 2L))); assertThat(cartWith2.getLineItems().get(0).getQuantity()).isEqualTo(2); final Cart cartWith0 = client().executeBlocking(CartUpdateCommand.of(cartWith2, ChangeLineItemQuantity.of(lineItem, 0L))); assertThat(cartWith0.getLineItems()).hasSize(0); });
See the test code.
Modifier and Type | Method and Description |
---|---|
javax.money.MonetaryAmount |
getExternalPrice() |
ExternalLineItemTotalPrice |
getExternalTotalPrice() |
String |
getLineItemId() |
long |
getQuantity() |
static UpdateAction<Cart> |
of(LineItem lineItem,
long quantity) |
static ChangeLineItemQuantity |
of(String lineItemId,
long quantity) |
static ChangeLineItemQuantity |
ofLineItemAndExternalPrice(LineItem lineItem,
long quantity,
javax.money.MonetaryAmount externalPrice) |
static ChangeLineItemQuantity |
ofLineItemAndExternalPrice(String lineItemId,
long quantity,
javax.money.MonetaryAmount externalPrice) |
static ChangeLineItemQuantity |
ofLineItemAndExternalTotalPrice(LineItem lineItem,
long quantity,
ExternalLineItemTotalPrice externalTotalPrice) |
static ChangeLineItemQuantity |
ofLineItemAndExternalTotalPrice(String lineItemId,
long quantity,
ExternalLineItemTotalPrice externalTotalPrice) |
getAction
public static UpdateAction<Cart> of(LineItem lineItem, long quantity)
public static ChangeLineItemQuantity of(String lineItemId, long quantity)
public static ChangeLineItemQuantity ofLineItemAndExternalPrice(LineItem lineItem, long quantity, @Nullable javax.money.MonetaryAmount externalPrice)
public static ChangeLineItemQuantity ofLineItemAndExternalPrice(String lineItemId, long quantity, @Nullable javax.money.MonetaryAmount externalPrice)
public static ChangeLineItemQuantity ofLineItemAndExternalTotalPrice(LineItem lineItem, long quantity, @Nullable ExternalLineItemTotalPrice externalTotalPrice)
public static ChangeLineItemQuantity ofLineItemAndExternalTotalPrice(String lineItemId, long quantity, @Nullable ExternalLineItemTotalPrice externalTotalPrice)
public String getLineItemId()
public long getQuantity()
@Nullable public javax.money.MonetaryAmount getExternalPrice()
@Nullable public ExternalLineItemTotalPrice getExternalTotalPrice()