We ended up writing a custom promotion for that, following the guide:
https://world.episerver.com/documentation/developer-guides/commerce/marketing/custom-promotions/
Look into the implementation for the default "Spend for free items" promotion and any promotion that has a selection for inspiration.
Thanks, Erik Norberg,
I implemented a custom promotion. But how can I pass "Limit number of discounted items" value to Promotion Engine? and how to pass dynamic values to "Limit number of discounted items"?
I don't follow you, what value is that?
Can you share the code of your implementation?
Thanks for your reply.
I use the below code.
protected override RewardDescription Evaluate(EntryPromotion promotionData, PromotionProcessorContext context)
{
var lineItems = GetLineItems(context.OrderForm);
var condition = promotionData.Condition;
int requiredQuantity = condition.RequiredQuantity;
var applicableCodes = targetEvaluator.GetApplicableCodes(lineItems, condition.Targets, condition.MatchRecursive);
//// filter the lineitems based on the required quantity(line item qty should be equal or greater than required quantity).
var filteredLineItems = GetFilteredLineItems(lineItems, requiredQuantity, condition.MixMatch);
//// filter the applicable codes based on the filtered lineitems.
var filteredApplicableCodes = GetFilteredApplicableCodes(applicableCodes, filteredLineItems);
var fulfillmentStatus = fulfillmentEvaluator.GetStatusForBuyQuantityPromotion(
filteredApplicableCodes,
filteredLineItems,
requiredQuantity,
minRequiredQuantity
);
return RewardDescription.CreatePercentageReward(
fulfillmentStatus,
GetRedemptions(filteredApplicableCodes, promotionData, context, lineItems),
promotionData,
promotionData.Percentage,
fulfillmentStatus.GetRewardDescriptionText(localizationService));
}
I need
" Buy Products for Discount from Other Selection
Buy at least X items from catalog entries and get related catalog entries at a discount." promotion.
If user buy A,B,C (3) products,we should apply 10% discount for Product D.If I use this default its working fine.But How can I pass "(Limit number of discounted items)MaxQty" in Evaluate method.Is there any possiblity?
kindly help.
Is this a new promotion and no longer the give away from your original post?
For give aways your processor should inherit form the GetFreeItemsProcessorBase
public class YourCustomPromotionProcessor : GetFreeItemsProcessorBase<YourCustomPromotionData>
What does your PromotionData look like?
Than you.
I used EntryPromotionProcessorBase.
MyEntryPromotionProcessor : EntryPromotionProcessorBase<MyEntryPromotion>
Can you explain me the Evaluate() method for GetFreeItemsProcessorBase?.How can I achieve this?
Decompiling the source code for GetFreeItemsProcessorBase gives you:
protected override RewardDescription Evaluate(TEntryPromotion promotionData, PromotionProcessorContext context)
{
PurchaseQuantity purchaseQuantity = _conditionGetter(promotionData);
IList<string> applicableCodes;
FulfillmentStatus fulfillmentStatus = purchaseQuantity.GetFulfillmentStatus(context.OrderForm, _targetEvaluator, _fulfillmentEvaluator, out applicableCodes);
if (!fulfillmentStatus.HasFlag(FulfillmentStatus.Fulfilled))
{
return NotFulfilledRewardDescription(promotionData, context, fulfillmentStatus);
}
context.AddConditionalItems(promotionData.get_ContentLink(), applicableCodes, purchaseQuantity.RequiredQuantity);
IEnumerable<RedemptionDescription> redemptions = GetRedemptions(promotionData, context, applicableCodes);
return RewardDescription.CreateFreeItemReward(fulfillmentStatus, redemptions, promotionData, fulfillmentStatus.GetRewardDescriptionText(_localizationService));
}
Of course you have to replace the PurchaseQuantity condition with your own one to support your use cases.
Hi,
If a customer buys a set of items, we would give one item(which is not in that set) free. There is no default Epi promotion to achieve this. Is there any way to customize?
We tried,
"Buy Products for Discount from Other Selection
Buy at least X items from catalog entries and get related catalog entries at a discount. " promotion with 100%.
Thanks in Advance.