Custom Cart Calculate orchestrator and default calculator sequence
Key Takeaway
By default, shipping, postShipping and taxes run only during checkout. To run them as the cart changes, a custom orchestrator must add isCartItemChanged() to their conditions, and tax also needs a custom tax calculator.
The Cart Calculate API lets a developer control how a Commerce cart is recalculated, both in the cart and during checkout. A custom orchestrator is an Apex class that decides which calculators run (pricing, promotions, inventory, shipping, postShipping, taxes), in what order, and after which buyer actions. You need to know the default sequence and its trigger logic before you can safely change either one.
Three levels of control
The Cart Calculate API has three levels of control:
- Orchestrators decide which calculators run and when.
- Calculators do the cart calculations, such as shipping and tax.
- Services do specific calculations that can reach beyond the cart. For example, the pricing service also affects product detail pages.