In 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.
Select the marketing tab
Click on the plus button on the top left-hand corner of the page and add a campaign name. 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 below:
DisplayName = "Test Campaign",
GUID = "3fd81fcb-bfac-4ebc-a7dd-4d7e200f2e2b",
Description = "Test Campaign")]
public class TestCampaignData : SalesCampaign
After we have created a campaign, click the top left plus again and click discount. From here you will need to pick out of all the discount types you have created in your solution via code. 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.
One important tip that can lead to a source of frustration is to forget to enable the active checkbox 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.
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);
When you run this code you should be able to hit a breakpoint in your promotions processors evaluate method. If the breakpoint never gets hit then make sure the campaign and promotion are active AND they have a valid start and end dates.
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.
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