What is Promotion evaluation and partially activated promotion in Hybris ?

So Guys,
In every of my Hybris interview I face question related to Promotion, so today let’s start with some of them.

What is Promotion evaluation and partially activated promotion ?

Let’s you have a promotion "Buy 4 get 1 free" means when you buy 4 quantity then you will get 1 free item of same

So there will start evaluate promotion against a shopping cart and order then question will what will evaluate, it could be below

1. Evaluate which of the available promotions have been activated or "fired".
2. Evaluate which of the available promotions have been partially activated or "could fire".

So above both mode of evaluation is performing by Promotion extension.
So from above if User has added 4 quantities then there promotion action will fire i.e. means promotion activated

But suppose user has added 3 products not 4 then it means he very short from to get promotion means if he buy 1 more then he can get promotion. Then this condition called “could fire promotion” i.e. partially activated promotion

So In above case Hybris do associate a single item to this and communicated to customers on a website. For instance, a message such as "Add another item to your basket and 1 free in your order" could be displayed.

Technical:

If you look in Promotion logic (In jalo class) where you will find that below method
public List<PromotionResult> evaluate(final SessionContext ctx, final PromotionEvaluationContext promoContext)
       {
}

Activated Promotion:
       // Create a view of the order containing only the allowed products
                     final PromotionOrderView orderView = promoContext.createView(ctx, this, restrictResult.getAllowedProducts());
                     if (orderView.getTotalQuantity(ctx) >= qualifyingCount)
                     {
                           final long eligibleCountForPromotion = orderView.getTotalQuantity(ctx) / qualifyingCount;
                           final long nonEligibleCount = orderView.getTotalQuantity(ctx) % qualifyingCount;
                           final long totalFreeCount = freeCount * eligibleCountForPromotion;
                           // Begin logging of promotions consuming order entries
                           promoContext.startLoggingConsumed(this);
                           // Get a price comparator
                           final Comparator<PromotionOrderEntry> comparator = PromotionEvaluationContext.createPriceComparator(ctx);
                           // Consume high priced items as these are the ones that will be paid for
                           orderView.consumeFromTail(ctx, comparator, (orderView.getTotalQuantity(ctx) - (totalFreeCount + nonEligibleCount)));
                           // Consume the free items from the cheap end of the list, as these result in the lowest discount
                           final List<PromotionOrderEntryConsumed> freeItems = orderView.consumeFromHead(ctx, comparator, totalFreeCount);
                           // Create the actions to take for this promotion to fire.  In this case an entry level discount is created
                            // for each of the free items.
                           final List<AbstractPromotionAction> actions = new ArrayList<AbstractPromotionAction>();
                           for (final PromotionOrderEntryConsumed poec : freeItems)
                           {
                                  // Set the adjusted unit price to zero, these are free items
                                  poec.setAdjustedUnitPrice(ctx, 0D);
                                  final double adjustment = poec.getEntryPrice(ctx) * -1.0D;
                                  // This action creates an order entry discount.
                                  actions.add(PromotionsManager.getInstance().createPromotionOrderEntryAdjustAction(ctx, poec.getOrderEntry(ctx),
                                                adjustment));
                           }
                           // Put together a the result for this iteration.
                           final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx, this,
                                         promoContext.getOrder(), 1.0F);
                           // Get a list of all the order entries that were consumed during this run
                           final List<PromotionOrderEntryConsumed> consumed = promoContext.finishLoggingAndGetConsumed(this, true);
                           result.setConsumedEntries(ctx, consumed);
                           // Add the actions that this promotion has produced
                           result.setActions(ctx, actions);
                           // Add the result object to the list of results
                           results.add(result);
                     }





Partially activated promotion:

// Check to see if there are still some qualifying products in the basket
                     final long remainingCount = orderView.getTotalQuantity(ctx);
                     if (orderView.getTotalQuantity(ctx) > 0)
                     {
                           // Start logging the products we could take
                           promoContext.startLoggingConsumed(this);

                           // Consume the products passing false the removeFromOrder.  This means that we noted which products
                           // *could* cause us to fire, but are not actually removing them from the context.
                           orderView.consume(ctx, remainingCount);

                           // The certainty for this is calculated as a percentage based on the qualifying items available versus
                           // the number needed to make this promotion fire.
                           final float certainty = (float) remainingCount / (float) qualifyingCount;

                           // Create the promotion result
                           final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx, this,
                                         promoContext.getOrder(), certainty);

                           // Fill in the entries we could have consumed
                           result.setConsumedEntries(promoContext.finishLoggingAndGetConsumed(this, false));

                           // Add the result to the list of results
                           results.add(result);
                     }



So in partially activated promotion, still Promotion Results (promotion action) return with message “”.


No comments:

Post a Comment