public interface CustomLineItem extends LineItemLike
A custom line item is a generic item that can be added to the cart but is not bound to a product. You can use it for discounts (negative money), vouchers, complex cart rules, additional services or fees. You control the lifecycle of this item.
A CustomLineItem can have custom fields
.
Example for adding a CustomLineItem
to a Cart
:
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()); });
See the test code.
CustomLineItemDraftImpl
,
AddCustomLineItem
,
RemoveCustomLineItem
,
Order.getCustomLineItems()
,
Cart.getCustomLineItems()
Modifier and Type | Method and Description |
---|---|
CustomFields |
getCustom() |
List<DiscountedLineItemPriceForQuantity> |
getDiscountedPricePerQuantity()
Gets discount information for groups of line items.
|
String |
getId() |
javax.money.MonetaryAmount |
getMoney()
The positive or negative monetary amount of this custom line item.
|
LocalizedString |
getName() |
Long |
getQuantity()
The item count of this custom line item.
|
ItemShippingDetails |
getShippingDetails()
Container for the sub-quantity of the line item quantity for the specific address when multiple shipping addresses are required
|
String |
getSlug() |
Set<ItemState> |
getState() |
Reference<TaxCategory> |
getTaxCategory() |
TaxedItemPrice |
getTaxedPrice() |
TaxRate |
getTaxRate() |
javax.money.MonetaryAmount |
getTotalPrice() |
static String |
resourceTypeId()
An identifier for this resource which supports
CustomFields . |
LocalizedString getName()
javax.money.MonetaryAmount getMoney()
ChangeCustomLineItemMoney
String getSlug()
Set<ItemState> getState()
getState
in interface LineItemLike
@Nullable Reference<TaxCategory> getTaxCategory()
String getId()
getId
in interface LineItemLike
Long getQuantity()
getQuantity
in interface LineItemLike
ChangeCustomLineItemQuantity
CustomFields getCustom()
javax.money.MonetaryAmount getTotalPrice()
getTotalPrice
in interface LineItemLike
List<DiscountedLineItemPriceForQuantity> getDiscountedPricePerQuantity()
LineItemLike
getDiscountedPricePerQuantity
in interface LineItemLike
@Nullable TaxedItemPrice getTaxedPrice()
getTaxedPrice
in interface LineItemLike
@Nullable ItemShippingDetails getShippingDetails()
static String resourceTypeId()
CustomFields
.TypeDraft.getResourceTypeIds()
,
Custom