You do not create Cart Items directly; the storefront creates them when a shopper adds products. What you do configure is the Cart Calculate API, which is the framework that prices, promotes, checks inventory, and taxes each Cart Item. Here is how to set up custom cart calculation in a B2B or D2C store.
- Decide which calculators you need
The Cart Calculate API ships Pricing, Promotions, Inventory, Shipping, and Taxes calculators. Confirm which standard ones meet your needs and where you require a custom integration, such as an external tax engine or a third-party inventory source.
- Write an orchestrator
Create an Apex class that extends CartExtension.CartCalculate and override the calculate method. The orchestrator controls which calculators run and in what sequence when the cart changes.
- Register the extension point
Register your orchestrator for the Commerce_Domain_Cart_Calculate extension point so the platform invokes it on cart updates. Without registration, the default calculation runs instead.
- Plug in custom calculators
For a custom tax or inventory integration, implement the matching calculator and have your orchestrator call it. The calculator reads the Cart Items, computes its result, and writes values back to the cart.
- Test on representative carts
Validate in a sandbox with carts that mix product and charge lines, multiple delivery groups, and stacked promotions. Confirm the totals and the Cart to Order mapping before you enable it in production.
Pricing, Promotions, and Inventory run during both cart and checkout; Shipping and Taxes run only at checkout by default.
Extend CartExtension.CartCalculate and override calculate to control calculator order and which ones execute.
Commerce_Domain_Cart_Calculate is the registration name the platform uses to find and invoke your orchestrator.
Choose whether an out-of-stock Cart Item blocks checkout or is flagged for backorder, tuned per product type.
- Shipping and Taxes do not run during the cart phase by default, so cart-stage totals exclude them until checkout.
- A custom field only maps from Cart Item to OrderItem if the same API name exists on both Cart and Order (and OrderSummary).
- Loading and saving the in-memory CartExtension.CartItem is done by Salesforce, not by your Apex; you read and adjust, the platform persists.
- Stacked line-level and cart-level promotions can interact in surprising ways; test the combined discount on real carts.