Fluent builder for adding a product SKU to a cart, or updating the existing line item for that SKU. Configure the quantity, an optional fixed or percentage discount, and any order option fields, then call addOrUpdate to apply the change. Obtained from CartManager.cartItemBuilder.
Group: Builders
Methods
increment(boolean b) · quantity(BigDecimal b) · quantity(long b) · quantity(double b) · discount(BigDecimal b) · discount(double b) · discountRate(BigDecimal b) · discountRate(double b) · sku(ProductSku sku) · sku(String sku) · orderFields(Map orderFields) · addOrUpdate()
increment(boolean b)
Returns: CartItemBuilder
Sets whether adding this item should increment the quantity of an existing matching line item rather than replacing it.
| Parameter | Description |
|---|---|
b | true to add to the existing quantity, false to replace it |
quantity(BigDecimal b)
Returns: CartItemBuilder
Sets the quantity of the item to add or update. Defaults to one if never set.
| Parameter | Description |
|---|---|
b | the quantity to set |
quantity(long b)
Returns: CartItemBuilder
Sets the quantity of the item to add or update. Defaults to one if never set.
| Parameter | Description |
|---|---|
b | the quantity to set |
quantity(double b)
Returns: CartItemBuilder
Sets the quantity of the item to add or update. Defaults to one if never set.
| Parameter | Description |
|---|---|
b | the quantity to set |
discount(BigDecimal b)
Returns: CartItemBuilder
Sets a fixed discount amount to apply to the line item. Must be negative, eg -10 to reduce the grand total by 10. Cannot be combined with discountRate.
| Parameter | Description |
|---|---|
b | the discount amount, which must be negative or zero |
discount(double b)
Returns: CartItemBuilder
Sets a fixed discount amount to apply to the line item. Must be negative, eg -10 to reduce the grand total by 10. Cannot be combined with discountRate.
| Parameter | Description |
|---|---|
b | the discount amount, which must be negative or zero |
discountRate(BigDecimal b)
Returns: CartItemBuilder
Sets a discount rate to apply to the line item, as a proportion of the SKU's base cost times the quantity. Must be negative. Cannot be combined with discount.
| Parameter | Description |
|---|---|
b | the discount rate, which must be negative or zero |
discountRate(double b)
Returns: CartItemBuilder
Sets a discount rate to apply to the line item, as a proportion of the SKU's base cost times the quantity. Must be negative. Cannot be combined with discount.
| Parameter | Description |
|---|---|
b | the discount rate, which must be negative or zero |
sku(ProductSku sku)
Returns: CartItemBuilder
Sets the product SKU to add or update in the cart. Required before calling addOrUpdate.
| Parameter | Description |
|---|---|
sku | the SKU to add or update |
sku(String sku)
Returns: CartItemBuilder
Looks up the product SKU by its name and sets it as the SKU to add or update in the cart. Required before calling addOrUpdate.
| Parameter | Description |
|---|---|
sku | the name of the SKU to look up and add or update |
orderFields(Map orderFields)
Returns: CartItemBuilder
Sets custom order option fields to record against the line item, such as answers to product questions.
| Parameter | Description |
|---|---|
orderFields | a map of option name to value to save on the line item |
addOrUpdate()
Returns: ProductOrder
Applies the configured item to the cart: adds a new line item for the SKU, or updates the quantity of an existing matching line item, then applies any configured discount and order fields. Fires a ShoppingCartEvent for the added-to-cart action. Throws if the cart has already been submitted, if the item is from a different store to one already in the cart, if no SKU was set, or if both a discount and a discount rate were set.