What problem does it solve?
Register SFCC hooks via cartridge package.json and hooks.json. Use when adding hooks or troubleshooting hook registration.
Core Features & Use Cases
- Create a top-level cartridge package.json (cartridges/<cartridge-name>/package.json) and define the hooks path relative to that package.json.
- Map hook names to script files in hooks.json relative to the location of hooks.json.
- Export hook functions as CommonJS exports using the unqualified hook name (e.g., exporting "dw.order.calculate" as "exports.calculate").
- Enable the Salesforce Commerce Cloud API hook execution feature switch in Business Manager for OCAPI/SCAPI hooks.
- Ensure the cartridge is deployed to the site cartridge path and uploaded for use.
- Notes:
- The hooks path is relative to the package.json location.
- The script path in hooks.json is relative to hooks.json itself.
- For Shopper API hooks, returning a value can skip the system implementation; return nothing when you want the default implementation to run.
Quick Start
Create a top-level cartridge package.json, create hooks.json, map hooks to scripts, export the functions, enable the hook execution feature switch in Business Manager, and upload the cartridge.