Try our conversational search powered by Generative AI!

K Khan
Jul 20, 2016
  3918
(2 votes)

Custom promotion engine

Hypothesis: Promotion engine will run promotions only for the defined market even if editors are creating promotions for other markets also.

using System;
using System.Collections.Generic;
using System.Linq;
using EPiServer.Commerce.Marketing;
using EPiServer.Commerce.Marketing.Internal;
using EPiServer.Commerce.Order;
using EPiServer.Core;

namespace EPiServer.Reference.Commerce.Site.Features.Discounts.BrandBased
{
    public class CustomPromotionEngine : PromotionEngine
    {
        private readonly PromotionEngineContentLoader promotionEngineContentLoader;
        private readonly Lazy<ContentReference> campaignFolderRootLink;
        private readonly IRedemptionLimitService redemptionLimitService;
        private readonly PromotionFilters promotionFilters;
        private readonly PromotionApplicator promotionApplicator;
        private readonly ILineItemCalculator lineItemCalculator;
        private readonly IShippingCalculator shippingCalculator;
        private readonly IOrderFormCalculator orderFormCalculator;
        private readonly IContentLoader contentLoader;

        public CustomPromotionEngine(PromotionEngineContentLoader promotionEngineContentLoader, IRedemptionLimitService redemptionLimitService, PromotionFilters promotionFilters, PromotionApplicator promotionExecutor, ILineItemCalculator lineItemCalculator, IShippingCalculator shippingCalculator, IOrderFormCalculator orderFormCalculator, IContentLoader contentLoader) :
            base(promotionEngineContentLoader, redemptionLimitService, promotionFilters, promotionExecutor, lineItemCalculator, shippingCalculator, orderFormCalculator)
        {
            this.promotionEngineContentLoader = promotionEngineContentLoader;
            this.campaignFolderRootLink = new Lazy<ContentReference>(new Func<ContentReference>(this.GetCampaignFolderRoot));
            this.redemptionLimitService = redemptionLimitService;
            this.promotionFilters = promotionFilters;
            this.promotionApplicator = promotionExecutor;
            this.lineItemCalculator = lineItemCalculator;
            this.shippingCalculator = shippingCalculator;
            this.orderFormCalculator = orderFormCalculator;
            this.contentLoader = contentLoader;
        }

        public override IEnumerable<RewardDescription> Run(IOrderGroup orderGroup, PromotionEngineSettings settings)
        {
            if (orderGroup.Market.MarketName == "United Kingdom")
            {
                return base.Run(orderGroup, settings);
            }
            else
            {
                return Enumerable.Empty<RewardDescription>();
            }
        }

        }
}

Add registry for your custom promotion engine

c.For<IPromotionEngine>().Use<CustomPromotionEngine>();

Code was tested in quick silver

Jul 20, 2016

Comments

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog