Sitecore Experience Commerce 9: Configure Policies Like a Boss with Policy Sets

When configuring an environment in Sitecore Experience Commerce 9, you can specify policies (learn more about policies and entities here). In addition to specifying a list of policies directly in the environment JSON config, you can also specify a set of policies that make up a single policy. This is defined using something called a policy set.

What?

An example of a policy set is the BraintreePolicySet that is defined in the example Habitat Commerce Authoring environment configuration JSON:

In order to define a policy set, it must be of type Sitecore.Commerce.Core.PolicySetPolicy and a PolicySetId must be specified in order to identify it in the entity store. In this Habitat example, the policy set is defined in PlugIn.Payments.Braintree.PolicySet-1.0.0.json:

Why?

This approach allows you to isolate sets of policies based on a logical group into a separate entity. When this environment is bootstrapped in Sitecore Commerce, you will see separate entity records in the Commerce Global database for the environment itself and the individual policy sets. This approach has the following advantages:

Single entity to manage a specific set of policies.

Allows you to re-use and share policies across multiple environments by simply referencing the same policy set in the relevant environment JSON configurations.

Allows you to update a specific policy set independently without touching the main environment configuration JSON. This can mitigate accidental errors.