Smarter e-commerce emails
21st of July, 2016 0 comments

Smarter e-commerce emails

A question I frequently get from customers is whether the e-commerce emails frequency and conditions can be changed.

Let's take a look at what we are dealing with:

Event Condition Notification recipient
New order created 'Send order notification' ticked in Store/Multistore configuration Admin and customer
Payment of an order 'Send payment notification' ticked in Store/Multistore configuration Admin and customer
Changing the order status of an order 'Send notification' ticked in Store/Multistore configuration Admin and customer

I'll start by saying that the settings can be a bit too confusing to memorise, so I do find myself checking the Kentico Documentation every now and then.

Why are we getting so many order emails, even for orders that have not been paid for?

Well, this one is easy to fix. Just untick the 'Send order notification' setting.

Our customers keep getting an email each time we change the status of an order

Another easy fix - untick the 'Send notification' setting.

We want the 'order status change' emails to be sent to admin, but not the customer

We want the 'new order created' email sent out only if the customer is paying by direct debit

At this point, we seem to be in trouble.

Conditional order emails

To solve the above issues, I have created a module that can help with controlling the e-commerce emails.

Instead of using the built-in settings for toggling emails on or off, the module exposes a set of macro fields for determining the condition of order emails.

Conditional Order Emails module settings

This gives you the flexibility to write a specific condition that must be met for a particular notification email to be sent.

The macro methods and objects used in the e-commerce notification emails can also be used in the condition fields. *

  • Order
  • OrderStatus
  • BillingAddress
  • ShippingAddress
  • CompanyAddress
  • ShippingOption
  • PaymentOption
  • Currency
  • Customer
  • DiscountCoupon
  • ShoppingCart
  • ContentTable
  • ContentTaxesTable
  • ShippingTaxesTable
  • EproductsTable

* This list was obtained from Kentico v7, and may differ in Kentico v8 and later versions. Please test your macro condition to ensure correct behaviour.

Usage

A good way to explain the usage of the module is a real life example: sending out the 'new order' notification email only for orders paid by cash. This could mean that the 'new order' notification email could contain bank details or payment instructions. It would not make much sense to send these out for orders paid by credit card.

Here's how to set this up:

  1. Ensure that the module is installed
  2. Open the Settings application in your website administration area. Select your website in the 'Site' dropdown (unless you want the configuration change to be global).
  3. Expand the 'E-commerce' section, and click on 'Order notifications'
  4. For the 'Order notification to customer' field, untick the 'Inherit from global settings' checkbox.
  5. In the 'Order notification to customer' field, enter the following macro (yes, without the curly braces):
    PaymentOption.PaymentOptionName == "Cash"
    • "Cash" is the code name of the payment method. This would be different from website to website. To get the code name of the payment method, open the 'Store configuration' application, and click the 'Payment methods' tab. Edit the payment method by clicking the pencil icon, and the "Code name" field will contain the value you are looking for.
  6. Test it! You will receive the 'new order' email only if you selected the appropriate payment method.

You can then proceed with tweaking your order notification email templates.

Where do I get it?

The Kentico Marketplace, of course! It's free - get it here

How do I install it?

I am personally not a fan of the NuGet way of installing modules. A lot of Kentico users either do not have Visual Studio on their computer, or they are not familiar with how to use it.

My approach was to make this a self-installing module. This means that the module will install itself once the files are copied to your website folder.

The installation steps are:

  1. Download the module
  2. Extract the files
  3. Copy the extracted DLL file to the CMS/bin folder of your website. Careful when deploying to live sites. Your website will slow down for a few minutes, while it recompiles.
  4. Add the following key to the CMS/web.config file, under the <appSettings> element: <add key="WDM.ConditionalOrderEmailsProvider.Init" value="true" />
  5. Open the Event Log, and find the entry that shows "ConditionalOrderEmails Module Installed". Can't see this, or there is an "Error Installing ConditionalOrderEmails Module" error in the logs? Contact me for help.
  6. Configure to your liking
  7. Enjoy!

Enabling/disabling the module

To disable the module, simply remove the WDM.ConditionalOrderEmailsProvider.Init key from the appSettings section of the web.config file (see the installation instructions, for the exact line). You could also delete the DLL file from the CMS/bin folder, however this will recompile your site, so be careful when doing this on a live website.

How did you build it?

I'm glad you asked! To keep this post neat and tidy, I will explain the inner workings in a future post. Stay tuned!

Written by Kristian Bortnik



Comments