public interface CustomLineItemDraft extends CustomDraft
Draft for adding a custom line item to the cart.
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.
CustomLineItem
Modifier and Type | Method and Description |
---|---|
CustomFieldsDraft |
getCustom() |
ExternalTaxRateDraft |
getExternalTaxRate()
Possible custom tax rate.
|
javax.money.MonetaryAmount |
getMoney() |
LocalizedString |
getName() |
Long |
getQuantity() |
ItemShippingDetailsDraft |
getShippingDetails()
Container for the sub-quantity of the line item quantity for the specific address when multiple shipping addresses are required.
|
String |
getSlug() |
ResourceIdentifier<TaxCategory> |
getTaxCategory()
Gets the tax category for this custom line item.
|
static CustomLineItemDraft |
of(LocalizedString name,
String slug,
javax.money.MonetaryAmount money,
Referenceable<TaxCategory> taxCategory,
long quantity)
Creates a draft having a standard tax category and no custom fields.
|
static CustomLineItemDraft |
of(LocalizedString name,
String slug,
javax.money.MonetaryAmount money,
Referenceable<TaxCategory> taxCategory,
long quantity,
CustomFieldsDraft custom)
Creates a draft having a standard tax category and custom fields.
|
static CustomLineItemDraft |
ofExternalTaxCalculation(LocalizedString name,
String slug,
javax.money.MonetaryAmount money,
ExternalTaxRateDraft externalTaxRate,
long quantity)
Creates a draft having an external tax rate and no custom fields.
|
static CustomLineItemDraft |
ofExternalTaxCalculation(LocalizedString name,
String slug,
javax.money.MonetaryAmount money,
ExternalTaxRateDraft externalTaxRate,
long quantity,
CustomFieldsDraft custom)
Creates a draft having an external tax rate and custom fields.
|
static CustomLineItemDraft |
ofExternalTaxCalculation(LocalizedString name,
String slug,
javax.money.MonetaryAmount money,
long quantity)
Creates a draft having no tax rate (for external tax calculation) and no custom fields.
|
static CustomLineItemDraft |
ofExternalTaxCalculation(LocalizedString name,
String slug,
javax.money.MonetaryAmount money,
long quantity,
CustomFieldsDraft custom)
Creates a draft having no tax rate (for external tax calculation) and custom fields.
|
LocalizedString getName()
javax.money.MonetaryAmount getMoney()
String getSlug()
@Nullable ResourceIdentifier<TaxCategory> getTaxCategory()
TaxMode
@Nullable ExternalTaxRateDraft getExternalTaxRate()
getTaxCategory()
,
TaxMode
Long getQuantity()
@Nullable CustomFieldsDraft getCustom()
getCustom
in interface CustomDraft
ItemShippingDetailsDraft getShippingDetails()
static CustomLineItemDraft of(LocalizedString name, String slug, javax.money.MonetaryAmount money, Referenceable<TaxCategory> taxCategory, long quantity)
name
- the display name of the custom line item (corresponds to a product name)slug
- unique field in the cart which is intended to identify the custom line item (not translated)money
- the amount of the custom line itemtaxCategory
- the tax category of the custom line itemquantity
- the count of items of this line item in the cartstatic CustomLineItemDraft of(LocalizedString name, String slug, javax.money.MonetaryAmount money, Referenceable<TaxCategory> taxCategory, long quantity, @Nullable CustomFieldsDraft custom)
name
- the display name of the custom line item (corresponds to a product name)slug
- unique field in the cart which is intended to identify the custom line item (not translated)money
- the amount of the custom line itemtaxCategory
- the tax category of the custom line itemquantity
- the count of items of this line item in the cartcustom
- custom fields for the custom line itemstatic CustomLineItemDraft ofExternalTaxCalculation(LocalizedString name, String slug, javax.money.MonetaryAmount money, ExternalTaxRateDraft externalTaxRate, long quantity)
name
- the display name of the custom line item (corresponds to a product name)slug
- unique field in the cart which is intended to identify the custom line item (not translated)money
- the amount of the custom line itemexternalTaxRate
- tax rate specific for this line item if the standard tax rates do not sufficequantity
- the count of items of this line item in the cartstatic CustomLineItemDraft ofExternalTaxCalculation(LocalizedString name, String slug, javax.money.MonetaryAmount money, long quantity)
name
- the display name of the custom line item (corresponds to a product name)slug
- unique field in the cart which is intended to identify the custom line item (not translated)money
- the amount of the custom line itemquantity
- the count of items of this line item in the cartstatic CustomLineItemDraft ofExternalTaxCalculation(LocalizedString name, String slug, javax.money.MonetaryAmount money, ExternalTaxRateDraft externalTaxRate, long quantity, @Nullable CustomFieldsDraft custom)
name
- the display name of the custom line item (corresponds to a product name)slug
- unique field in the cart which is intended to identify the custom line item (not translated)money
- the amount of the custom line itemexternalTaxRate
- tax rate specific for this line item if the standard tax rates do not sufficequantity
- the count of items of this line item in the cartcustom
- custom fields for the custom line itemstatic CustomLineItemDraft ofExternalTaxCalculation(LocalizedString name, String slug, javax.money.MonetaryAmount money, long quantity, @Nullable CustomFieldsDraft custom)
name
- the display name of the custom line item (corresponds to a product name)slug
- unique field in the cart which is intended to identify the custom line item (not translated)money
- the amount of the custom line itemquantity
- the count of items of this line item in the cartcustom
- custom fields for the custom line itemSetCustomLineItemTaxRate
,
CustomLineItemDraft