The Plugin.Validation.PolicySet
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
Plugin.Validation.PolicySet.jsonファイルは、Business ToolsまたはAPI呼び出しを通じて入力された構成値に対してCommerce Engineが強制する検証ポリシーのグループを定義しています。
検証ポリシーは、Commerceエンティティプロパティまたはエンティティコンポーネントプロパティに適用されます。
Commerce Engine SDK.*.zipパッケージでは、サンプルSitecore.Commerce.Engineソリューションで提供されているデフォルトのポリシーセットJSONファイルを見ることができます。デフォルトのポリシーセットファイルへのパスは以下の通りです:
wwwroot\data\Environments\Plugin.Validation.PolicySet-1.0.0.json
検証ポリシーの例
以下は、Customer entityプロパティにデフォルトで適用される検証ポリシーの例を示しています:
"$type": "Sitecore.Commerce.Core.ValidationPolicy, Sitecore.Commerce.Core", "TypeFullName": "Sitecore.Commerce.Plugin.Customers.Customer", "Models": { "$type": "System.Collections.Generic.List`1Sitecore.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 }
} },
検証ポリシーの特性
Sitecore.Commerce.Core.ValidationAttributesモデルは、Commerce Engineが検証ポリシーを定義するためにサポートする検証プロパティを定義します。
これらのプロパティのいずれかを使って カスタム検証ポリシーを定義できます。
!注これらのプロパティの一部は、現在デフォルトの検証ポリシーセットで使用されていません。
財産
概要
MinLength
有効なプロパティ値に必要な最小文字数。
MaxLength
有効なプロパティ値で許される最大文字数。
MinValue
これは最低財産価値を表す整数です。
MaxValue
これは最大の財産価値を表す整数です。
StartDate
開始日はある日程内です。
EndDate
日付範囲内の終了日。
RegexValidator
入力文字の列を比較するための正則表現です。例えば、Customer "email" プロパティ値はデフォルトで以下の正規表現に対して検証されます:("^\\w-\\.+@(\\w-+\\.)+\\w-{2,4}$")
RegexValidatorErrorCode
定義された商取引用語の値に対応するエラーコードがエラーメッセージとして表示されます。
Customer_EmailValidationErrorはあらかじめ定義された商取引用語で、「メールは有効でない」という表示値を持ちます。
CustomValidator
カスタムバリデーターです。