2017/03/24

How to setup an event based sales rule, or - grant a discount if the customer experiences an error!

Increase conversion

Monitoring- and Analytictools like Google Analytics are great things to optimize your E-commerce system to sale more of your products.

But, wouldn't it be great to interact with the user right in the situation, when he is leaving the direct way to the checkout and maybe changing his mind?

To guide the user back on the way to a sale you can for example  apply a exclusive discount or put a free product to is cart - event based and automatically.

How to setup an event based sales rule

First off, you'll need to download the latest Notify module for Magento here: https://grafzahl.io/notify-module/

Now you are able to go through the easy install process, which is explained here: https://documentation.grafzahl.io/notify-module/doc/install-setup.html

At this point, we are very close to our goal.

Create a new notification

General settings

To do that, click on your Notify menu in the main navigation of your Adminpanel.

Now you'll see the common Magento grid where you can add a new Item with the upper right "New"-Button.

This page will load:
Notify General Tab
The Notify Configuration Item in the Magento Adminpanel. "General"-Tab.


Fill your Title and Description. These fields are not used for technical purpose. They are only for you to identify the notifications.

The switch "Active" is self-explaining. The transmission type defines, how your notifications or reports are send to you. The default is Email. More transmission types like Slack, SMS or Logfile are on our Todo-List.

The summary type option will give you the possibility to summarize any of the recorded issues of this notification:
  • Immediately: The issue will be sent immediately as it is recorded. The Report configuration will offer you Text-Templates to define the message which is composed for the specific issue.
  • Daily, Weekly, Monthly: The issues of every defined event-trigger will be summarized and reported in the selected frequence. The Report configuration will offer you different elements which you can configure to compose the collected data in any way you would like to see the issues.
Click Immediately here, to get notified immediately. This also is an indication for you, that your sales rule has been applied.

With the Store Multiselect field you can decide, in which shops this notification item is valid and collects issues.

Trigger selection

The trigger selection looks like this:
The Notify Event-Trigger Selection. The left column contains all Areas. When you click on an Area, the second column will list all available Event-Triggers for that Area.


You can select from some defined Trigge-Events that are available for Notify. The name of them are describing most likely when they are triggered and therefor creating a new issue.

The Trigger are devided into Areas. They are explaining where this Event will trigger, like "Admin Panel".
When you click on one of the Areas, you will get a list of all available Events in the second column.
Clicking on one of them will add it to the right column. This indicates that it is selected for your Notification.

We want to apply a sales rule, when the customer opens a 404-Page. Therefor we select "Error" and "User gets 404 page" to get notified every time a customer opens a URL in our online store which does not exists.

To go on with the Rule Conditions and Report Configuration you'll need to save the Notification by now. This enables the Trigger selection and reveal the fields for the Triggers in the next Tabs.

Rules configuration

This Tab will let you filter the issues on information that is available in the situation of the issue. At the moment there are no filter options for the 404-Error-Trigger. So we can skip that.

Report settings

This is where you define what is reported in case of an issue. You will see a Textarea field with available Placeholders on the right. You can type any text you like and add those placeholders to create a message that is most informative for you.

Define your message for that Issue and fill it with the available Placeholders on the right. Click "Save Template" to submit the Template text. Then click "Save and Continue Edit".

Define the automated Action

This configuration is the most interesting. Here you can define what will happen if the issue was reported.




You will get the form above, if you enable the switch on the right. Select the option "Apply a sales rule" on the left side of the form.

In the loaded options on the right, select the sales rule which should be applied to the customers cart after he got a 404 Page.

Now you are ready.

2017/03/16

How to get an Email Notification for every Exception

Magentos error handling is pretty good. PHP Errors, Warnings or Notices are written into the system.log file and Exceptions are caught by Magento to show the customer a (not very good looking) page and write the error stack into a file as a report for the system administrator.

Ok, but how often are those exceptions coming up? Sure - you tested your ecommerce store very well to prevent those situations for your customers, but you know - its software!

Even the best tested site is not 100% bug-free.
Some customers may contact you and report their error but the most wont. And you really want to fix any Exception that is thrown by your shop.

So here is the solution: We'll integrate an instant notification or a daily report for any exception that is occuring on your Magento webshop.

With the help of our module Notify for Magento, that is very easy.

The module is a notification system that also can create summaries of the collected data and send them as recurring reports.

To be able to configure a notification or report for a thrown exception, we only need to insert a little piece of code into the exception page:


// prepare data object
$data = Mage::getSingleton('notify/issue_data');
$data->setTrigger('customer_experienced_exception')
    ->setArea('error')
    ->setBacktrace(htmlspecialchars($this->reportData[1]))
    ->setError($this->reportData[0])
    ->setReportId($this->reportId);
// trigger customer_experienced_exception
Mage::helper('notify/notification')->recordIssue($data);

Put this on the end of the file /errors/default/report.phtml.

We have to setup this new trigger for Notify to be able to configure a notification or report in the admin panel.

Open your notify.xml of your custom module that extends Notify or of Grafzahl_Notify module (not recommended).

Add the configuration for our new trigger (config/notify/trigger - node):


<error label="Error">
    <customer_experienced_exception label="User gets an Exception">
        <enable>1</enable>
        <passed_data>
            <error type="string">Error Message</error>
            <report_id type="string">Report Id</report_id>
            <backtrace type="string">Backtrace</backtrace>
        </passed_data>
        <renderer>notify/renderer_error_customerExperiencedException</renderer>
    </customer_experienced_exception>
</error>


Create the renderer class and you are done! The renderer class is only a simple class with extends the renderer abstract like the following:


/**
 * Grafzahl_Notify
 *
 * @category    Grafzahl
 * @package     Grafzahl_Notify
 * @copyright   Copyright (c) 2017 Grafzahl (https://grafzahl.io)
 * @license     https://grafzahl.io/license
 */
class Grafzahl_Notify_Block_Renderer_Error_CustomerExperiencedException
    extends Grafzahl_Notify_Block_Renderer_Abstract
{

}

It is recommended to create those files in your custom module that is extending the default Notify module.

Configure the notification

Now you can configure the report or notification in the admin panel. Read about that in our documenation.

To get this powerful notification module for your Magento store, visit https://grafzahl.io/notify-module