Cert++
Close

Calling custom extension points with HookMgr

Key Takeaway

HookMgr.callHook runs all hooks registered for an extension point, in cartridge-path order, and returns only the last hook's value. If no hook and no system default implementation exists, callHook returns undefined instead of throwing.

A hook is an extension point in B2C Commerce business logic where you register scripts to customize behavior. With a custom hook, you define your own extension point name and register a script for it in your cartridge. You then call the hook from your code with the dw.system.HookMgr class.

OCAPI hooks and custom hooks

A storefront application can use two kinds of hooks. OCAPI hooks are extension points that B2C Commerce provides to run scripts before or after specific OCAPI calls. Custom hooks are extension points you define yourself and call from your own code with HookMgr methods.

You can access a custom hook from either OCAPI or storefront code. So custom hooks are useful for shared functionality across a multichannel set of applications based on the same site.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Given a use case, extend functionality or capture an event using hook extension points

0/6

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers. 796 members and growing.