A note from 2026: This article was published in 2016. SAP hybris has since been rebranded as SAP Commerce Cloud, and the promotion engine APIs and storefront integration points have changed across releases. Treat the code as a Hybris 6.0 proof of concept and validate it against your current SAP Commerce Cloud version.

Situation

A “could have fired” message indicates that the promotion criteria have been partially fulfilled. For example, when you have two products in your cart and a promotion for three products, such as “buy 3, get 1 free,” the “could have fired” message could look like “buy one more product and get one free.”

SAP hybris 6.0 uses a new rule-based promotion engine that is faster and more flexible. However, because of the completely new paradigm, some capabilities that we had in previous versions of hybris are not present in hybris 6. One of them is “could have fired” messages.

In the new version, for this purpose you need to use fake promotions. This means that, for the example above, you need to create two promotions: one for a set of three products and another for a set of two products. When fired, the second promotion should show the “could have fired” message.

For some cases, this approach is quite flexible. For example, you can configure “could have fired” messages for products that are similar to the promotional product. This is a really strong point.

However, it is manual work. It is difficult to cover all the cases when a “could have fired” message could be shown. The “could have fired” promotions are difficult to manage and support.

Complexity

The new rule-based promotion engine is only integrated into the cart. Product pages, product lists, and search results will not use it at all.

Drools, the core of the hybris 6 promotion engine, is designed for a broad range of tasks. SAP hybris pushes data into Drools and receives a set of actions. There is no such thing as detecting “partially fired rules.”

Challenge

Create a proof-of-concept prototype with smart “could have fired” messages. The idea is to show tips on product pages, such as:

Solution

The product page controller evaluates promotions against the customer’s cart plus the current product. Then the results are compared with the ones from the shopping cart. Added actions are displayed as “could have fired” messages.

The caveat is in the promotion engine interfaces. For some reason, the classes don’t expose all the data available in the backoffice. Some methods and attributes that are used by hybris are not available to developers.

Video

In the video below, the following process is shown:

Promotion proof-of-concept screenshot 1

Promotion proof-of-concept screenshot 2

The second part is a bit more complicated:

Promotion proof-of-concept screenshot 3

Technical details

final CartModel existingCart = cartService.getSessionCart();
final CartModel virtualCart = modelService.create(CartModel.class);
cloneCart(existingCart, virtualCart);
final ProductModel product = productService.getProductForCode(productCode);
addProductToCart(virtualCart, product)

...
RuleEvaluationResult ruleEvaluationResultWithoutNewProduct =
promotionEngineService.evaluate(virtualCart, getPromotionGroups());
RuleEvaluationResult ruleEvaluationResult =
promotionEngineService.evaluate(existingCart, getPromotionGroups());
...
Iterator < AbstractRuleActionRAO > next6 = ruleEvaluationResult.getResult().getActions().iterator();
while (next6.hasNext()) {
AbstractRuleActionRAO actionRAO = next6.next();
if (actionRAO instanceof DiscountRAO) {
BigDecimal discountValue = ((DiscountRAO) actionRAO).getValue();
if (ruleEvaluationResultWithoutNewProduct.getResult() != null) {
Iterator < AbstractRuleActionRAO > next7 = ruleEvaluationResultWithoutNewProduct.getResult().getActions().iterator();
...
}
}
...
}

Any questions?

Contact me privately using the form below or leave your comment to this article:

© Rauf Aliev, June 2016