Inventory check reference implementation and inventory reservation
Key Takeaway
Checking inventory and reserving inventory use different extensions, and the place order API decides when inventory is reserved.
A B2B Commerce checkout does two jobs with inventory: checking inventory while the cart is calculated, and reserving inventory so it is held while the order is placed. Each job has its own extension. The place order API that the checkout uses decides when inventory is reserved and whether the reservation is temporary or final.
Checking and reserving inventory
An inventory check finds out whether the products are available. A reservation holds the inventory while the order is placed.
Picture a buyer who wants 10 boxes of gloves. An inventory check looks at the shelf and reports that 10 boxes are there, but the boxes stay on the shelf. A reservation sets those 10 boxes aside for this buyer.
Each job has its own base Apex class and extension point name, so each job gets its own extension provider.
| Inventory cart calculator | Inventory service | |
|---|---|---|
| What it does | Calculates inventory for cart and checkout based on the inventory service | Reserves and tracks available inventory |
| Base Apex class | CartExtension.InventoryCartCalculator | commerce_inventory.CommerceInventoryService |
| Extension point name | Commerce_Domain_Inventory_CartCalculator | Commerce_Domain_Inventory_Service |
By default, the inventory service uses the Omnichannel Inventory (OCI) system for inventory data. Reserving inventory in an external system requires a class that extends commerce_inventory.CommerceInventoryService and is mapped to the Commerce_Domain_Inventory_Service extension point. An inventory cart calculator is not enough, because it only handles inventory checks during cart calculation and does not create reservations.
Salesforce provides a sample inventory cart calculator in the forcedotcom/commerce-extensibility GitHub repo, next to samples for the pricing service and the promotion, shipping, and tax calculators.
The cart calculation orchestrator is a separate extension provider that extends CartExtension.CartCalculate, not CartExtension.InventoryCartCalculator. The orchestrator's sample shows the default orchestration behavior for B2B and B2C stores, both before checkout and during checkout.