public final class AddLineItem extends UpdateActionImpl<Cart> implements CustomDraft
See also CartInStoreUpdateCommand.
withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final long quantity = 3; final String productId = product.getId(); final AddLineItem action = AddLineItem.of(productId, MASTER_VARIANT_ID, quantity); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, action)); 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); assertThat(lineItem.getProductSlug()).isEqualTo(product.getMasterData().getStaged().getSlug()); assertThat(lineItem.getVariant().getIdentifier()).isEqualTo(ByIdVariantIdentifier.of(lineItem.getProductId(), lineItem.getVariant().getId())); assertThat(lineItem.getDiscountedPricePerQuantity()).isNotNull().isEmpty(); assertThat(lineItem.getLastModifiedAt()).isNotNull(); });
See the test code.
getAction
public static AddLineItem of(ProductIdentifiable product, int variantId, long quantity)
public static AddLineItem of(String productId, int variantId, long quantity)
public static AddLineItem of(LineItemDraft template)
public String getProductId()
public Integer getVariantId()
public Long getQuantity()
@Nullable public ResourceIdentifier<Channel> getDistributionChannel()
@Nullable public ResourceIdentifier<Channel> getSupplyChannel()
@Nullable public CustomFieldsDraft getCustom()
getCustom
in interface CustomDraft
@Nullable public ExternalTaxRateDraft getExternalTaxRate()
@Nullable public javax.money.MonetaryAmount getExternalPrice()
@Nullable public ExternalLineItemTotalPrice getExternalTotalPrice()
@Nullable public ItemShippingDetailsDraft getShippingDetails()
@Nullable public ZonedDateTime getAddedAt()
public AddLineItem withSupplyChannel(Referenceable<Channel> supplyChannel)
public AddLineItem withDistributionChannel(Referenceable<Channel> distributionChannel)
public AddLineItem withCustom(CustomFieldsDraft custom)
public AddLineItem withExternalTaxRate(@Nullable ExternalTaxRateDraft externalTaxRate)
public AddLineItem withExternalPrice(@Nullable javax.money.MonetaryAmount externalPrice)
public AddLineItem withExternalTotalPrice(@Nullable ExternalLineItemTotalPrice externalTotalPrice)