Add discountIn my previous post I desribed how to programmatically create a custom promotion in EPiServer Commerce 9 beta. The post was developer focussed and showed how we can create custom promotions/discounts in EPiServer 9 than previously possible. In this post I will contrate on the experience of our editors and merchandisers as we want them to see something nice in the UI when working in their campaigns than a forms view right?

Visualising the promotion to our users

When building out the a custom promotion as described in Creating a custom promotion with the new EPiServer Commerce 9 promotion engine (BETA) - Part I the promotion options are only presented to user using the forms view in the EPiServer UI. If we want to visualise our promotion as part of the campaign we need to do some other tasks. Fortunately if you are familiar with developing with EPiServer or MVC then the concepts should be very familair:

Model

The model is simply the VisitorGroupPromoData as defined in Part I of this blog post.

View

Next up is the view to show information about the promotion on the page:

@using EPiServer.Commerce.Marketing.Promotions
@using EPiServer.Commerce.UI.Models.Promotion
@using EPiServer.Web.Mvc.Html
@inherits System.Web.Mvc.WebViewPage>
@{
    Layout = Model.LayoutPath;
}

@Html.Raw(String.Format( Model.Description, Model.PromotionData.MatchingVisitorGroups, Html.PropertyFor(x => x.PromotionData.DiscountPercent, new { CustomTag = "span", CssClass = "threshold-selector" }).ToHtmlString()))

This view allows the promotion to be visualised in the UI when editing campaigns in the new Marketing UI in EPiServer Commerce 9:

Commerce UI view

Controller

The final piece is our controller. It is as simple as it gets and simply wires up our Promotion Data to a view:

public class VisitorGroupPromotionController : ContentController
{
    public VisitorGroupPromotionController() { }

    public ActionResult Index(VisitorGroupPromoData currentContent)
    {
        PromotionModel model =
            new PromotionModel(currentContent,
                "Users in the following visitors group(s): {0}, get {1}% off their order");
        return base.View(model);
    }
}

In my example the visitor group selection must be edited in the forms view and the discount percentage can be edited on page.

Conclusion

The new version of the EPiServer Commerce 9 promotions engine is looking very developer friendly. To create a custom promotion can be as few as 3 classes and should allow developers and marketers to deliver their functionality quicker and easier than before.

Please note!

This post was written on the current beta version v8.13.4 of EPiServer Commerce and is subject to change. Please refer to the official documentation: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Marketing/Marketing for the latest information.

I will try to update this post as/when possible to ensure it's kept up to date.


Comments

Recommendations for you