top of page
Search
Writer's pictureYassine Alahyane

Sitecore Commerce - Coupons Dashboard Plugin



Coupons are an important feature of any eCommerce Platform. They help Marketing promote some products, increase Sales during targeted periods of time and retain Customers.


In Sitecore Commerce, Coupons are created through Promotions, and can be Public or Private (Single use).


Lately, the client's marketing department requested a way to view Coupons Usage such as:


  • Total usage count

  • The Orders Where a coupon was used.

  • Total discount resulting from a coupon

  • Public and Private coupons separated in the Dashboard


To achieve this we decided to build a Coupons Dashboard that will give Marketing valuable information to help them make better decisions as to how, where and when to use Coupons.


In this blog Post I will explain how this Dashboard work and what are the prerequisites for it to work properly.


Of course I am also sharing the plugin that you can find here.


The prerequisites:

Before we started building the plugin, we needed to make sure we had everything we needed.

So, looking at the requirements:


Total Usage Count: Available OOB in the Coupon Entity.

Orders where the coupon was used: Needs customization.

Total Discount resulting from a coupon: Needs customization.

Public and Private coupons separated in the Dashboard: Needs customization.


So, as you can see, we need to fill these gaps before we can build the Dashboard.


Let's take a closer look at each one of these requirements and how we can fulfill them.


Orders where the coupon was used:

In order to get the list of orders associated with a coupon, we need to build this association.

Meaning, we need to create a Relationship (List) that maps the coupon to the order.


This block, added to IOrderPlacedPipeline will build this association (Full code available in the plugin):



Total Discount resulting from a coupon:

This requirement will also be fulfilled with the association between Coupons and Orders mentioned above. As you can calculate the totals from the associated orders.


Public and Private coupons separated in the Dashboard:

When coupons are created, whether public or private, they are both added to Coupons List.

We need to make sure they are also added to new PublicCoupons and PrivateCoupons Lists based on the type of coupon.


This block overrides OOB AddPublicCouponsBlock to add the coupon to PublicCoupons.

This block overrides OOB GenerateCouponBlock to add the coupon to PrivateCoupons.


The plugin also includes a custom endpoint to add all existing coupons to Public or Private Coupons List


Now that we have the prerequisites figured out, we can start building the Dashboard.


The Dashboard consist of:


A new navigation Link added in the main Bizfx Launchpad:



The List View of Public and Private Coupons with Summary information:


The Details View of a Coupon with Monetary information and the list of associated orders:



How to Install:


  1. Clone the Github repo here

  2. Copy the 'Alyas.Commerce.Plugin.CouponsDashboard.csproj' plugin to your XC Solution and add it as a project.

  3. Add it as a dependency to your Sitecore.Commerce.Engine project.

I hope you find this plugin helpful.


Feel free to leave comments or questions.


102 views0 comments

Comments


bottom of page