Good question. I don't have an answer out of my head, but I'll look into it. This is, however, likely a piece that we are missing
Untested by me, but it seems the workaround is to inherit from EntryRewardApplicator, and then inside the protected methods you can add information to the AffectedEntries, which each contains a list of PriceEntry and each PriceEntry has an ILineItem. Not sure if it works, but it looks like it will
Thanks Quan. I have something half working, needs more work and testing but as an initial implementation this is what I have.
[ServiceConfiguration(Lifecycle = ServiceInstanceScope.Singleton, ServiceType = typeof(EntryRewardApplicator))] public class CustomEntryRewardApplicator : EntryRewardApplicator { private static readonly Injected<IContentLoader> _contentLoader; protected override Decimal ApplyPercentage(AffectedEntries item, Decimal percentage, PromotionProcessorContext processorContext) { var returnVal = base.ApplyPercentage(item, percentage, processorContext); // Update custom properties on lineitem PriceEntry priceEntry = item.PriceEntries.FirstOrDefault(); if (priceEntry != null) { // Retrieve the campaign if (_contentLoader.Service.TryGet(priceEntry.Promotion.ParentLink, out SalesCampaign campaign)) { priceEntry.ParentItem.Properties["PromotionCode"] = campaign.Code; } } return returnVal; } }
NIce. However the default implementation is already registered via ServiceConfiguration, so if you want to make sure your implementation gets used,you have to register it in IConfigurationModule instead.
Just FYI: I am working on something that will make the override easier. But let's see if that gets enough approvals from my colleagues
OK thanks Quan. This seems to be working correctly for me, so for the time being will stick with this, but if an easier override does make it into a release I'd be keen to upgrade.
Commerce version 12.5.0
Hi All,
Is there a way to set custom properties on a lineitem when a discount is applied by the promotions engine?
All the discounts in our site will be of type BuyQuantityGetSelectedItemsDiscount and they will all be percentaged based as well. I can see the LineItemDiscountAmount is set, but I'd also like to set some custom properties like the campaign the discount is in and the percentage from the discount that was applied. Would also like to set the criteria that meant the lineitem was affected by the discount. For example when setting up the discount in Marketing, you can select category nodes as part of the criteria. If the variation is within a category node that means the discount is applied to the lineitem, I'd like to store the category node against the lineitem. Because of the node hierarchy, this won't necessarily be the direct node of the variation, it may be the parent node or grandparent node, etc... Is that possible?
Thanks
Mark