1
protected override RewardDescription Evaluate(EntryPromotion promotionData, PromotionProcessorContext context)
{
  var lineItems = GetLineItems(context.OrderForm);
  var condition = promotionData.Condition;
  var applicableCodes = targetEvaluator.GetApplicableCodes(lineItems, condition.Targets, condition.MatchRecursive);   
  var filteredLineItems = GetFilteredLineItems(lineItems, condition.RequiredQuantity);  
  var filteredApplicableCodes = GetFilteredApplicableCodes(applicableCodes, filteredLineItems);                

  if (applicableCodes.NotNullOrEmpty() && filteredApplicableCodes.IsNullOrEmpty())
  {
    return RewardDescription.CreatePercentageReward(
      FulfillmentStatus.PartiallyFulfilled,
      Enumerable.Empty<RedemptionDescription>(),
      promotionData,
      promotionData.Percentage,
      Enum.GetName(typeof(RequestFulfillmentStatus), RequestFulfillmentStatus.PartiallyFulfilled));
  }  

  var fulfillmentStatus = fulfillmentEvaluator.GetStatusForBuyQuantityPromotion(
    filteredApplicableCodes,
    filteredLineItems,
    condition.RequiredQuantity,
    condition.RequiredQuantity);

  return RewardDescription.CreatePercentageReward(
    fulfillmentStatus,
    GetRedemptions(filteredApplicableCodes, promotionData, context, lineItems),
    promotionData,
    promotionData.Percentage,
    fulfillmentStatus.GetRewardDescriptionText(localizationService));
}

We have customized promotion to apply promotion only for lineitem that has required quantity. Now, when we exclude a promotion from other and two line items applicable for both promotions, only one promotion is getting applied for both.

eg: we want one line item to get applied "buy 10 items and get 10%" and others to "buy 20 items and get a 20% offer".

If it is a single line item applicable for promotion, it works fine!. (We are using Commerce 12.5.1)

Yarl
  • 728
  • 1
  • 7
  • 26
Mekala V
  • 31
  • 5

1 Answers1

0

Thanks for the reply.

We achieved the solution by using affected entries.

  ////To check applied discount entries.
        var isPromotionApplied = context.EntryPrices.Prices.Count() > 0 ? true : false;
        if (isPromotionApplied)
        {
            ////To filter the item if it have already discount.
            var codesAlreadyDiscounted = context.EntryPrices.Prices.Select(x => x.ParentItem.Code);
            lineItems = lineItems.Where(x => !codesAlreadyDiscounted.Contains(x.Code));
        }
Mekala V
  • 31
  • 5