Broadleaf Microservices
  • v1.0.0-latest-prod

CartPricingService

Overview

Service that handles pricing operations on a cart.

Default Implementation Details

This workflow is as follows:

  1. Initialize PriceCartRequest

  2. Refresh Catalog-based pricing for the cart items if requested on the PriceCartRequest

  3. 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

  4. Price cart items via PricingProvider

  5. Calculate each item’s subtotal

  6. Record whether each item was priced

    1. 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,

    2. Then the cart item is wrapped in a CartItemValidationException

    3. Which is then thrown, to be handled by the the original caller (e.g., the frontend client)

  7. 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"

  8. Calculate and store bundle cart item prorated prices

  9. Calculate fulfillment pricing

  10. 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

  11. Calculate the cart totals

  12. Mark the cart as priced

  13. Persist if requested

Configuration

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.

Calculating Totals

Totals are calculated in the following order:

  1. Item adjustments (a.k.a, discounts) totals

  2. Item totals

    • This is (unit-price x quantity) - adjustments total

  3. Cart Subtotal: Without adjustments, fulfillment, or taxes

    • This is the sum of the cart item totals without their adjustments

  4. Cart adjustments total

    • Includes the sum of all cart item adjustments

    • Without any fulfillment adjustments, this is included in fulfillment total already

  5. Fulfillment total

    • Includes fulfillment and fulfillment item costs less adjustments

  6. Fees total

    • This is the sum of the fee type cart item totals. See DefaultCartItemTypes#isExtraFee() for the items that qualify as fees.

  7. 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

  8. 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].