Try our conversational search powered by Generative AI!

Register custom IPromotionExcludedCatalogItemService

Vote:
 

Hi,

I have been looking at customizing how we handle Promotion Exclusions.

To do this I have implemented a basic custom romotion service' that implements 'IPromotionExcludedCatalogItemService' and have registered this in a initialization module.

However when I am testing out the implementation the code is never getting executed.

Below is the code I have written to get just the basic structure in place to ensure the code is firing:

Custom Implementition

using EPiServer.Commerce.Marketing;
using EPiServer.ServiceLocation;
using System.Collections.Generic;
using System.Linq;

namespace EPiServer.Reference.Commerce.Site.Features.Promotions
{
    [ServiceConfiguration(typeof(IPromotionExcludedCatalogItemService), Lifecycle = ServiceInstanceScope.Singleton)]
    public class CustomPromotionExclusions : IPromotionExcludedCatalogItemService
    {
        public IEnumerable<string> GetExcludedLineItemCodes(PromotionData promotionData, IEnumerable<string> codes)
        {
            return Enumerable.Empty<string>();
        }
    }
}

InitializationModule

using EPiServer.Commerce.Marketing;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Reference.Commerce.Site.Features.Promotions;
using EPiServer.ServiceLocation;

namespace EPiServer.Reference.Commerce.Site.Infrastructure
{
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]

    public class PromotionInitialization : IConfigurableModule
    {
        public void Initialize(InitializationEngine context)
        {
            
        }

        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            var services = context.Services;

            services.RemoveAll<IPromotionExcludedCatalogItemService>();

            services.AddSingleton<IPromotionExcludedCatalogItemService, CustomPromotionExclusions>();
        }

        public void Uninitialize(InitializationEngine context)
        {
            
        }
    }
}

Maybe I am just having a bad day, however I can see that the implementation is registered in the IOC container using 'DeveloperTools'.

Anyone any ideas?

Thanks

Paul

#292253
Edited, Nov 26, 2022 8:10
Vote:
 

You should not need 

[ServiceConfiguration(typeof(IPromotionExcludedCatalogItemService), Lifecycle = ServiceInstanceScope.Singleton)]

Have you tried debugging and put a break point in your code to see if it's called ? 

#292289
Nov 27, 2022 15:33
Vote:
 

Hi Quan,

Thanks for the input, yeah I have put in breaks points to see if it is getting hit however it never gets there.

I was thinking it is then something to do with how the promotion engine works, which I am still to dig into.

I have dropped the code into a quicksilver site also and it doesn't fire.

Paul

#292326
Nov 28, 2022 8:22
Vote:
 

That class should only hit if one or more of your promotions have ExcludedCatalogItems set to something 

#292327
Nov 28, 2022 8:37
Vote:
 

Ah, that would be the problem then.

What I am looking for is more a global setting to exclude over a 1000 products.

It will apply to 99% of promotions all except 1% of promotions.

Paul

#292328
Nov 28, 2022 8:42
Vote:
 

Do you mean those 1000 products will be excluded in 99% of promotions, and will be included in 1% of promotions?

That would be tricky then. If you instead only want to exclude 1000 products for all promotions it'll be easier. You can add a property (flag) to your entry, and set it to true if you want to exclude it (in case your products share same characteristics like same content type it'll even be easier). Then you can use EntryFilterSettings.AddFilter for those.

Add Co2 compensation fee in checkout | Optimizely Developer Comm

#292329
Nov 28, 2022 9:01
Vote:
 

Hi Quan,

Thanks for the info, I will have to re-think my approach to this one.

Paul

#292330
Nov 28, 2022 9:08
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.