Class PromotionEvaluationContext
- java.lang.Object
-
- de.hybris.platform.promotions.result.PromotionEvaluationContext
-
public class PromotionEvaluationContext extends java.lang.ObjectPromotionEvaluationContext.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classPromotionEvaluationContext.ConsumptionLoggerConsumptionlogger keeps track of all consumptions during an evaluation run.
-
Constructor Summary
Constructors Constructor Description PromotionEvaluationContext(AbstractOrder order, boolean observeRestrictions, java.util.Date date)Create an context for evaluating promotions on the given order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabandonLogging(AbstractPromotion promo)Abandon the current logging operation and throw away all of the consumption objects.static java.util.Comparator<PromotionOrderEntry>createPriceComparator(SessionContext ctx)Create a comparator for the current context that orders by price in natural order (lowest to highest).PromotionOrderViewcreateView(SessionContext ctx, AbstractPromotion promotion, java.util.List<Product> validProducts)Create a filtered view of the order containing only the products specified in validProducts.java.util.List<PromotionOrderEntryConsumed>finishLoggingAndGetConsumed(AbstractPromotion promo, boolean removeFromOrder)Complete the logging operation and return a list of all order entry consumptions since logging began.java.util.DategetDate()Get the effective date from the evaluation context.protected PromotionEvaluationContext.ConsumptionLoggergetLogger()Get the consumption logger for this context.booleangetObserveRestrictions()Should restrictions be observed when evaluating promotions.AbstractOrdergetOrder()Get the order that this context is working on.voidstartLoggingConsumed(AbstractPromotion promo)Start recording all of the consumed items in any view.
-
-
-
Constructor Detail
-
PromotionEvaluationContext
public PromotionEvaluationContext(AbstractOrder order, boolean observeRestrictions, java.util.Date date)
Create an context for evaluating promotions on the given order.- Parameters:
order- The order the context is evaluatingobserveRestrictions- Whether restrictions should be observed during evaluationdate- The effective date to use when evaluating promotions
-
-
Method Detail
-
startLoggingConsumed
public void startLoggingConsumed(AbstractPromotion promo)
Start recording all of the consumed items in any view. This will remember any items consumed from any view that currently exist, and any view created.- Parameters:
promo- The promotion requesting the recording
-
finishLoggingAndGetConsumed
public java.util.List<PromotionOrderEntryConsumed> finishLoggingAndGetConsumed(AbstractPromotion promo, boolean removeFromOrder)
Complete the logging operation and return a list of all order entry consumptions since logging began. This operation moves the current set of operations to the LOG of all operations since the context was created.- Parameters:
promo- The promotion requesting to complete the logging operationremoveFromOrder- Consume all the entries marked such that they cannot be used in another promotion- Returns:
- A List of all consumption operations made to any view since logged was started
-
abandonLogging
public void abandonLogging(AbstractPromotion promo)
Abandon the current logging operation and throw away all of the consumption objects.- Parameters:
promo- the promotion
-
getLogger
protected PromotionEvaluationContext.ConsumptionLogger getLogger()
Get the consumption logger for this context. Only used internally by the view system.- Returns:
- The logger
-
getOrder
public AbstractOrder getOrder()
Get the order that this context is working on.- Returns:
- The current order
-
getObserveRestrictions
public boolean getObserveRestrictions()
Should restrictions be observed when evaluating promotions.- Returns:
trueif restrictions should be observed,falseotherwise.
-
createView
public PromotionOrderView createView(SessionContext ctx, AbstractPromotion promotion, java.util.List<Product> validProducts)
Create a filtered view of the order containing only the products specified in validProducts. This view shows the live remaining quantities of items, and is able to determine how many items remain. The view removes consumed items and as such always shows the current available state. The products in the cart and their base products (if variant or composite) are matched against the validProducts list. This allows a variant product in the cart to be matched against its base product in the list of valid products. Variant products extend VariantProduct and composite products implement theCompositeProductinterface.- Parameters:
ctx- The hybris session contextpromotion- The promotion creating the viewvalidProducts- The products that should be included in the view- Returns:
- A filtered view of the order showing only products from the list of valid products
-
getDate
public java.util.Date getDate()
Get the effective date from the evaluation context. The date exists so that the effect of promotions can be seen on dates other than the current system time.- Returns:
- The date that the promotions are being evaluated using
-
createPriceComparator
public static java.util.Comparator<PromotionOrderEntry> createPriceComparator(SessionContext ctx)
Create a comparator for the current context that orders by price in natural order (lowest to highest). The head of a list sorted by this comparator will have the lowest price at index 0 and the highest at index length-1- Parameters:
ctx- The current hybris session context- Returns:
- A comparator to sort PromotionOrderEntry objects by price
-
-