Helpcenter +918010117117 https://cdn.storehippo.com/s/573db3149f0d58741f0cc63b/ms.settings/5256837ccc4abf1d39000001/57614ef64256dc6851749879-480x480.png" [email protected] https://www.facebook.com/StoreHippohttps://twitter.com/StoreHippohttps://www.linkedin.com/company/hippoinnovations/https://plus.google.com/+Storehippo/posts
B4,309-10 Spaze iTech Park, Sector 49, Sohna Road, 122001 Gurgaon India
call to replace anchor tags contains '/admin' in href

Hooks

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.

Adding Hooks

To add a hook in your store, go to the AdvanceSettings > Hooks section in the StoreHippo Admin Panel. Click on the Add New button and the following fields will open up: 

Name

Enter the name of the hook.

Event

Here, you can define the event before or after which the hook will be executed.

Entity

Enter the entity name on which the user wants to execute hooks. For example, ms.orders, ms.products, etc.

Command

Enter the entity command on which the user wants to execute hooks. For example, list, add, and many more.

Mode

Choose the mode of hooks. Following are the two modes:

1. Prehooks

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();
}

2. Posthooks

Posthooksare executed after the command handler.Posthooksare executed in order of priority like prehooks. The highest priority posthooks are executed first and so on.

Example: If you want to send a welcome message to the user after registration, then write aposthookon add command of the user entity.

function (req, res, next) {
    // code to send sms 
    next();
}

Action

Select the action that you want to perform.

Send Mail

Send mail notifications to the customer if a user selects this action.

Settings

  • Mailer: Select the mail template that you want to send the user on the execution of this hook.
  • To: Provide email id of the recipient user. This field also supports the handlebar.
  • Attachment Field: User can provide URL or field name in which file is stored.

Execute Handlers

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.

Priority

If multiple hooks are added on a single entity command than this field decides the priority of execution.

Description

Enter the description of the hook.

Disabled

Select the checkbox, if you want to make the hook inactive. Keep the checkbox unselected to enable the checkbox.

Sort Order

Enter the sort order for the hook. The lower the number, the further up it will display. 

2022-07-28T23:29:35.811Z