Sequence Diagram

The Promotion Engine sequence diagram displays the simplified sequence of a cart modification through the storefront via commerceservices to the Promotion Engine and Rule Engine including persistence.

Steps

Actions

1-3

A product is added to the cart and the recalculation is triggered. This includes the reevaluation of promotions.

4

  • This step calls the updatePromotions() method. This method is defined in the legacy PromotionService interface.

  • The Promotion Engine also implements this interface, and when active, it overrides the legacy implementation.

  • Therefore, the updatePromotions() call goes to the DefaultPromotionEngineService.

5-6

All promotion results from the last evaluation are undone, which also includes database operations.

7-11

Preparation of the Rule-Aware Objects (RAO), which should be provided as facts to the Rule Engine:

  • Source data, which is the provided CartModel and PromotionGroupModels, needs to be converted into Rule-Aware Objects.

  • The FactContextFactory creates a FactContext for the type <PROMOTION_ORDER>.

  • A Spring configuration for the FactContextType <PROMOTION_ORDER> stores the information, which RAO providers are needed for such a promotion evaluation request.

  • The FactContextFactory has a map that links contexts to a list of RAO providers.

  • In a loop over the RAO providers, all required Rule-Aware Objects are populated based on the data in the source objects. The Converter or Populator pattern is used here.

12-14

  • The Rule Engine, which should be used for the evaluation of promotions, is identified in these steps. It makes no sense to evaluate promotion rules in a rule module, which keeps order management rules.

  • This is where the AbstractRuleEngineContext comes in.

  • The Spring configuration for the DefaultPromotionEngineService also stores the information on which Rule Engine context a promotion evaluation request is processed.

15-16

Now that the facts are populated and the rule module is identified, this data is put into a RuleEvalutionContext object and the RuleEngineService is called for evaluation. The DefaultCommerceRuleEngineService enriches the RuleEvalutionContext with further details.

17-19

The DefaultPlatformRuleEngineService is called, which prepares DroolsSession and DroolsCommand and triggers the Drools Rule Engine.

20-26

  • Drools evaluates the rules.

  • When a rule is fired, it executes an action, which can be applying a discount to the cart or adding a free product.

  • The in-memory ordercalculation is called to recalculate the cart. Based on the result, the CartRAO and other RAOs are updated or created in the working memory.

  • An appropriate ActionRAO is added to the list in the ResultRAO.

  • When all rules are evaluated, the relevant RAOs are retrieved from the working memory and returned in a RuleEvaluationResult.

27-28

  • Nothing is persisted yet, there is only a list of ActionRAO. This list can be displayed, if there is some simulation mode.

  • In promotions, the results are then persisted, which may include creating DiscountValues, creating CartEntryModels, changing the shipment code, creating promotion results, or anything that was decided by the Rule Engine.

  • A strategy is mapped to each ActionRAO and determines the step to be done for its mapped ActionRAO.

  • These strategies are Java classes that ensures results from the Rule Engine are persisted and are only displayed in some front-end or any other required processing.

  • The use of the results from the Rule Engine depends on the strategy. The same ActionRAO may have a different processing in different modules. For example, the DisplayMessageRAO is used to create and display potential promotions in the Promotion Engine. But a different rule module may use this message to put it into an e-mail and send it to a customer.

  • When all ActionRAO are processed and applied by the strategies, the cart is calculated.

29-30

All promotion results are persisted in the same way as it was done for the legacy promotions. The results from the Promotion Engine are compatible with commercefacades, commerceservices, and the Accelerator extensions.