Cert++
Close

Hooks versus controller extension for multichannel logic

Key Takeaway

Put logic that must run the same way for the storefront and for API clients in a custom hook, because storefront code and OCAPI hook scripts can both call it with dw.system.HookMgr.callHook. Use controller extension when the change belongs to a storefront page.

Hooks are named extension points that run your script at a set point in the application flow or at a specific event, such as before or after an OCAPI or SCAPI call. Controller extension changes an SFRA storefront route by inheriting the original controller and then adding to the route or replacing it. Sometimes the same logic must serve both the storefront and API-based client applications on the same site. In that case a hook is the better home, because both storefront code and the APIs can reach it.

Hooks or controller extension

Choose between the two by asking who needs the logic.

If the change belongs to a storefront page...

Use controller extension on the SFRA route for that page.

If the logic must run the same way for the storefront and for API clients...

Use a hook, because storefront code and the APIs can both reach it.

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.