Cart and coupon operations with commerce/cartApi
Key Takeaway
In commerce/cartApi, Imperative APIs change the cart and Wire Adapters read it. To remove a coupon, pass the applied coupon's ID, not the code text.
commerce/cartApi is the Storefront API bundle that a custom Lightning Web Component uses to work with a buyer's cart. Storefront APIs are supported in B2B and B2C stores built with LWR templates. Salesforce provides commerce/cartApi so custom cart components get entitlement guardrails, caching, and coordinated page updates without relying on platform UI APIs or Aura controllers.
Why use Storefront APIs
Storefront APIs connect Lightning Web Components to data and run processes such as adding a product to a cart or applying a coupon. Storefront APIs are preferred over platform UI APIs and Aura controllers for four reasons:
- Security: Storefront APIs apply guardrails such as buyer entitlement automatically.
- Performance: Multiple cache layers (browser, CDN, server) stop the same data from being fetched repeatedly.
- Convenience: Storefront APIs aggregate data from sources like catalogs and price books.
- UI cohesiveness: Cart components update together in real time.