This workflow is as follows:
Initialize PriceCartRequest
Refresh Catalog-based pricing for the cart items if requested on the PriceCartRequest
Clear current pricing information from the cart
Clears all totals on the cart
Resets the currency and locale
Clears all totals on FulfillmentGroups
including CSR price overrides
Clears all totals on CartItems
including CSR price overrides
Clears all adjustments applied to the cart
Price cart items via PricingProvider
Calculate each item’s subtotal
Record whether each item was priced
If the item was not priced, a ConfigError
is added to its globalConfigErrors
with failure type PRICE_UNAVAILABLE
and a localized message, cartItem.validationError.noPriceFoundForItem
,
Then the cart item is wrapped in a CartItemValidationException
Which is then thrown, to be handled by the the original caller (e.g., the frontend client)
Apply order and order item adjustments (a.k.a., offers or discounts) via OfferProvider
This is done before fulfillment pricing since fulfillment pricing can be dependent on merchandise pricing, particularly whether discounts can be applied like "free shipping on orders of $50 or more"
Calculate and store bundle cart item prorated prices
Calculate fulfillment pricing
Apply fulfillment and fulfillment item adjustments via OfferProvider
The OfferProvider
takes an argument determining whether order and order item adjustments should be calculated, allowing this second call to isolate fulfillment adjustment calculations
Mark the cart as priced
Persist if requested
CartOperationServiceProperties
defines broadleaf.cartoperation.service.calculateProratedFulfillmentPricing
.
This property determines whether order-level adjustments (a.k.a, offers or discounts) should be prorated to each order item, primarily for tax purposes.
Thus, if an order has a $20 discount and 5 items, then each item gets a $4 discount attributed to it.
Default is true
.
CartOperationServiceProperties
defines broadleaf.cartoperation.service.switchCurrencyOnLocaleSwitch
.
This property determines whether or not the cart should automatically switch to the new locale’s default currency when the locale is updated during a cart reprice.
Default is false
.
CartOperationServiceProperties
defines broadleaf.cartoperation.service.updateCatalogPricingOnCurrencyChange
.
This property determines whether or not to force an update to the catalog pricing stored on the cart when repricing with a new currency.
Default is true.
Totals are calculated in the following order:
Item adjustments (a.k.a, discounts) totals
Item totals
This is (unit-price x quantity) - adjustments total
Cart Subtotal: Without adjustments, fulfillment, or taxes
This is the sum of the cart item totals without their adjustments
Cart adjustments total
Includes the sum of all cart item adjustments
Without any fulfillment adjustments, this is included in fulfillment total already
Fulfillment total
Includes fulfillment and fulfillment item costs less adjustments
Fees total
This is the sum of the fee type cart item totals. See DefaultCartItemTypes#isExtraFee()
for the items that qualify as fees.
Tax total
First determines a TaxCalculationStrategy, which out of the box returns ACTUAL
when taxes can be calculated, and defaults to SKIP
otherwise (e.g. address is not yet provided or missing details). Then based on the strategy, the tax calculation is either actual, estimated, or completely skipped
For different behaviors on how the strategy is determined, you can override DefaultCartPricingService#determineTaxCalculationStrategy
For details on how tax calculation is done, see document on TaxService
Cart total
This is subtotal + fulfillment total + fees total + non-included tax total - adjustments total
Finally, by default, if there is a single payment on the cart it is updated so that its amount matches the cart’s total.
If there are multiple payments on the cart, DefaultCartOperationService#reallocateCartTotalMultiplePayments
can be overridden to setup a custom strategy for reallocating amounts across payments.
Tip
|
These calculations are primarily handled by CartTotalsCalculator, but tax is handled by the [TaxService]. |