Shipping calculation reference implementation
Key Takeaway
To replace the default shipping calculation when the Cart Calculate API is enabled, extend CartExtension.ShippingCartCalculator, override calculate() to populate CartDeliveryGroupMethods, and map the class to Commerce_Domain_Shipping_CartCalculator.
Shipping calculation decides which shipping methods a buyer in a B2B Commerce store can choose at checkout and what each one costs. A developer customizes it with an Apex class, and the Cart Calculate API runs that class as one step in its checkout calculations.
Where shipping fits
Shipping calculation is one calculator inside the Cart Calculate API, which has three levels:
- Orchestrators choose which calculators run and when.
- Calculators do cart calculations such as shipping and tax.
- Services do specific calculations that can reach beyond the cart.
Pricing, inventory and taxes call underlying services that you can extend separately. The shipping calculator doesn't call a service, so your calculator class is where custom shipping logic goes.