Unique voucher/coupon codes in Episerver Commerce using Episerver Campaign

Tags: Episerver Commerce Episerver Campaign Oct 30, 2017

Using Episerver Commerce it’s possible to offer discounts to customers using the built in discount engine. Discounts can also have a coupon code associated meaning only customers who know that code can get the discount. However, it’s not possible to assign individual coupon codes for customers using Episerver Commerce alone. On the other hand Episerver Campaign can create, allocate and distribute unique coupon codes to customers.

So this post describes how it's possible to use Episerver Commerce and Episerver Campaign to validate and use individual coupon discount codes for customers.

The diagram below shows the interaction between the customer, Episerver Commerce and Episerver Campaign and describes what the code implements: 

The steps below describe how it's possible to implement the unique voucher codes for customers using Episerver Commerce and Episerver Campaign. 

Define the custom promotion type

First of all a custom promotion type is needed to allow Episerver Commerce users to select a coupon type that’s required in order to be eligible for the discount. The example below inherits one of the built in types (SpendAmountGetOrderDiscount). A new property is added to define the coupon code type defined in Episerver Campaign:

This new property gives users the ability so select from the available coupon codes that have been defined in Episerver Campaign:

It should be noted that there is some plumbing to connect the Episerver Campaign APIs to check for coupon types. Specifically the Episerver Campaign CouponBlockWebservice API is used in the CouponCodeTypesSelectionFactory to retrieve a list of coupon code types from Episerver Campaign and display them in the discount definition in Episerver Commerce. Full code can be found on Github and Gist as described in the Code section at the end of this post.

Coupon filter (ICouponFilter)

A ICouponFilter implementation is also required to check if the coupon code matches one that has been assigned to the user and also is the correct type for the discount. This uses some more of the Campaign APIs to ensure the coupon is valid and has been assigned to the current user, specifically the Episerver Campaign CouponCodeWebservice API:

Marking the coupon as used (ICouponUsage)

When the customer checks out and completes the order the coupon should be marked as used to ensure the customer cannot get the same discount. We can use the ICouponUsage interface for this:

This simply marks the coupon as used so the customer cannot use it again.

Outcome

The outcome means that Episerver Campaign can distribute emails, SMS’s or even push notifications to customers containing unique coupon codes for those customers. Customers can then use the coupon code assigned to them to achieve a discount in their basket:

Conclusion

This post was written to share the code and approach that was demonstrated at the Episerver Partner Close up events in Stockholm and Helsinki. However it does show how easy it is to implement powerful features using the Episerver platform with little implementation effort. Some thought around caching would be advisable for production scenarios to reduce the dependencies on the Episerver Campaign APIs during promotion and price calculations.

All code was written on top of a standard Quicksilver site. 

Code

The wrapper for the coupon API’s can be found over on Github and the code for the promotion can be found on Gist.

References / Useful links

comments powered by Disqus