Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
I would suggest you to wait for Commerce 13 which is just a few weeks away https://world.episerver.com/blogs/Quan-Mai/Dates/2019/2/new-feature-in-commerce-13-exclude-catalog-items-per-promotion/
@Quan, thank you for the reply. But I dont think we have the bandwidth to upgrade the solution at this point in time. And also this is something more dynamic, there could be N number of items which will need to be filtered based on a metafield value for example. And not a manual step where I go in and exclude items manually for a promotion.
Hi,
I am using commerce 12.15.0, I have a requirment to exclude certain items from all line item promotions. My approach is to override the GetLineItems method in the EntryPromotionProcessorBase abstract class. This way I can add my exclusion logic in one place, and since all entry promotions use this processor they should automatically filter the line items. But now I have a problem, EntryPromotionProcessorBase being an abstract class, I need to implement Evaluate and GetPromotionItems method. But if I do this in the processor it would apply to all line items promotions right? And then all the different types of promotions would not be of any use. Below is my code, I need help to create a generic processor which can be used by all entry promotions.
[ServiceConfiguration(Lifecycle = ServiceInstanceScope.Singleton)] public class TestProcessor : EntryPromotionProcessorBase<EntryPromotion> { public override IEnumerable<ILineItem> GetLineItems(IOrderForm orderForm) { //Custom logic to exclude certain line items from promotions. CustomerPriceService priceService = ServiceLocator.Current.GetInstance<IPriceService>() as CustomerPriceService; string currentCustomerGroup = ServiceLocator.Current.GetInstance<ICurrentCustomer>().GetCurrentCustomer().CustomerGroup; var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>().GetCurrentMarket(); IEnumerable<ILineItem> defaultList = base.GetLineItems(orderForm); List<ILineItem> lineItems = new List<ILineItem>(); foreach(ILineItem item in defaultList) { bool hasCustomerGroupPrice = false; PriceFilter filter = new PriceFilter() { Currencies = new Currency[] { new Currency("USD") }, CustomerPricing = new CustomerPricing[] { CustomerPricing.AllCustomers, new CustomerPricing(CustomerPricing.PriceType.PriceGroup, currentCustomerGroup) }, Quantity = 1 }; hasCustomerGroupPrice = priceService.HasCustomerGroupPrice(currentMarket.MarketId, DateTime.UtcNow, new CatalogKey(item.Code), filter); if(hasCustomerGroupPrice) { lineItems.Add(item); } } return lineItems.AsEnumerable(); } protected override RewardDescription Evaluate(EntryPromotion promotionData, PromotionProcessorContext context) { throw new NotImplementedException(); } protected override PromotionItems GetPromotionItems(EntryPromotion promotionData) { throw new NotImplementedException(); } }