Try our conversational search powered by Generative AI!

Promotions - NullReference exception at CalculateAndCommit

Vote:
 

Hi, I am running Episerver.Business.Commerce version 9.22 with EpiServer 9.12.1 on a site and we have set up a custom Order promotion with the VNext workflow, but it is throwing a NullReferenceException whenever we return a Fulfilled status on a RewardDescription from the Evaluate Function.

This is the code generating the RewardDescription that leads to the error:

protected override RewardDescription Evaluate(NonFullMemberDiscountPromotion promotionData, PromotionProcessorContext context)
        {
            var orderForm = context.OrderForm;
            
            var discountAmount = 10;

            List redemptionDescription = new List { CreateRedemptionDescription(orderForm) };

            var rewardDescription = RewardDescription.CreateMoneyReward(
                FulfillmentStatus.Fulfilled,
                    redemptionDescription,
                    promotionData,
                    discountAmount,
                    description: $"{discountAmount.ToString("C")} discount applied to order as set by support staff");

            return rewardDescription;
}

The stack trace is as follows:

at EPiServer.Commerce.Marketing.OrderFormPriceMatrix.CalculateAndCommit(AffectedEntries item, Func`3 apply)
at EPiServer.Commerce.Marketing.OrderRewardApplicator.ApplyDiscount(AffectedOrder item, Decimal discountAmount, PromotionProcessorContext processorContext)
at EPiServer.Commerce.Marketing.RewardApplicatorBase`1.<>c__DisplayClass1_0.b__0(TAffectedObject item)
at EPiServer.Commerce.Marketing.RewardApplicatorBase`1.ForEach(Func`2 apply, IEnumerable`1 affectedItems)
at EPiServer.Commerce.Marketing.RewardApplicatorBase`1.Apply(RewardDescription reward, RedemptionDescription redemption, PromotionProcessorContext processorContext)
at EPiServer.Commerce.Marketing.RewardApplicatorBase`1.Apply(RewardDescription reward, Int32 remainingRedemptions, PromotionProcessorContext processorContext)
at EPiServer.Commerce.Marketing.PromotionEngine.Run(IOrderGroup orderGroup, PromotionEngineSettings settings)
at EPiServer.Commerce.Marketing.IPromotionEngineExtensions.Run(IPromotionEngine promotionEngine, IOrderGroup orderGroup)
at AISC.Commerce.Workflow.Activities.CalculateDiscountsVNextActivity.Execute(ActivityExecutionContext executionContext) in C:\w\AISC\AISC.Mediachase.Commerce.Workflow\Activities\OrderGroupActivities\CalculateDiscountsVNextActivity.cs:line 29
at Mediachase.Commerce.WorkflowCompatibility.Activity.Execute()
at Mediachase.Commerce.Engine.ActivityFlowRunner.<>c__DisplayClass15_0`1.b__0()

Looking at the stack trace, CalculateAndCommit takes an AffectedEntries argument, but the RewardDescription we return from Evaluate has a null value for AffectedEntries. It's an Order level promotion though, so I'm not sure if that's expected or not. The AffectedOrder and AffectedObject fields are not null on the RewardDescription.

Any thoughts on this? Could it be a bug I need to make a support ticket for?

#179988
Edited, Jun 27, 2017 16:24
Vote:
 

Hi,

It is not a known bug (at least to me), but I suspect if it was, it's very likely to be fixed in a later version. I would suggest you to try to upgrade to latest version to see if it gets fixed. 

If upgrading is not possible for you - contact our developer support ticket for a workaround. 

#180111
Jun 30, 2017 9:19
Vote:
 

Hi David!

I have the exact same problem did you solve it?

It occours when I run the CartValidate workflow first time after compilation, eg going directly to the basket page after compiling. If I add an item to the cart before going to the basket page and the CartValidate it works just fine.

Any thoughts?

I'm running Commerce 10.7.

Thanks!

/Kristoffer

#181376
Edited, Aug 17, 2017 9:34
Vote:
 

David, anything? Thanks!

#181464
Aug 21, 2017 14:46
Vote:
 

Maybe this helps. I had a simular problem, I accidentally used 'RewardDescription.CreateFreeItemReward' and not 'RewardDescription.CreateGiftItemsReward' in my custom promotion. That caused some weird problems later on, including the NullReference error. 

#181466
Aug 21, 2017 15:56
Vote:
 

Hi Rene!

I'm using the RewardDescription.CreateMoneyReward since it is money I want to create an amount. Maybe there is a problem with that one? Episerver is using RewardDescription.CreateMoneyOrPercentageRewardDescription but I need to manipulate the saved value and the SavedAmount is {get;} only.

@Quan, can I after using RewardDescription.CreateMoneyOrPercentageRewardDescription manipulate the saved amount? Now I do this since it is {get} only:

return RewardDescription.CreateMoneyReward(
                       fulfillmentStatus,
                       new List<RedemptionDescription> { redemptionDescription },
                       promotionData,
                       amount,
                       fulfillmentStatus.GetRewardDescriptionText(_localizationService));

Where amount is my manipulated amount. Should work just fine right?

/Kristoffer

#181479
Aug 22, 2017 9:33
* 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.