Discount Validation
As outlined in the Discounts & Offers article, all discounts have a setting called Check for validation reason. If this is checked, the discount is added to a loop, which can then be used in frontend to show why the discount was not applied.
This has two uses:
- It is an excellent debug tool when setting up discounts – it makes it easy to see why a discount which you believe should apply is not applied
- It makes it possible to show customers what they need to do in order to qualify for a discount, e.g. Buy for $987 more and get 5% OFF
A (very ugly) implementation of a debug section could look like this:
The section above is rendered using the following code example:
RAZOR
<!--Discount Validation-->
<div class="panel panel-default col-md-12">
<h3>Discount Validation</h3>
<p>The following order discounts are not applied to this order:</p>
<ul>
@foreach (var discount in GetLoop("DiscountValidationResults"))
{
<li><b>@discount.GetString("Ecom:DiscountValidationResult.Name")</b></li>
<ul>
<li><b>Type:</b> @discount.GetString("Ecom:DiscountValidationResult.Type")</li>
<li><b>Description:</b> @discount.GetString("Ecom:DiscountValidationResult.Description")</li>
<li><b>Class:</b> @discount.GetString("Ecom:DiscountValidationResult.Discount.Class")</li>
<li><b>Not applied because:</b></li>
<ul>
@foreach (var reason in discount.GetLoop("DiscountValidationReasons"))
{
<li>@reason.GetString("Ecom:DiscountValidationReason.SystemReasonDescription")</li>
}
</ul>
</ul>
}
</ul>
</div>