Data Model

This diagram displays the data model for the Promotion Engine and Rule Engine.

Overview

This diagram displays three layers - SAP Commerce Cloud platform, Promotion Engine and Rule Engine. In this diagram, you can see color-coded boxes that correspond to (1) Data Model, (2) Data (Impex) that represent sample data being used, (3) API, and (4) some Backoffice elements.

The first layer represents SAP Commerce Cloud platform, which serves as the building block of the modules.

The second layer consists of Rule Engine, which is split into two categories - Commerce Rule Engine and Drools Rule Engine. Each particular category contains its own Data Model, Data (ImpEx), API, and Backoffice modules.

Commerce Rule Engine runs on top of Drools Rule Engine. This layer introduces Commerce-related data and functionality to Backoffice to create the Rule Builder, which is the user interface to create custom rules.

The following tables provide a list of the components with corresponding descriptions of Drools Rule Engine and Commerce Rule Engine:

Drools Rule Engine

Component

Description

DroolsRule

The item type that defines the Drools Rule.

Platform RuleEngine Service

The API that operates on top of the DroolsRule and overlaps the underlying Drools API.

Rule Engine Backoffice

The basic functionality to create, compile, and reload the Drools Rule on the Backoffice.

Commerce Rule Engine

Component

Description

SourceRule and SourceRule Template

The item types that define the Rule Builder.

Rule Builder Conditions and Actions

Business Object Data in the Commerce Rule Engine.

Rule-Aware Objects with Actions

The API that represents the Actions and Conditions, and the executable Actions, which are results of different Rules.

Rule Compiler

The API that extracts data from the SourceRule and compiles Conditions and Actions using the DroolsRule.

Commerce RuleEngine Service

The API that triggers the Platform RuleEngine Service.

Rule Builder Backoffice

Contains the custom user interface to create rules.

Promotion Engine, which runs on top of Rule Engine, introduces all the promotion-specific components.

Promotion Engine
Component

Description

PromotionSource Rule and PromotionSource Template

The item types that define promotion-specific data.

Promotions and Templates

Include out-of-the-box Promotions and Templates data.

Strategy Implementation for Actions

The API that implements all strategies such as discounts, free gifts, free delivery, and so on.

Promotion Service

The API that is triggered on the shopping cart when the promotions are activated.

Promotion Engine Backoffice

Uses the Rule Builder Backoffice and Rule Engine Backoffice and includes Promotion-specific Backoffice functionality.

Each layer in this diagram is extensible. For example, you can extend the Drools Rule Engine without using the Commerce Rule Engine. To learn more about the extensibility guide, refer to Promotion Engine Trail.

Data Model

For a deeper understanding of how data connects to others and how data is processed, refer to the diagrams:

promotionengineservices

PromotionSourceRule extends SourceRule, PromotionSourceRuleTemplate extends SourceRuleTemplate

The Promotion-specific subtypes used as attributes such as website, which corresponds to the legacy PromotionGroup, are not useful outside of promotions.

RuleBasedPromotion extends AbstractPromotion

For compatibility reasons with commercefacades and other extensions, it is necessary to create subtype of AbstractPromotion. This RuleBasedPromotion is automatically generated by an interceptor whenever a DroolsRule for promotions is created. The RuleBasedPromotion does not store required data except the firedMessage and is linked to the AbstractRuleEngineRule, which actually keeps all the logic for conditions, actions, priority, and so on.

AbstractRuleBasedPromotionAction extends AbstractPromotionActionModel

This item type and its subtypes are also required for compatibility reasons, but these also store data for the applied actions, which are necessary for undoing promotions during clean-up. For example, the RuleBasedOrderChangeDeliveryModeAction remembers the original shipment mode that is restored in case the promotion is undone.

ruleengine

AbstractRuleEngineRule

Refers to the abstract item type for engine rules.

AbstractRulesModule

Refers to the abstract item type for rule modules. A rule module is a container for rules.

AbstractRuleEngineContext

Refers to the abstract item type for rule engine contexts.

These abstract types are unaware of the underlying rule engine, and define common attributes. Since Drools is used as rule engine, these abstract item types need a concrete implementation, which is specific to Drools.

DroolsRule extends AbstractRuleEngineRule

The abstract type defines common attributes such <code> or <active>, whereas DroolsRule adds Drools-specific attributes such as <globals>. A different rule engine creates its own subtype with specific attributes.

DroolsKIEModule extends AbstractRulesModule

Drools does not use the module as container for rules. A Drools module has knowledge bases, which keep the rules (DroolsKIEBase). A Drools module can have multiple knowledge bases.

DroolsKIEBase

In Drools, the knowledge base is the container for rules. It has a one-to-many relation to DroolsRule.

DroolsKIESession

Defines if the rules are executed in a Stateful or Stateless session (DroolsSessionType). Promotion rule evaluations use stateless sessions, as keeping the working memory of a stateful session up-to-date is close to impossible for carts and promotions. A small change in the cart can cause too many changes with respect to promotions.

DroolsRuleEngineContext extends AbstractRuleEngineContext

It is used to determine in which rule module and knowledge base the rules should be evaluated. For example, the PromotionEngineService is configured (via Spring) to use the rule engine context for promotions for rule evaluation.

RuleType

This enumeration type is associated with AbstractRuleEngineRule and AbstractRulesModule. Validations make sure the only the <ruleType> of the rule and the module fit together. It is also used by the rule deployment process to find the correct module for a rule.

CatalogVersionToRuleEngineContextMapping

This maps catalog versions to rule engine contexts. If there are more than one rule modules for the same use case (for example, the rule modules "promotions-module" and "promotions-preview-module" for the use case promotions), it is necessary to determine during runtime which rule module should be used for the rule evaluation. Based on the catalog versions in the cart or in the session, the mapping table is used to find the correct rule module.

ruleengineservices

SourceRule extends AbstractRule

It stores the rule details such as <startDate> and <endDate> or conditions actions in a generic, rule engine independent way. These rule details are then translated and compiled into a rule engine-specific format, for example into a DroolsRule.

SourceRuleTemplate extends AbstractRuleTemplate

It can be used as a starting point for a new SourceRule.

RuleConditionDefinition, RuleConditionDefinitionParameter, RuleConditionDefinitionCategory, RuleActionDefinition, RuleActionDefinitionParameter, RuleActionDefinitionCategory

These item types provide a data model to define generic rule conditions and actions. For example, there is a condition that compares the cart total against a certain value. You would define the condition <cart.total> in the item type RuleConditionDefinition and the three required parameters for <operator>, <value>, and <currency> in the related item type RuleConditionDefinitionParameter. If this condition definition is finally used to compose a SourceRule (for example in the RuleBuilder), this condition definition would be populated with concrete values for the parameters and then be part of the concrete conditions of a SourceRule.

RuleToEngineRuleTypeMapping

This maps the sub-type of a SourceRule to the RuleType (for example, PromotionSourceRule to RuleType "PROMOTION"). The mapping is used to find out the RuleType of the DroolsRule when a SourceRule is compiled and which DroolsKIEModules are allowed as target environment for a SourceRule.