November Happy Hour will be moved to Thursday December 5th.

Visitor Groups Criterion EnumSelectionFactory Values Not Populating

Vote:
 

Hi,

I'm  trying to create a custom criterion where one of the values is a dropdown using the Visitor Groups EnumSelectionFactory, but am unable to get any of the values to populate in the dropdown.

I've followed the documentation here and here, but haven't had any luck. Any ideas where the issue could be?

Code below:

CriterionModel

using System.ComponentModel.DataAnnotations;

using EPiServer.Personalization.VisitorGroups;
using EPiServer.Web.Mvc.VisitorGroups;


public class CookieExistsCriterionModel : CriterionModelBase
    {
        [Required]
        public string CookieName { get; set; }

        public string CookieValue { get; set; }

        [DojoWidget(
            WidgetType = "dijit.form.FilteringSelect",
            SelectionFactoryType = typeof(EnumSelectionFactory),
            AdditionalOptions = "{ selectOnClick: true }")]
        public StringComparisonType Comparison { get; set; }

        public override ICriterionModel Copy()
        {
            return ShallowCopy();
        }
    }

Criterion

[VisitorGroupCriterion(
        Category = "Site Criteria",
        DisplayName = "Cookie Exists",
        Description = "Checks if a specific cookie exists",
        LanguagePath = "/enums/client/clientsite/commerce/site/infratructure/enums/stringcomparisontype/"
       )]
    public class CookieExistsCriterion : CriterionBase<CookieExistsCriterionModel>
    {
        public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
        {
            return httpContext.Request.Cookies[Model.CookieName] != null;
        }

        //Comparison Logic
    }

Enums.xml

<?xml version="1.0" encoding="utf-8" ?>
<languages>
  <language name="English" id="en">
    <enums>
      <client>
        <clientsite>
          <commerce>
            <site>
              <infrastrcture>
                <enums>
                  <stringcomparisontype>
                    <none>None</none>
                    <equals>Equals</equals>
                    <contains>Contains</contains>
                    <startswith>Starts With</startswith>
                    <endswith>Ends With</endswith>
                    <regexmatch>Regex Match</regexmatch>
                  </stringcomparisontype>
                </enums>
              </infrastrcture>
            </site>
          </commerce>
        </clientsite>
      </client>
    </enums>
  </language>
</languages>

Thank you.

#256951
Jun 22, 2021 21:11
Vote:
 

I use an enum as a criteria here: https://github.com/davidknipe/CookieVisitorGroupCriteria/blob/master/CookieVisitorGroupCriteria/Models/CookieValueCriterionModel.cs#L23

May be worth comparing? Things that jump out are that I don't define the widget type, I think the UI works it out. 

David

#257001
Jun 23, 2021 18:26
Justin Z. - Jun 24, 2021 18:27
Thanks for your code. While I was trying to understand your xml and LanguagePath attribute, I finally noticed the spelling mistake in my xml file.
Vote:
 

Weirdly enough it looks like you are trying to build a criterion for cookies? If so my package may do what you want?

https://nuget.episerver.com/package/?id=CookieVisitorGroupCriteria

If anything is missing based on your requirements I'd be happy to accept a PR get it added to the Nuget feed and attribute you as a collaborator :)

#257002
Jun 23, 2021 18:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.