Multiple hook registrations and cartridge path execution order
Key Takeaway
When a custom extension point is called, every module registered for it runs, in every cartridge on the cartridge path. Modules in cartridges listed earlier run first, but you can't control the order of several modules registered in one hooks.json file.
A hook is a script module that a cartridge registers for a named extension point. One extension point can have more than one module registered for it, either in one cartridge's hooks.json file or in several cartridges. B2C Commerce runs these modules in an order set by the cartridge path. What happens to their return values depends on whether the extension point is a custom extension point or a Shopper API extension point. Together, these rules decide which code runs, in what order, and which result comes back.
Two kinds of extension points
Each extension point is either a custom extension point or a Shopper API extension point. The two kinds differ in how they are named and how they are called.
| Custom extension points | Shopper API extension points | |
|---|---|---|
| Name | A name you define, such as app.payment.processor.default | Uses the dw.ocapi.shop.* prefix |
| How it's called | Storefront code calls dw.system.HookMgr.callHook(extensionPoint, functionName, args) | The same hooks are called for both SCAPI and OCAPI requests |