Setting Up a Notification

Notification purpose is to send messages to the specified recipients when some certain event has occurred in your system.

In this context, an event is the certain action of a visitor of your site (e.g., login, registration, placing an order) or an action of a system (e.g., change order status, cron job execution).

All notifications are located at System -> Event Watcher and Notification -> Manage Notifications section. There you can edit existing notification, or create a new one.

Event watcher & notification for Magento 2 works for different store views.

How to Create New Notification

Visit System -> Event Watchers -> Manage Notifications and press Add New Notification button to open creation page. It breaks into two subsequent stages:

  1. On the first stage, you need to configure general settings:
    • Title - name of a notification.
    • Is Active - activate a notification.
    • Event - an event which should trigger a notification. They are grouped in the drop-down menu. Select it and press Continue to proceed to the next stage.

      Note

      After you had selected the Event, it can not be undone later. You will need to create a new notification, bound to another event.
  2. On the second stage, you need to configure details, which break into two sections:
    • Notification Details
      • Recipient - select recipient of a notification.
      • Notification Template - select existing template or create a new one by editing an existing.
      • Do not send more than - here you can limit the number of sent messages within a specified number of minutes. Messages, which exceed this limit will be muted.
    • Conditions: It allows you to send messages only if the selected conditions are met for the target event.
  3. Make sure that rules are activated and press Save to complete.

Notification

Adding Conditions to Notifications

Each notification has Conditions section, where you can set conditions that define when notification should be sent.

Rules

All conditionals should be enclosed in the global mode block. They have four possible global modes of applying, shown in special header If *[apply mode]* of these conditions are *[validation mode]*:

Applying modes define, when rule shall be triggered:

  • ALL - implies, that rule will be executed only when strictly all conditions were met;
  • ANY - implies, that rule will be executed only when one or more (but not all) of conditions were met;

Validation modes define, which result can produce each condition to be counted as "met":

  • TRUE - implies. that conditions should be valid.
  • FALSE - implies, that conditions should be invalid.

You can also define multiple nested mode blocks by selecting the Conditions Combination option. These modes allow creating flexible condition sets to satisfy a policy of any complexity.

Once you had selected global mode (or left it as default), press the green (+) button, and pick up a condition type.

