1. Commerce Engine policies

The Plugin.Validation.PolicySet

Version:

The Plugin.Validation.PolicySet.json file defines a group of validation policies that the Commerce Engine enforces on some of the configuration input values entered using the Business Tools or via API calls.

The validation policies can apply to Commerce entity properties or to entity components properties.

In the Commerce Engine SDK.*.zip package, you can see the default policy set JSON file provided in the sample Sitecore.Commerce.Engine solution. The path to the default policy set file is:

wwwroot\data\Environments\Plugin.Validation.PolicySet-1.0.0.json

Example validation policies

The following shows an example of the validation policies applied by default to the Customer entity properties:

"$type": "Sitecore.Commerce.Core.ValidationPolicy, Sitecore.Commerce.Core",
        "TypeFullName": "Sitecore.Commerce.Plugin.Customers.Customer",
        "Models": {
          "$type": "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Model, Sitecore.Commerce.Core]], mscorlib",
          "$values": [
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "AccountNumber",
              "MaxLength": 100,
              "MinLength": 1
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "AccountStatus",
              "MaxLength": 100,
              "MinLength": 1
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "LoginName",
              "MaxLength": 100,
              "MinLength": 1
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "Email",
              "MaxLength": 100,
              "MinLength": 1,
              "RegexValidator": "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",
              "RegexValidatorErrorCode": "Customer_EmailValidationError"
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "Password",
              "MaxLength": 100
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "FirstName",
              "MaxLength": 100
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "LastName",
              "MaxLength": 100
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "Language",
              "MaxLength": 100
            }
          ]
        }
      },

Validation policy properties

The Sitecore.Commerce.Core.ValidationAttributes model defines the validation properties that the Commerce Engine supports to define validation policies.

You can use any of these properties to define your custom validation policies.

Note

Some of these properties are not currently used in the default validation policy set.

PropertyDescription
MinLength                                      The minimum number of characters required in a valid property value.
MaxLengthThe maximum number of characters allowed in a valid property value.
MinValueAn integer representing the minimum property value.
MaxValueAn integer representing the maximum property value.
StartDateThe start date in a date range.
EndDateThe end date in a date range.
RegexValidatorThe regular expressions against which to compare a sequences of input characters. For example, the Customer "email" property value is validated against the following regular expression by default: ("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$")
RegexValidatorErrorCodeThe error code corresponding to a defined commerce term value to display as an error message.

For example, the value Customer_EmailValidationError is a pre-defined commerce term that has the following display value: "Email is not valid."
CustomValidatorA custom validator.
If you have suggestions for improving this article, let us know!