User Group Based Promotion

Vote:
 

Hi Team,

           We are using custom promotions and we get promotion data by using the code below,

var promotions = promotionEngine.Evaluate(contentLink, currentMarket.GetCurrentMarket(), Currency.USD, RequestFulfillmentStatus.PartiallyFulfilled);

         In evaluate method, we have customized as follows,

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);

            //// filter the lineitems based on the required quantity(line item qty should be equal or greater than required quantity).
            var filteredLineItems = GetFilteredLineItems(lineItems, condition.RequiredQuantity);

            //// filter the applicable codes based on the filtered lineitems.
            var filteredApplicableCodes = GetFilteredApplicableCodes(applicableCodes, filteredLineItems);

            //// this condition is especially to evaluate variation(to get applicable promotions for variation).
            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));
        }

    

     Its working fine. But, we need promotion based on usergroup.Is there any way to inject metafield into virtually created cart.Kindly help.

Thanks,

Mekala V

#202844
Apr 02, 2019 12:54
Vote:
 

Hi Mekala,

I may be misunderstanding your requirements but, if you're looking to target a promotion to a specific set of users, you can set up a campaign for the targetted promotions and target that campaign using a visitor group. That way you can do the targetting without any need for code changes/deployments.

#202850
Apr 02, 2019 14:36
Vote:
 

Agree with Paul, that would be the recommended way to go. Create a visitor group that maps to an user group and then target that VG in your campaign.

The drawback of using VG is it will not work with non Http context scenarios

#202858
Apr 02, 2019 23:56
Vote:
 

Thanks for the Reply.

Is there any API to add the custom field to the virtually creating Cart while retrieving promotions. We used the below code to retrieve promotions.

var promotions = promotionEngine.Evaluate(contentLink, currentMarket.GetCurrentMarket(), Currency.USD, RequestFulfillmentStatus.PartiallyFulfilled);

#202908
Apr 03, 2019 12:34
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.