Class RequestHooks

This class represents all script hooks that can be registered to receive notifications about storefront requests. It contains the extension points (hook names), and the functions that are called by each extension point. A function must be defined inside a JavaScript source and must be exported. The script with the exported hook function must be located inside a site cartridge. Inside the site cartridge a ‘package.json’ file with a ‘hooks’ entry must exist.

1"hooks": "./hooks.json"

The hooks entry links to a json file, relative to the ‘package.json’ file. This file lists all registered hooks inside the hooks property:

1"hooks": [
2     {"name": "dw.system.request.onSession", "script": "./script.js"},
3     {"name": "dw.system.request.onRequest", "script": "./script.js"},
4]

A hook entry has a ‘name’ and a ‘script’ property.

  • The ‘name’ contains the extension point, the hook name.
  • The ‘script’ contains the script relative to the hooks file, with the exported hook function.

Constant Summary 

ConstantDescription
extensionPointOnRequest: String = “dw.system.request.onRequest”The extension point name dw.system.request.onRequest.
extensionPointOnSession: String = “dw.system.request.onSession”The extension point name dw.system.request.onSession.

Constructor Summary 

This class does not have a constructor, so you cannot create it directly.

Method Summary 

MethodDescription
onRequest()The function is called by extension point extensionPointOnRequest.
onSession()The function is called by extension point extensionPointOnSession.

Methods inherited from class Object 

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Constant Details 

extensionPointOnRequest 

extensionPointOnRequest: String = "dw.system.request.onRequest"

The extension point name dw.system.request.onRequest.


extensionPointOnSession 

extensionPointOnSession: String = "dw.system.request.onSession"

The extension point name dw.system.request.onSession.


Method Details 

onRequest() 

onRequest(): Status

The function is called by extension point extensionPointOnRequest. It is called when a storefront request was received from the client.

Returns:

  • Status.OK for success.
  • Status.ERROR for error.

onSession() 

onSession(): Status

The function is called by extension point extensionPointOnSession. It is called when a new storefront session was started.

Returns:

  • Status.OK for success.
  • Status.ERROR for error.