Sitecore 8.2 rev. 161115 (Update-1)
Sitecore Commerce 8.2.1 (Initial Release)
Hi!
We are trying to add a custom qualification to use it in the new promotions. In order to do it, we added a new class to Commerce Engine plugin.
public class ProductBelongsToCategory : ICondition
{
public IRuleValue<bool> ExcludeCategories { get; set; }
public bool Evaluate(IRuleExecutionContext context)
{
return false; // just an example
}
}
We expected that the boolean property will be rendered as a checkbox. However, we received an exception when we tried to use this qualification.
System.FormatException: String was not recognized as a valid Boolean (in class Sitecore.Commerce.UX.Shared.Components.CommerceFoundationFormHelper).
I could find the response of InvokeAction ajax call in the browser which contained following JSON: "..."Name": "ExcludeCategories",\r\n "Policies": [],\r\n "DisplayName": "Exclude?",\r\n "Value": "",...". So, Value property is empty string (I would expect to see there "False"). Also, I tried to set the initial value explicitly. To do this, I added a constructor to the class with a following code:
ExcludeCategories = new LiteralRuleValue<bool>(false);
, but it didn't help.
Questions:
- Is it possible to render checkboxes in qualifications?
- If it is possible - what should we do to achieve the goal?
P.S. It looks like we can replace the code in helper class (CommerceFoundationFormHelper) to handle empty strings and use the new model in the standard view ..\Website\sitecore\shell\client\Commerce\Layouts\Renderings\CommerceFoundationFormHelper\CommerceFoundationFormHelper.cshtml. However, I would like to avoid replacing of the standard Sitecore classes and views.
<!--the model below can be replaced we the custom code-->
@model Sitecore.Commerce.UX.Shared.Components.CommerceFoundationFormHelper
<div @Model.HtmlAttributes>
<div class="sc-commerceForm-formData">
@Model.FormData()
</div>
<div class="sc-commerceForm-formInitializationData">
@Model.FormFieldInitializationData()
</div>
<script type="application/json" class="sc-commerceForm-entityView">
@Html.Raw(Json.Encode(Model.EntityViewResponse))
</script>
</div>
Thank you in advance for the help.