Available in Enterprise Plan and above.
Hooks are useful functions/codes that execute before or after a specific event happens in a store. For example, after a new customer is created, before the product lists or reviews listing, etc.
To add a hook in your store, go to the
Enter the name of the hook.
Here, you can define the event before or after which the hook will be executed.
Enter the entity name on which the user wants to execute hooks. For example, ms.orders, ms.products, etc.
Enter the entity command on which the user wants to execute hooks. For example, list, add, and many more.
Choose the mode of hooks. Following are the two modes:
Prehooks are function/code that is executed before the command handler. Prehooks are executed in order of priority. The highest priority prehooks are executed first and so on.
Example: If you want to list only published products, write a prehook on the list command of the products entity:
function (req, res, next) {
if (!req.query) {
req.query = {}
}
if (!req.query.filters) {
req.query.filters = [];
}
req.query.filters.push({field: 'publish', value: '1', operator: 'equal'});
next();
}
Example: If you want to send a welcome message to the user after registration, then write a
function (req, res, next) {
// code to send sms
next();
}
Select the action that you want to perform.
Send mail notifications to the customer if a user selects this action.
Settings
Handler: When you select the handler option, you can add the custom code that will be executed before or after command execution according to the mode.
If multiple hooks are added on a single entity command than this field decides the priority of execution.
Enter the description of the hook.
Select the checkbox, if you want to make the hook inactive. Keep the checkbox unselected to enable the checkbox.
Enter the sort order for the hook. The lower the number, the further up it will display.