Cert++
Close

Extending default cart calculators in Apex

Key Takeaway

Extend the base class, call super.calculate(request), change the in-memory cart, then register the class and link it to a store that has the Cart Calculate API enabled.

The Cart Calculate API runs a chain of Apex calculators for pricing, promotions, inventory, shipping and taxes whenever a buyer changes the cart or moves through checkout. You extend a default calculator by writing an Apex class that extends that calculator's base class in the CartExtension namespace, then registering it for the matching extension point. Your class can keep the standard calculation and add its own work around it.

Three levels of control

The Cart Calculate API has three levels of control:

  • Orchestrators decide which calculators run and when.
  • Calculators do the cart math, such as shipping and tax.
  • Services do specific calculations that can reach beyond the cart. For example, the pricing service also affects the store's product detail pages.
Salesforce Accredited B2B Commerce Developer Professional Study Guide

Checklist progress

0/124Learned

Code implementations against the 4 crucial reference implementations used in checkout and payment interfaces with in-depth knowledge of all supported actions

0/23

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other Salesforce Accredited B2B Commerce Developer Professional studiers. 757 members and growing.