Applying A Promotion To The Marketing Engine In Episerver Commerce

In some previous articles I’ve talked about Using The New Promotions Engine in Episerver Commerce and The New Order Repository In Commerce. Also, don’t forget you need to read this as well How To Enable Beta Features In Episerver.

That covers a lot of the basics but it fails to cover how a content editor can create a campaign and discount within Episerver

Open Commerce Manager

episerver_commerce_manager_marketing

Select the marketing tab

Create a new campaign

episerver_commerce_sales_campaign

Click on the plus button on the top left hand corner of the page and add a campaign name.

episerver_commerce_creating_a_sales_campaign

At this stage, you will have to fill in the appropriate campaign details. I won’t cover this bit but it is worth noting that if you want extra campaign details you might want to create a custom campaign. You can do this by creating a class that extends the default SalesCampaign type. An example snippet to create a custom campaign can be seen bwloe:

[ContentType(
DisplayName = "Test Campaign",
GUID = "3fd81fcb-bfac-4ebc-a7dd-4d7e200f2e2b",
Description = "Test Campaign")]
public class TestCampaignData : SalesCampaign
{
}

Creating a Discount

After we have created a campaign, click the top left plus again and click discount.

episerver_commerce_manager_adding_a_discount

From here you will need to pick out of all the discount types you have created in your solution via code.

episerver_commerce_picking_a_discount

These discounts work exactly like a page or a block so the properties you will need to fill in for your promotion will be based on the properties you defined on your discount.
episerver_commerce_campaign_page

Activating The Campaign and promotion

One import tip that can lead to a source of frustration is to forget to enable the active check-box on the campaign AND all the discounts within them. If you do not activate the promotion it will not be triggered when the promotion engine is run.

episerver_commerce_activating_promotion

Job Done

After you have created your campaign and discount and you have the code to apply the discounts (see below) you should have everything set-up. You will want to add this code in the add line item and update line item areas in your basket code.

var cart = orderRepository.Create<Cart>(Guid.NewGuid(), Cart.DefaultName);	
var orderGroup = ((IOrderGroup)cart);	
promotionEngine.Run(orderGroup);	
cart.AcceptChanges();

When you run this code you should be able to hit a break point in your promotions processors evaluate method. If the breakpoint never gets hit then make sure the campaign and promotion is active AND they have valid start and end dates.

Conclusion

In today’s guide, we’ve walked through how to create a campaign and a promotion within the Episerver commerce manager. The process is very simple but there are a few hidden gotcha’s you should be aware of.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

2 replies
  1. sushant chandan
    sushant chandan says:

    When we add the code PromotionEngine.Run(orderGroup);
    It is throwing an error that – An object reference is required for the non-static field, method, or property ‘PromotionEngine.Run(orderGroup)’
    Please guide me what to do for the error.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *