Vulnerability in EPiServer.Forms
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?
"Buy Products for Discount from Other SelectionBuy at least X items from catalog entries and get related catalog entries at a discount. " promotion with 100%.
Thanks in Advance.
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(
GetRedemptions(filteredApplicableCodes, promotionData, context, lineItems),
" Buy Products for Discount from Other SelectionBuy 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?
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?
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);
FulfillmentStatus fulfillmentStatus = purchaseQuantity.GetFulfillmentStatus(context.OrderForm, _targetEvaluator, _fulfillmentEvaluator, out applicableCodes);
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.
Thanks..Its working fine.
But,For example if I add 5 products to cart and i give purchaseQuantity.RequiredQuantity as 1,discount will apply for only one product.But it applied to 5 products.