A frequent question I’m asked is “Why isn’t my discount applying?” The best way to troubleshoot a discount issue is to use pipeline logging in conjunction with the tracing feature of the OrderDiscount component. Remember that you should only use this for troubleshooting, preferably on a test system as logging and tracing will slow down your site.
There are many issues that could prevent a discount from applying including date ranges of the campaign item, active status (approval status), interactions with other discounts, and expressions not evaluating as expected.
First, turn on pipeline logging for the basket pipeline by editing the pipelines section of your web.config:
Next, set the “_Trace_Discounts” key in the pipeline context dictionary (or PipelineInfo["_trace_discounts"] =1;) before executing the basket pipeline. If you are using the StarterSite, you’ll need to edit the code for CommerceComponents.dll. In ControlLibrary\Helpers\BasketHelper.cs the RunPipeline() function:
private PipelineExecutionResult RunPipeline(string pipelineName, OrderPipelineType type)
using (PipelineInfo pipeline = new PipelineInfo(pipelineName, type))
pipeline["_trace_discounts"] = 1;
Now when the basket pipeline runs, it will output a trace of the discount algorithm in the “_discounts_trace_info” key.
So browse to the site and checkout a basket that qualifies for the discount you’re troubleshooting. Now open the pipeline log (it should be under your pipeline files, C:\Inetpub\wwwroot\StarterSite\pipelines\log, make sure your IIS worker process has permission to write here) to see trace information for each discount that is loaded into the runtime cache and the expressions that were evaluated, etc. It should look something like:
RootObject: WriteValue _discounts_trace_info VT_NULL __null__ VT_BSTR Discount tracing session started at: 1/19/2007 1:53:06 PM
Total number of discounts: 3
Basket contains: 1 lines
No TargetingProfiles dictionary. Using legacy userprofile and contextprofile keys.
No context profile.
No user profile.
0. Id = 1
BUY 1.00(q), CondExprId=1; GET 1 at 100.00(%), AwardExprId=1 ; OL=0, Djoint=-1, CC=0, CA=0, AC=0, AA=0
1. Id = 5
BUY 1.00(q), CondExprId=0; GET 1 at 20.00(%), AwardExprId=2 ; OL=0, Djoint=0, CC=0, CA=0, AC=0, AA=0
2. Id = 8
BUY 40.00($), CondExprId=0; GET 1 at 100.00(%), AwardExprId=0 ; OL=-1, Djoint=0, CC=0, CA=0, AC=0, AA=0
Basket line 0; Disc 1; Condition Expression 1 = true
Basket line 0; Disc 1; Award Expression 1 = true
Basket line 0; Disc 5; Award Expression 2 = false
Running engine for discount Id = 1
Discount_Id=1: Basket lines sorted for conditions
0: Basket line index 0
Discount_Id=1: Basket lines sorted for awards
Discount Id = 1 is a winner.
Running engine for discount Id = 5
Discount_Id=5: Basket lines sorted for conditions
Discount_Id=5: Basket lines sorted for awards
Discount Id = 5 is not a winner.
Running engine for discount Id = 8
Discount_Id=8: Basket lines sorted for conditions
Discount_Id=8: Basket lines sorted for awards
Discount Id = 8 is not a winner.
Now you should have enough information to figure out why the wrong discount was given, an eligibility requirement wasn’t met, or whatever else is keeping your discount from applying.
If your discount isn’t in the "Sorted discounts" part of the trace, it means that it is not currently active. Double check that:
· The discount is not deleted
· The discount is active (approved)
· The parent campaign is active (approved)
· The current date is between the discount’s StartDate and EndDate