1

I want to learn which promotions were applied to which products on promotionengine in order to distribute prices on products amongst themselves and send them to ERP.

When we look at the promotionService in Hybris, there is a method called getPromotionResults(order). It returns PromotionOrderResults object. In this object, two methods are related to my case, getAppliedProductPromotions() and getAppliedOrderPromotions(). If I did not miss it, I could not see product info for a promotion in these methods' results. Also, I looked at all attributes via promotion.getAppliedOrderPromotions().get(0).getAllAttributes() but i could not have them.

How can I know product info and discount amount in a promotion?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Hatip Kabak
  • 316
  • 2
  • 22

2 Answers2

0

The method you are looking for is

PromotionOrderResults#getAppliedProductPromotions()

This will return all the promotions applied to order entries / products, you can navigate to the products via PromotionOrderEntryConsumed PromotionResult#getConsumedEntries()

Sukram
  • 381
  • 2
  • 6
  • I have a target bundle promotion and describe 4 containers which have their own products in conditions. In addition to that, I describe an action which contains a specific price for the order including one product from each container. I could not reach consumed entries in calculationService. For the sake of giving an example, "order.getAllPromotionResults().iterator().next().getConsumedEntries()" results in empty list. I use Hybris v6.4. – Hatip Kabak Sep 19 '18 at 13:59
  • I saw a link https://www.elision.eu/the-new-features-in-sap-hybris-commerce-6-7/ . When you look at it, you see "Consumption and availability of order entry items for promotion". Is there any option to get products affected by the promotion in calculationService during place order? – Hatip Kabak Sep 19 '18 at 14:00
0

I have a way to get the product that was Added as free gift on a promotion... Usually is something like this

Set promotionResultModels = cart.getAllPromotionResults();
 
  if (!Objects.isNull(promotionResultModels))
  {
     Iterator resultsIterator = promotionResultModels.iterator();

     while (resultsIterator.hasNext())
     {
        PromotionResultModel promoResultModel = (PromotionResultModel) resultsIterator.next();
        Iterator var6 = promoResultModel.getActions().iterator();

        while (var6.hasNext())
        {
           AbstractPromotionActionModel action = (AbstractPromotionActionModel) var6.next();
           if (action instanceof RuleBasedOrderAddProductActionModel)
           {
              String freeGiftProductCode = ((RuleBasedOrderAddProductActionModel) action).getProduct().getCode();

           }
        }
     }
  }

However in my scenario, this is Free Gift promotion, not sure if the Bundle Based Promotion might have similar properties. As per the product that actually FIRED the promotion, I'm still looking a way to get it. The closest I've been is with this:

((RuleBasedOrderAddProductActionModel) action).getRule().getRuleContent()

However that's the Hybris Generated Code that has the RAO's and the product codes are buried within that string. So I needed to write an ugly script parser to find the codes.

Let me know if you find out the second part, the Products that triggered the promos, I'm still looking for it too.

David Espino
  • 2,177
  • 14
  • 21