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
This should be changed
var redemptions = orderForm.Shipments .First() .LineItems .Select(lineItem => new AffectedItem(lineItem)) .Select(affectedItem => new RedemptionDescription(affectedItem));
it should be
redemptions = new List<RedemptionDescription>() { new RedemptionDescription(new AffectedOrder(orderForm)) };
Hi,
It should return the items which the promotion applies to. For an order promotion you can return this:
return new PromotionItems( promotionData, new CatalogItemSelection(null, CatalogItemSelectionType.All, true), new CatalogItemSelection(null, CatalogItemSelectionType.All, true));
I have just upgraded EPiServer Commerce from 9.8.1 to 9.15.0. I am using custom promotion and found that API for promotions has been changed.
Here is the current code for custom OrderPromotion:
[ContentType(GUID = "E6271950-DB98-4FE6-9626-CEFCBF46BE19")] public class AdditionalDiscountPromoData : OrderPromotion { } public class AdditionalDiscountPromoProcessor : PromotionProcessorBase
{
protected override RewardDescription Evaluate(
AdditionalDiscountPromoData promotionData,
PromotionProcessorContext context)
{
var orderForm = context.OrderForm;
var cart = context.OrderGroup as Cart;
if (cart == null)
{
return NoReward(promotionData);
}
var additionalDiscountPercent = 10.0m;
if (!orderForm.Shipments.Any()) // Shipment gets removed when no items in the cart
{
return NoReward(promotionData);
}
var redemptions = orderForm.Shipments
.First()
.LineItems
.Select(lineItem => new AffectedItem(lineItem))
.Select(affectedItem => new RedemptionDescription(affectedItem));
return RewardDescription.CreatePercentageReward(
FulfillmentStatus.Fulfilled,
redemptions,
promotionData,
additionalDiscountPercent,
description: $"{additionalDiscountPercent} % discount applied to an order");
}
private RewardDescription NoReward(PromotionData promotionData)
{
return new RewardDescription(
FulfillmentStatus.NotFulfilled,
Enumerable.Empty(),
promotionData,
unitDiscount: 0,
unitPercentage: 0,
rewardType: RewardType.None,
description: "No discount applied");
}
protected override PromotionItems GetPromotionItems(AdditionalDiscountPromoData promotionData)
{
return null;
}
}
There is one new method to override "GetPromotionItems" I don't know how to use - just returning null.
Another change compared to previous version is that instead of afftected items RewardDescription expects RedemptionDescription sequence. RedemptionDescription constructor can take 1 or more affected items. I am just mapping affected item to RedemptionDescription one to one.
I went through with debugger and seems that Evaluate method is executed correctly. GetPromotionItems method is never called. But discount doesn't get applied on the order anymore. Previous version work perfectly.
What am I missing?