There are many possible conditions, which depend on the every Event field. Here is their list, depending on event types:

  • Customer

    • Is Confirmed - whether the customer is confirmed.
    • Created At - where the customer was created.
    • Associate to Website - to which Website customer is associated.
    • Create In - at which Store customer is registered.
    • Group - to which Group customer belongs.
    • Personal Information - such as Gender, First Name, Last Name, Email, Date of Birth and so on.
    • Billing and Shipping Addresses - these conditions work with multiline text address representation, so use contains and does not contain operators for it.
    • Failures Number - number of last tried failures to login (counts as errors before successful login, or last fail attempt).
    • First Failure Date - date of first registered login failure.
    • Lifetime Sales - total amount, paid for all orders, placed by a customer, and completed.
    • Average Sales - average amount, which customer pays per order.
    • Number of Orders - the number of orders that the customer had placed and completed.
    • Last Activity - checks the last date of customer visit and returns the number of full days from that date.
  • Store

    • Lifetime Sales - total amount, paid for of all orders in the current store.
    • Number of Orders - the number of all completed orders in the current store.

     

  • Admin (User)

    • Personal Information - such as Username, First Name and Last Name.
    • Is Active - whether the current admin user is active.
    • Number of Logins - total number of successful logins of the current user.
    • Last Login Date - date of the last login of the current user.
    • number of failed logins - total number of failed logins of the current user.
    • Admin IP - IP address, from which admin user has been registered.
    • Is Admin Logged In from a New IP - a special flag, which is set only when an admin user is logged from IP, other than he used for registration.
  • Schedule

    • Job Code - identifier, set as name attribute for <job> tag in /etc/crontab.xml config file of the module.

      Example

      Job Code for Message Queue processing task would be mq_process, and can be seen in /vendor/mirasvit/module-message-queue/src/Mq/etc/crontab.xml config.
    • Status - the status of the job at the time of cron check. There are the following options available:
      • Pending - used when the job was just scheduled for execution.
      • Running - used when the job is running now
      • Error - used when the job was terminated unexpectedly.
      • Missed - used, when the job was not executed (for example, queue waiting time was over).
      • Success - used when the job was executed successfully.
    • Message - text condition, which allows you to check job results. Use contains and does not contain operators.
    • Time Frame Information - such as Created At, Scheduled At, Executed At and Finished At.
    • Finished Ago - allows to check, how many minutes ago was finished last cron task. Used in combination with Code to check when was certain task was last executed.
    • Run Time - allows to check, how much time cron task has consumed.
    • Last heartbeat time - allows to check, how many minutes ago was executed so-called heartbeat task. It runs each time with cron started, so using this condition, you can check whether cron actually runs.
  • Product

    These conditions are used in events of the following event groups: Customer, Shopping Cart, Wishlist, Review. They break into two large categories:

    • Product - contains all attributes, defined at Stores -> Attributes -> Product.
    • Additional Product Conditions - contains two shortcuts, which allow you to track sales of your top products:
      • Newest Products is a shortcut to Product is one of [X] most recently added products is [Yes/No] expression, where X is limit of newly added products list to check.

        Example

        If you need to know whether one of your 10 newest products was bought, you need condition Product is one of 10 most recently added products is Yes.
      • Top Selling Products - is a shortcut to Product is one of [X] top selling products is [Yes/No], where X is also a limit for a list of top-performing products to check.

        Example

        Likewise - if you need to know whether one of your top 10 products was bought, you need condition Product is one of 10 top-selling products is Yes.
  • Product Special Block

    There are two special options used in conditions:

    • Product Subselection - opens a special block If [ALL/ANY] products in cart/order matching these conditions:, which can contain one or more Products condition from category above

      This block simplifies complex conditions and makes conditions more logical and readable.
    • Product Attribute Value Comparison - opens a special block If [Comparison Mode] [Constant] of [Selection Mode] [Attribute] found while ALL of these conditions match, which also can contain one or more Products condition from category above.

      This block is quite complex. It allows you to create a collection of products using Products conditionals. Then, using Selection Mode options Same and Different, you can pick up an Attribute and compare that attribute value to some Constant. There are three possible Comparison Modes: Equal To, More than, and Less Than.

    Refer to the Examples section to know how these blocks can be properly used.

  • Shipping Address

    • Country - allows checking which country product should be delivered.
    • City - a city name, where shipping should be provided.
    • State/Province - a state name, where shipping should be provided (works only with USA, Australia, Canada, and other federal-type countries).
    • Region - a region where shipping should be provided.
    • Postcode - postal code (precise format depends on country).
  • Quote

    • Subtotal - allows checking subtotal (without tax and shipping fees).
    • Total quantity of products - the total quantity of items ordered in the current Cart.
    • Total count of products - total number of product titles in current Cart.
    • Shopping Cart products available for purchase - checks, whether Quote contains products, eligible, or do not eligible to buy.

     

  • Order

    • Status - current status of Order. List of possible order statuses can be seen at Stores -> Settings -> Order Status.
    • Total quantity of products - the total quantity of items ordered in the current Order.
    • Total count of products - total number of product titles in current Order.
    • Grand Total - actually paid money amount for current order
    • Payment Method - payment method, used for current order. List of possible Payment Methods can be seen at Stores -> Configuration -> Sales -> Payment Methods.
    • Shipping Method - shipping method, used for the current order. List of possible Shipping Methods can be seen at Stores -> Configuration -> Sales -> Shipping Methods.
    • Invoice Created - this condition is Yes, if the invoice is already issued.
    • Shipping Created - this condition is Yes, if shipping is already created.
    • Updated At Time - checks, whether Order event triggered at some time point. This condition is text-based and uses 24-hours clock notation. If you wish to check creation or update time in Magento notation, use Created At or Updated At conditions.
  • Wishlist

    • Total quantity of products - the total quantity of items in the current Wishlist.
    • Total count of products - total number of product titles in current Wishlist.
    • Subtotal - total money amount for current Wishlist (the price of each product is multiplied by item count of its kind, and then all prices summed).

     

  • Admin Notifications

    • Title - the title of admin notifications sent to the current site.
    • Description - contents of admin notifications, sent to current site. It is text-based condition, so use contains or does not contain operators.
    • Severity - importance of notifications. There are the following possible values:
      • Notice – updates, releases, and other Magento news;
      • Minor – minor updates and other messages;
      • Major – important notifications, which you should check shortly;
      • Critical – vulnerability issues and other most important notifications.
    • Url - URL, supplied with notification. It is also a text-based condition.
    • Is Read - whether notification was already read.
    • Is Removed - whether notification was removed from Inbox.
    • Date Added - date on which notification was added to the Inbox.

     

  • Error

    • Level - level of throwed error or exception. There are the following possible values, in their importance order:
      • Debug
      • Info
      • Notice
      • Warning
      • Error
      • Critical
      • Alert
      • Emergency
    • Message - message that describes error. It is a text-based condition, so use contains or does not contain operators to check its contents.
    • Backtrace - stack trace of the error. It's also a text-based condition, like above.

     

Back to Notification creation