Class PromotionEvaluationContext
java.lang.Object
de.hybris.platform.promotions.result.PromotionEvaluationContext
PromotionEvaluationContext.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classConsumptionlogger keeps track of all consumptions during an evaluation run. -
Constructor Summary
ConstructorsConstructorDescriptionPromotionEvaluationContext(AbstractOrder order, boolean observeRestrictions, Date date) Create an context for evaluating promotions on the given order. -
Method Summary
Modifier and TypeMethodDescriptionvoidabandonLogging(AbstractPromotion promo) Abandon the current logging operation and throw away all of the consumption objects.static Comparator<PromotionOrderEntry>Create a comparator for the current context that orders by price in natural order (lowest to highest).createView(SessionContext ctx, AbstractPromotion promotion, List<Product> validProducts) Create a filtered view of the order containing only the products specified in validProducts.finishLoggingAndGetConsumed(AbstractPromotion promo, boolean removeFromOrder) Complete the logging operation and return a list of all order entry consumptions since logging began.getDate()Get the effective date from the evaluation context.Get the consumption logger for this context.booleanShould restrictions be observed when evaluating promotions.getOrder()Get the order that this context is working on.voidStart recording all of the consumed items in any view.
-
Constructor Details
-
PromotionEvaluationContext
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 Details
-
startLoggingConsumed
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 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
Abandon the current logging operation and throw away all of the consumption objects.- Parameters:
promo- the promotion
-
getLogger
Get the consumption logger for this context. Only used internally by the view system.- Returns:
- The logger
-
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, 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
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
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
-