Hook registration, HookMgr, OCAPI/SCAPI hooks, and system extension points
View on GitHubSalesforceCommerceCloud/b2c-developer-tooling
b2c
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/main/plugins/b2c/skills/b2c-hooks/SKILL.md -a claude-code --skill b2c-hooksInstallation paths:
.claude/skills/b2c-hooks/# B2C Commerce Hooks
Hooks are extension points that allow you to customize business logic by registering scripts. B2C Commerce supports two types of hooks:
1. **OCAPI/SCAPI Hooks** - Extend API resources with before, after, and modifyResponse hooks
2. **System Hooks** - Custom extension points for order calculation, payment, and other core functionality
## Hook Types Overview
| Type | Purpose | Examples |
|------|---------|----------|
| OCAPI/SCAPI | Extend API behavior | `dw.ocapi.shop.basket.afterPOST` |
| System | Core business logic | `dw.order.calculate` |
| Custom | Your own extension points | `app.checkout.validate` |
## Hook Registration
### File Structure
```
my_cartridge/
├── package.json # References hooks.json
└── cartridge/
└── scripts/
├── hooks.json # Hook registrations
└── hooks/ # Hook implementations
├── basket.js
└── order.js
```
### package.json
Reference the hooks configuration file:
```json
{
"name": "my_cartridge",
"hooks": "./cartridge/scripts/hooks.json"
}
```
### hooks.json
Register hooks with their implementing scripts:
```json
{
"hooks": [
{
"name": "dw.ocapi.shop.basket.afterPOST",
"script": "./hooks/basket.js"
},
{
"name": "dw.ocapi.shop.basket.modifyPOSTResponse",
"script": "./hooks/basket.js"
},
{
"name": "dw.order.calculate",
"script": "./hooks/order.js"
}
]
}
```
### Hook Script
Export functions matching the hook method name (without package prefix):
```javascript
// hooks/basket.js
var Status = require('dw/system/Status');
exports.afterPOST = function(basket) {
// Called after basket creation
return new Status(Status.OK);
};
exports.modifyPOSTResponse = function(basket, basketResponse) {
// Modify the API response
basketResponse.c_customField = 'value';
};
```
## HookMgr API
Use `dw.system.HookMgr` to call hooks programmatically:
```javascript
var HookMgr = requi