0

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:

  1. Is it possible to render checkboxes in qualifications?
  2. 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.

1 Answer 1

1

IRuleValue doesn’t support ‘bool’ data type.

This blogs might help: https://sitecoresmurf.wordpress.com/2019/05/01/create-custom-promotion-benefit-action-with-sitecore-commerce-9/

https://sitecoresmurf.wordpress.com/2019/07/18/known-issues-limitations-and-extending-promotion-plugin-in-sitecore-commerce-9/

3
  • Thank you, @Milena.
    – Max
    Commented Nov 9, 2020 at 10:53
  • @milena please add more details here, these blogs can be deleted or moved. Try to follow this - stackoverflow.com/help/how-to-answer Commented Nov 9, 2020 at 15:27
  • @GauravAgarwal sorry, don't know to answer in more detail, didn't have this problem, came across these blogs that are hopefully pointing in the right direction.
    – Milena
    Commented Nov 10, 2020 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.