Sitecore Commerce Entities Explained
In a nutshell, an entity in Sitecore Commerce is a business concept that is encapsulated in a POCO class that inherits from the Commerce Entity base class, and is persisted with a unique identifier associated to it.
As an example, have a look at the default Commerce Cart Entity:
Persistence
Commerce entities are serialized into JSON and stored in a persistent store such as SQL Server. The Commerce EntityStore persists and retrieves entities.
Tip: You can inspect persisted entities in the CommerceEntities table in the Sitecore Commerce SharedEnvironments database.
Commerce Entity Properties
Along with other information such as a unique Id, an entity also has list of Components and Policies. This allows the Entity to be extended by either composition or policies.
Extension by composition
Entities can be extended by adding components to the Components property on the entity. Components are simply classes that are injected into the entity by a plugin through a Pipeline Block (more on how to create custom plugins in a separate post). A good thing about this pattern is that it allows us to inject components into an entity without interfering with components injected by other plugins.
Extension by policy
Entities can also be extended by adding Policies. A policy is basically a set of rules for an entity. It is a class that defines a set of data that can be used by business processes to determine behavior. E.g. you could define a policy for the cart entity that sets the maximum cart value or the maximum number of line items. In essence, policies are code based configuration settings.
Stay tuned and hit the follow button- in future posts I will show you how to create custom plugins and define policies.