Class PromotionsManager
- java.lang.Object
-
- de.hybris.platform.jalo.Manager
-
- de.hybris.platform.jalo.extension.Extension
-
- de.hybris.platform.promotions.jalo.GeneratedPromotionsManager
-
- de.hybris.platform.promotions.jalo.PromotionsManager
-
- All Implemented Interfaces:
ItemLifecycleListener,java.io.Serializable
- Direct Known Subclasses:
CachingPromotionsManager
public class PromotionsManager extends GeneratedPromotionsManager
The manager for the Promotions extension. Manages applying promotions to carts and orders.- Use the
updatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder)methods to evaluate the promotions that can be applied to a cart or order. - Use the
getPromotionResults(de.hybris.platform.jalo.order.AbstractOrder)methods to retrieve the promotions calculated for an order. - Use the
getProductPromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.product.Product)methods to retrieve the promotions that aProductcan be part of. - The promotions extension stores additional database items for the cart and order items. When a cart is removed
from the system it is necessary to call the
cleanupCart(de.hybris.platform.jalo.order.Cart)method to removed these items.
- See Also:
getProductPromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.product.Product),updatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(de.hybris.platform.jalo.order.AbstractOrder), Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPromotionsManager.AutoApplyModeWhich changes should the promotions manager apply to an order automatically.static classPromotionsManager.RestrictionSetResultClass representing the result of evaluating a set of restrictions.-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.extension.Extension
Extension.RestrictedLanguagesProvider, Extension.RightsProvider
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.Manager
Manager.GenericManagerSingletonCreator, Manager.ManagerSingletonCreator
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.promotions.jalo.GeneratedPromotionsManager
CATEGORYPROMOTIONRELATION_MARKMODIFIED, CATEGORYPROMOTIONRELATION_SRC_ORDERED, CATEGORYPROMOTIONRELATION_TGT_ORDERED, DEFAULT_INITIAL_ATTRIBUTES, ORDER2PROMOTIONRESULTSRELATIONALLPROMOTIONRESULTSHANDLER, PRODUCTPROMOTIONRELATION_MARKMODIFIED, PRODUCTPROMOTIONRELATION_SRC_ORDERED, PRODUCTPROMOTIONRELATION_TGT_ORDERED
-
-
Constructor Summary
Constructors Constructor Description PromotionsManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanautoApplyApplies(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotion promotion)protected java.lang.StringbuildQueryForDistinctProductPromotionQuery(Product product, SessionContext ctx, java.util.Map<java.lang.String,java.lang.Object> args)voidcleanupCart(Cart cart)Delete the the stored promotion results for a Cart.voidcleanupCart(SessionContext ctx, Cart cart)Delete the the stored promotion results for a Cart.voidcleanupOrphanedResults()Delete any promotion results that are orphaned.voidcleanupOrphanedResults(SessionContext ctx)Delete any promotion results that are orphaned.voidcreateEssentialData(java.util.Map params, JspContext jspc)Implement this method to create initial objects.PromotionGroupcreatePromotionGroup(SessionContext ctx, java.lang.String identifier)Create a newPromotionGroupinstance.PromotionNullActioncreatePromotionNullAction(SessionContext ctx)Create a newPromotionNullActioninstance.PromotionOrderAddFreeGiftActioncreatePromotionOrderAddFreeGiftAction(SessionContext ctx, Product product, PromotionResult result)Create a newPromotionOrderAddFreeGiftActioninstance.PromotionOrderAdjustTotalActioncreatePromotionOrderAdjustTotalAction(SessionContext ctx, double totalAdjustment)Create a newPromotionOrderAdjustTotalActioninstance.PromotionOrderChangeDeliveryModeActioncreatePromotionOrderChangeDeliveryModeAction(SessionContext ctx, DeliveryMode deliveryMode)Create a newPromotionOrderChangeDeliveryModeActioninstance.PromotionOrderEntryAdjustActioncreatePromotionOrderEntryAdjustAction(SessionContext ctx, AbstractOrderEntry entry, double adjustment)This does not store the order entry but records its information so that a similar order entry with the same product and quantity can be located in this and other orders.PromotionOrderEntryAdjustActioncreatePromotionOrderEntryAdjustAction(SessionContext ctx, AbstractOrderEntry entry, long quantity, double adjustment)Create a newPromotionOrderEntryAdjustActioninstance.PromotionOrderEntryConsumedcreatePromotionOrderEntryConsumed(SessionContext ctx, java.lang.String code, AbstractOrderEntry orderEntry, long quantity)Create a newPromotionOrderEntryConsumedinstance.PromotionOrderEntryConsumedcreatePromotionOrderEntryConsumed(SessionContext ctx, java.lang.String code, AbstractOrderEntry orderEntry, long quantity, double adjustedUnitPrice)Create a newPromotionOrderEntryConsumedinstance.PromotionPriceRowcreatePromotionPriceRow(Currency currency, double price)Create a newPromotionPriceRowinstance.PromotionPriceRowcreatePromotionPriceRow(SessionContext ctx, Currency currency, double price)Create a newPromotionPriceRowinstance.PromotionQuantityAndPricesRowcreatePromotionQuantityAndPricesRow(SessionContext ctx, long quantity, java.util.Collection<PromotionPriceRow> prices)Create a newPromotionQuantityAndPricesRowinstance.PromotionResultcreatePromotionResult(SessionContext ctx, AbstractPromotion promotion, AbstractOrder order, float certainty)Create a newPromotionResultinstance.protected voiddeleteStoredPromotionResults(SessionContext ctx, AbstractOrder order, boolean undoActions)Delete the the stored promotion results for an AbstractOrder.protected java.util.List<PromotionResult>evaluatePromotion(SessionContext ctx, PromotionEvaluationContext promoContext, AbstractPromotion promotion)PromotionsManager.RestrictionSetResultevaluateRestrictions(SessionContext ctx, java.util.List<Product> products, AbstractOrder order, AbstractPromotion promo, java.util.Date date)Evaluate all of the restrictions for a given promotion and return a result object containing the allowed items.PromotionsManager.RestrictionSetResultevaluateRestrictions(SessionContext ctx, java.util.List<Product> products, AbstractOrder order, java.util.Collection<AbstractPromotionRestriction> restrictions, java.util.Date date)Evaluate the specified restrictions and return a result object containing the allowed items.<T extends AbstractPromotion>
java.util.List<T>filterPromotionsByRestrictions(SessionContext ctx, java.util.List<T> allPromotions, Product product, java.util.Date date)Filter a list of promotions by their restrictionsstatic java.util.List<AbstractPromotion>findOrderAndProductPromotionsSortByPriority(SessionContext ctx, JaloSession jaloSession, java.util.Collection<PromotionGroup> promotionGroups, java.util.Collection<Product> products, java.util.Date date)Find all promotions that can be evaluated on the list of product specified.protected static voidfixupVouchersReapplyVouchers(SessionContext ctx, AbstractOrder order, java.util.List<Voucher> vouchers)Method to fixup the vouchers applied to the order.protected static java.util.List<Voucher>fixupVouchersRemoveVouchers(SessionContext ctx, AbstractOrder order)Method to fixup the vouchers applied to the order.static java.util.Collection<Product>getBaseProductsForOrder(SessionContext ctx, AbstractOrder order)Get the list of products and base products in the order.protected ComposedTypegetComposedType(java.lang.Class aClass)Lookup a composed type for a classPromotionGroupgetDefaultPromotionGroup()Lookup the default promotion group created by the promotions extension.PromotionGroupgetDefaultPromotionGroup(SessionContext ctx)Lookup the default promotion group created by the promotions extension.static PromotionsManagergetInstance()Get the instance of this manager.protected SessionContextgetLanguageNeutralSessionContext()Create a language neutral session contextjava.util.List<OrderPromotion>getOrderPromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, Product product, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, Product product)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, Product product, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotion>getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<ProductPromotion>getProductPromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, Product product, boolean evaluateRestrictions, java.util.Date date)Get the ordered list ofProductPromotioninstances that are related to theProductspecified.java.util.List<ProductPromotion>getProductPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product)Get the ordered list ofProductPromotioninstances that are related to theProductspecified.java.util.List<ProductPromotion>getProductPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product, boolean evaluateRestrictions, java.util.Date date)Get the ordered list ofProductPromotioninstances that are related to theProductspecified.PromotionGroupgetPromotionGroup(java.lang.String identifier)Lookup a promotion group with the given identifier.PromotionOrderResultsgetPromotionResults(AbstractOrder order)Get the promotion results for the specified order.PromotionOrderResultsgetPromotionResults(SessionContext ctx, AbstractOrder order)Get the promotion results for the specified order.PromotionOrderResultsgetPromotionResults(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)Get the promotion results for the specified order.protected java.util.List<PromotionResult>getPromotionResultsInternal(SessionContext ctx, AbstractOrder order)Get the list of promotion results for the specified order.protected voidinitialiseDefaultLocalisedValues(SessionContext languageNeutralSessionContext, ComposedType type)Set default values for localized attributes on the type specified.protected voidinitialiseDefaultLocalisedValues(SessionContext languageNeutralSessionContext, java.util.Set<ComposedType> types)Set the default values on the set of types specified.protected booleankeepApplied(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotion promotion, boolean autoApply)protected static java.lang.StringmakeActionGUID()Create a new unique string to identify an action instance.voidnotifyInitializationEnd(java.util.Map<java.lang.String,java.lang.String> params, JspContext ctx)voidnotifyInitializationStart(java.util.Map<java.lang.String,java.lang.String> params, JspContext ctx)protected java.util.Comparator<PromotionResult>sortByPromotionPriority()returns a comparator that sorts promotionresults by their promotion's priorityvoidtransferPromotionsToOrder(AbstractOrder source, Order target, boolean onlyTransferAppliedPromotions)Transfer the promotions applied to a cart to a new order.voidtransferPromotionsToOrder(SessionContext ctx, AbstractOrder source, Order target, boolean onlyTransferAppliedPromotions)Transfer the promotions applied to a cart to a new order.PromotionOrderResultsupdatePromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order)Update the promotions on the specifiedAbstractOrderobject.PromotionOrderResultsupdatePromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)Update the promotions on the specifiedAbstractOrderobject.PromotionOrderResultsupdatePromotions(java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order)Update the promotions on the specifiedAbstractOrderobject.protected PromotionOrderResultsupdatePromotionsNotThreadSafe(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)-
Methods inherited from class de.hybris.platform.promotions.jalo.GeneratedPromotionsManager
addToAllPromotionResults, addToAllPromotionResults, addToPromotions, addToPromotions, addToPromotions, addToPromotions, createAbstractPromotionAction, createAbstractPromotionAction, createAbstractPromotionRestriction, createAbstractPromotionRestriction, createCachedPromotionNullAction, createCachedPromotionNullAction, createCachedPromotionOrderAddFreeGiftAction, createCachedPromotionOrderAddFreeGiftAction, createCachedPromotionOrderAdjustTotalAction, createCachedPromotionOrderAdjustTotalAction, createCachedPromotionOrderChangeDeliveryModeAction, createCachedPromotionOrderChangeDeliveryModeAction, createCachedPromotionOrderEntryAdjustAction, createCachedPromotionOrderEntryAdjustAction, createCachedPromotionOrderEntryConsumed, createCachedPromotionOrderEntryConsumed, createCachedPromotionResult, createCachedPromotionResult, createOrderPromotion, createOrderPromotion, createOrderThresholdChangeDeliveryModePromotion, createOrderThresholdChangeDeliveryModePromotion, createOrderThresholdDiscountPromotion, createOrderThresholdDiscountPromotion, createOrderThresholdFreeGiftPromotion, createOrderThresholdFreeGiftPromotion, createOrderThresholdFreeVoucherPromotion, createOrderThresholdFreeVoucherPromotion, createOrderThresholdPerfectPartnerPromotion, createOrderThresholdPerfectPartnerPromotion, createProductBOGOFPromotion, createProductBOGOFPromotion, createProductBundlePromotion, createProductBundlePromotion, createProductFixedPricePromotion, createProductFixedPricePromotion, createProductMultiBuyPromotion, createProductMultiBuyPromotion, createProductOneToOnePerfectPartnerPromotion, createProductOneToOnePerfectPartnerPromotion, createProductPercentageDiscountPromotion, createProductPercentageDiscountPromotion, createProductPerfectPartnerBundlePromotion, createProductPerfectPartnerBundlePromotion, createProductPerfectPartnerPromotion, createProductPerfectPartnerPromotion, createProductPromotion, createProductPromotion, createProductSteppedMultiBuyPromotion, createProductSteppedMultiBuyPromotion, createPromotionGroup, createPromotionGroup, createPromotionNullAction, createPromotionNullAction, createPromotionOrderAddFreeGiftAction, createPromotionOrderAddFreeGiftAction, createPromotionOrderAdjustTotalAction, createPromotionOrderAdjustTotalAction, createPromotionOrderChangeDeliveryModeAction, createPromotionOrderChangeDeliveryModeAction, createPromotionOrderEntryAdjustAction, createPromotionOrderEntryAdjustAction, createPromotionOrderEntryConsumed, createPromotionOrderEntryConsumed, createPromotionPriceRow, createPromotionPriceRow, createPromotionProductRestriction, createPromotionProductRestriction, createPromotionQuantityAndPricesRow, createPromotionQuantityAndPricesRow, createPromotionResult, createPromotionResult, createPromotionUserRestriction, createPromotionUserRestriction, getAllPromotionResults, getAllPromotionResults, getDefaultAttributeModes, getName, getPreviousDeliveryMode, getPreviousDeliveryMode, getPromotions, getPromotions, getPromotions, getPromotions, getPromotionsCount, getPromotionsCount, getPromotionsCount, getPromotionsCount, removeFromAllPromotionResults, removeFromAllPromotionResults, removeFromPromotions, removeFromPromotions, removeFromPromotions, removeFromPromotions, setAllPromotionResults, setAllPromotionResults, setPreviousDeliveryMode, setPreviousDeliveryMode, setPromotions, setPromotions, setPromotions, setPromotions
-
Methods inherited from class de.hybris.platform.jalo.extension.Extension
checkBeforeItemRemoval, createProjectData, createSampleData, getCreatorDescription, getCreatorName, getCreatorParameterDefault, getCreatorParameterNames, getCreatorParameterPossibleValues, getRemote, isCreatorDisabled, notifyItemRemoval, onFirstSessionCreation, writeReplace
-
Methods inherited from class de.hybris.platform.jalo.Manager
afterItemCreation, beforeItemCreation, destroy, extractNonRequiredRemoteFromItem, extractRequiredRemoteFromItem, getAllValuesSessionContext, getAttribute, getAttributeMap, getFirstItemByAttribute, getFirstItemByAttribute, getRemoteManagerClass, getSession, getSingletonManagerInstance, getTenant, getTransientObject, getTransientObjectMap, init, setAttribute, setTenant, setTransientObject, wrap
-
-
-
-
Method Detail
-
notifyInitializationStart
public void notifyInitializationStart(java.util.Map<java.lang.String,java.lang.String> params, JspContext ctx)- Overrides:
notifyInitializationStartin classExtension
-
notifyInitializationEnd
public void notifyInitializationEnd(java.util.Map<java.lang.String,java.lang.String> params, JspContext ctx)- Overrides:
notifyInitializationEndin classExtension
-
getInstance
public static PromotionsManager getInstance()
Get the instance of this manager.- Returns:
- instance of this manager
-
createEssentialData
public void createEssentialData(java.util.Map params, JspContext jspc) throws java.lang.ExceptionImplement this method to create initial objects. This method will be called by system creator.- Overrides:
createEssentialDatain classExtension- Parameters:
params- the parameters provided by user for creation of objects for the extensionjspc- the jsp context; you can use it to write progress information to the jsp page during creation- Throws:
java.lang.Exception- if something goes wrong
-
getLanguageNeutralSessionContext
protected SessionContext getLanguageNeutralSessionContext()
Create a language neutral session context
-
initialiseDefaultLocalisedValues
protected void initialiseDefaultLocalisedValues(SessionContext languageNeutralSessionContext, java.util.Set<ComposedType> types)
Set the default values on the set of types specified.- Parameters:
languageNeutralSessionContext- - instance ofSessionContexttypes- - set of composed type instances
-
initialiseDefaultLocalisedValues
protected void initialiseDefaultLocalisedValues(SessionContext languageNeutralSessionContext, ComposedType type)
Set default values for localized attributes on the type specified. Looks up the localized value from the items.xml localized resources.- Parameters:
languageNeutralSessionContext- - instance ofSessionContexttype- The type to localize attributes on
-
getComposedType
protected ComposedType getComposedType(java.lang.Class aClass)
Lookup a composed type for a class
-
getProductPromotions
public final java.util.List<ProductPromotion> getProductPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product)
Get the ordered list ofProductPromotioninstances that are related to theProductspecified.- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product that the promotions are related to- Returns:
- The list of
ProductPromotionrelated to theProductspecified
-
getProductPromotions
public final java.util.List<ProductPromotion> getProductPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product, boolean evaluateRestrictions, java.util.Date date)
Get the ordered list ofProductPromotioninstances that are related to theProductspecified.- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product that the promotions are related toevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.date- The date to check for promotions, typically the current date- Returns:
- The list of
ProductPromotionrelated to theProductspecified
-
getProductPromotions
public java.util.List<ProductPromotion> getProductPromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, Product product, boolean evaluateRestrictions, java.util.Date date)
Get the ordered list ofProductPromotioninstances that are related to theProductspecified.- Parameters:
ctx- The session contextpromotionGroups- The promotion groups to evaluateproduct- The product that the promotions are related toevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.date- The date to check for promotions, typically the current date- Returns:
- The list of
ProductPromotionrelated to theProductspecified
-
buildQueryForDistinctProductPromotionQuery
protected java.lang.String buildQueryForDistinctProductPromotionQuery(Product product, SessionContext ctx, java.util.Map<java.lang.String,java.lang.Object> args)
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluate- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, java.util.Date date)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluatedate- The date to check for promotions, typically the current date- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product to pass to restrictions- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, Product product, java.util.Date date)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product to pass to restrictionsdate- The date to check for promotions, typically the current date- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluateevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, java.util.Date date)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluateevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.date- The date to check for promotions, typically the current date- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, Product product)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluateevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.product- The product to pass to restrictions if evaluateRestrictions is true- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, Product product, java.util.Date date)
Get the ordered list ofOrderPromotioninstances.- Parameters:
promotionGroups- The promotion groups to evaluateevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.product- The product to pass to restrictions if evaluateRestrictions is truedate- The date to check for promotions, typically the current date- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotion> getOrderPromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, boolean evaluateRestrictions, Product product, java.util.Date date)
Get the ordered list ofOrderPromotioninstances.- Parameters:
ctx- The session contextpromotionGroups- The promotion groups to evaluateevaluateRestrictions- Flag, pass false to ignore any restrictions specified on the promotions, pass true to observe the restrictions.product- The product to pass to restrictions if evaluateRestrictions is truedate- The date to check for promotions, typically the current date- Returns:
- The list of
OrderPromotion
-
filterPromotionsByRestrictions
public <T extends AbstractPromotion> java.util.List<T> filterPromotionsByRestrictions(SessionContext ctx, java.util.List<T> allPromotions, Product product, java.util.Date date)
Filter a list of promotions by their restrictions- Parameters:
allPromotions- The promotions list to filterproduct- Optional product to pass when evaluating restrictionsdate- The restriction date- Returns:
- The filtered list of promotions
-
updatePromotions
public final PromotionOrderResults updatePromotions(java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order)
Update the promotions on the specifiedAbstractOrderobject. This method will automatically apply all possible product promotional updates to the cart, but not apply order level promotions. Any previously applied order level promotions will remain applied. Promotions are evaluated at the current system time. The promotion results are stored in the database and the samePromotionOrderResultscan be obtained later by callinggetPromotionResults(de.hybris.platform.jalo.order.AbstractOrder).- Parameters:
promotionGroups- The promotion groups to evaluateorder- The order object to update with the results of the promotions- Returns:
- The promotion results
- See Also:
updatePromotions(SessionContext, Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date),getPromotionResults(de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(de.hybris.platform.jalo.SessionContext, de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date)
-
updatePromotions
public PromotionOrderResults updatePromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order)
Update the promotions on the specifiedAbstractOrderobject. This method will automatically apply all possible product promotional updates to the cart, but not apply order level promotions. Any previously applied order level promotions will remain applied. Promotions are evaluated at the current system time. The promotion results are stored in the database and the samePromotionOrderResultscan be obtained later by callinggetPromotionResults(de.hybris.platform.jalo.order.AbstractOrder).- Parameters:
ctx- The hybris session contextpromotionGroups- The promotion groups to evaluateorder- The order object to update with the results of the promotions- Returns:
- The promotion results
- See Also:
updatePromotions(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date),getPromotionResults(de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(de.hybris.platform.jalo.SessionContext, de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date)
-
updatePromotions
public PromotionOrderResults updatePromotions(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
Update the promotions on the specifiedAbstractOrderobject. The resulting promotions can be retrieved later by callinggetPromotionResults(de.hybris.platform.jalo.order.AbstractOrder). The order must be calculated before calling this method.updatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder)must be called after callingAbstractOrder.recalculate()on theAbstractOrder. Where thePromotionsManager.AutoApplyModeis set toPromotionsManager.AutoApplyMode.KEEP_APPLIEDthe state of any previously appliedPromotionResultis recorded and if it is still in the fired state (PromotionResult.isApplied()) after reevaluating the promotions it will be automatically reapplied. The promotion results are stored in the database and the samePromotionOrderResultscan be obtained later by callinggetPromotionResults(de.hybris.platform.jalo.order.AbstractOrder).- Parameters:
ctx- The hybris session contextpromotionGroups- The promotion groups to evaluateorder- The AbstractOrder object to update the promotions forevaluateRestrictions- If true any promotion restrictions will be observed, if false all promotion restrictions are ignoredproductPromotionMode- The auto apply mode. This determines whether this method applies any product promotional changes to line items or discounts to the overall amountorderPromotionMode- The auto apply mode. This determines whether this method applies any order promotional changes to line items or discounts to the overall amountdate- The effective date for the promotions to check. Use this to to see the effects of promotions in the past or future.- Returns:
- The promotion results
- See Also:
getPromotionResults(de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(de.hybris.platform.jalo.SessionContext, de.hybris.platform.jalo.order.AbstractOrder),getPromotionResults(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date)
-
updatePromotionsNotThreadSafe
protected PromotionOrderResults updatePromotionsNotThreadSafe(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
-
keepApplied
protected boolean keepApplied(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotion promotion, boolean autoApply)
-
autoApplyApplies
protected boolean autoApplyApplies(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotion promotion)
-
evaluatePromotion
protected java.util.List<PromotionResult> evaluatePromotion(SessionContext ctx, PromotionEvaluationContext promoContext, AbstractPromotion promotion)
-
fixupVouchersRemoveVouchers
protected static java.util.List<Voucher> fixupVouchersRemoveVouchers(SessionContext ctx, AbstractOrder order)
Method to fixup the vouchers applied to the order. This method is called before promotions have been calculates. It identifies any voucher discounts that are applied to the order, and removes them.- Parameters:
ctx- the hybris session contextorder- the order to fixup
-
fixupVouchersReapplyVouchers
protected static void fixupVouchersReapplyVouchers(SessionContext ctx, AbstractOrder order, java.util.List<Voucher> vouchers)
Method to fixup the vouchers applied to the order. This method is called after promotions have been applied. It takes a list of voucher that were removed from the order. This method reapplies the voucher's discount to the order. The voucher calculates its discount based on the subtotal and does not take into account other discounts. This method then recalculates the discount that should be applied for each voucher and adds a new global discount for this.- Parameters:
ctx- the hybris session contextorder- the order to fixupvouchers- the vouchers to reapply
-
findOrderAndProductPromotionsSortByPriority
public static java.util.List<AbstractPromotion> findOrderAndProductPromotionsSortByPriority(SessionContext ctx, JaloSession jaloSession, java.util.Collection<PromotionGroup> promotionGroups, java.util.Collection<Product> products, java.util.Date date)
Find all promotions that can be evaluated on the list of product specified. This includes all OrderPromotions and any ProductPromotions that are related to the any of the products passed- Parameters:
ctx- The hybris contextjaloSession- The jalo sessionpromotionGroups- The promotion groups to evaluateproducts- The list of products to find associated promotions fordate- The date to test against promotions- Returns:
- The list of promotions
-
getBaseProductsForOrder
public static java.util.Collection<Product> getBaseProductsForOrder(SessionContext ctx, AbstractOrder order)
Get the list of products and base products in the order. If the product is a variant then the base product is selected.- Parameters:
ctx- the hybris contextorder- the order- Returns:
- the list of products from the order
-
getPromotionResults
public final PromotionOrderResults getPromotionResults(AbstractOrder order)
Get the promotion results for the specified order. These are the promotion results stored in the database for the specified order as generated by the last call toupdatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder)for the same order. If any of the promotion results are invalid then they will be ignored.- Parameters:
order- The order to get the promotion results for- Returns:
- The promotion results
- See Also:
updatePromotions(Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date)
-
getPromotionResults
public PromotionOrderResults getPromotionResults(SessionContext ctx, AbstractOrder order)
Get the promotion results for the specified order. These are the promotion results stored in the database for the specified order as generated by the last call toupdatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder)for the same order. If any of the promotion results are invalid then they will be ignored. To force the list of promotions to be recalculated either callupdatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder)or call the version ofgetPromotionResults(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date).- Parameters:
ctx- The session contextorder- The order to get the promotion results for- Returns:
- The promotion results
- See Also:
updatePromotions(Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date)
-
getPromotionResults
public PromotionOrderResults getPromotionResults(SessionContext ctx, java.util.Collection<PromotionGroup> promotionGroups, AbstractOrder order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
Get the promotion results for the specified order. These are the promotion results stored in the database for the specified order as generated by the last call toupdatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder)for the same order. If any of the promotion results are invalid then this method will recalculate the promotions by callingupdatePromotions(java.util.Collection<de.hybris.platform.promotions.jalo.PromotionGroup>, de.hybris.platform.jalo.order.AbstractOrder).- Parameters:
ctx- The hybris session contextpromotionGroups- The promotion groups to evaluateorder- The AbstractOrder object to get the promotions forevaluateRestrictions- If true any promotion restrictions will be observed, if false all promotion restrictions are ignoredproductPromotionMode- The auto apply mode. This determines whether this method applies any product promotional changes to line items or discounts to the overall amountorderPromotionMode- The auto apply mode. This determines whether this method applies any order promotional changes to line items or discounts to the overall amountdate- The effective date for the promotions to check. Use this to to see the effects of promotions in the past or future.- Returns:
- The promotion results
- See Also:
updatePromotions(Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder),updatePromotions(SessionContext, Collection, AbstractOrder, boolean, AutoApplyMode, AutoApplyMode, Date)
-
getPromotionResultsInternal
protected java.util.List<PromotionResult> getPromotionResultsInternal(SessionContext ctx, AbstractOrder order)
Get the list of promotion results for the specified order.- Parameters:
ctx- The session contextorder- The order to get the promotion results for- Returns:
- The promotion results
-
sortByPromotionPriority
protected java.util.Comparator<PromotionResult> sortByPromotionPriority()
returns a comparator that sorts promotionresults by their promotion's priority
-
deleteStoredPromotionResults
protected void deleteStoredPromotionResults(SessionContext ctx, AbstractOrder order, boolean undoActions)
Delete the the stored promotion results for an AbstractOrder.- Parameters:
ctx- The session contextorder- The order to delete the results forundoActions- Undo the actions before deleting the promotion results
-
cleanupCart
public final void cleanupCart(Cart cart)
Delete the the stored promotion results for a Cart.- Parameters:
cart- TheCartto delete the results for
-
cleanupCart
public void cleanupCart(SessionContext ctx, Cart cart)
Delete the the stored promotion results for a Cart.- Parameters:
ctx- The session contextcart- TheCartto delete the results for
-
cleanupOrphanedResults
public final void cleanupOrphanedResults()
Delete any promotion results that are orphaned. This method should not be used in normal operation, thecleanupCart(de.hybris.platform.jalo.order.Cart)method should be used instead. This method can be used in an admin context if required.
-
cleanupOrphanedResults
public void cleanupOrphanedResults(SessionContext ctx)
Delete any promotion results that are orphaned. This method should not be used in normal operation, thecleanupCart(de.hybris.platform.jalo.order.Cart)method should be used instead. This method can be used in an admin context if required.- Parameters:
ctx- The session context
-
transferPromotionsToOrder
public final void transferPromotionsToOrder(AbstractOrder source, Order target, boolean onlyTransferAppliedPromotions)
Transfer the promotions applied to a cart to a new order. This is used when an order is created from a cart.- Parameters:
source- The cart that has promotionstarget- The order that promotions should be applied toonlyTransferAppliedPromotions- Flag to indicate that only applied promotions should be transfered. If false all promotion results will be transfered
-
transferPromotionsToOrder
public void transferPromotionsToOrder(SessionContext ctx, AbstractOrder source, Order target, boolean onlyTransferAppliedPromotions)
Transfer the promotions applied to a cart to a new order. This is used when an order is created from a cart.- Parameters:
ctx- The session contextsource- The cart that has promotionstarget- The order that promotions should be applied toonlyTransferAppliedPromotions- Flag to indicate that only applied promotions should be transfered. If false all promotion results will be transfered
-
evaluateRestrictions
public final PromotionsManager.RestrictionSetResult evaluateRestrictions(SessionContext ctx, java.util.List<Product> products, AbstractOrder order, AbstractPromotion promo, java.util.Date date)
Evaluate all of the restrictions for a given promotion and return a result object containing the allowed items.- Parameters:
ctx- The current contextproducts- The products to be considered for restrictionorder- The current orderpromo- The promotion to evaluatedate- The effective date to evaluate the restrictions on- Returns:
- A RestrictionSetResult object
-
evaluateRestrictions
public PromotionsManager.RestrictionSetResult evaluateRestrictions(SessionContext ctx, java.util.List<Product> products, AbstractOrder order, java.util.Collection<AbstractPromotionRestriction> restrictions, java.util.Date date)
Evaluate the specified restrictions and return a result object containing the allowed items.- Parameters:
ctx- The current contextproducts- The products to be considered for restrictionorder- The current orderrestrictions- The set of restrictions to evaluatedate- The effective date to evaluate the restrictions on- Returns:
- A RestrictionSetResult object
-
getDefaultPromotionGroup
public PromotionGroup getDefaultPromotionGroup()
Lookup the default promotion group created by the promotions extension.- Returns:
- the default promotion group
-
getDefaultPromotionGroup
public PromotionGroup getDefaultPromotionGroup(SessionContext ctx)
Lookup the default promotion group created by the promotions extension.- Parameters:
ctx- The session context- Returns:
- the default promotion group
-
getPromotionGroup
public PromotionGroup getPromotionGroup(java.lang.String identifier)
Lookup a promotion group with the given identifier.- Parameters:
identifier- identifier of the promotion group to look for- Returns:
- the promotion group or null if no group with the given identifier is found *
- Throws:
java.lang.IllegalArgumentException- if identifier is null
-
createPromotionOrderEntryConsumed
public PromotionOrderEntryConsumed createPromotionOrderEntryConsumed(SessionContext ctx, java.lang.String code, AbstractOrderEntry orderEntry, long quantity)
Create a newPromotionOrderEntryConsumedinstance.- Parameters:
ctx- The session contextcode- The object's codeorderEntry- TheAbstractOrderEntrythat is the base order entry for the objectquantity- The quantity mapped through from the base order entry- Returns:
- the new
PromotionOrderEntryConsumed
-
createPromotionOrderEntryConsumed
public PromotionOrderEntryConsumed createPromotionOrderEntryConsumed(SessionContext ctx, java.lang.String code, AbstractOrderEntry orderEntry, long quantity, double adjustedUnitPrice)
Create a newPromotionOrderEntryConsumedinstance.- Parameters:
ctx- The session contextcode- The object's codeorderEntry- TheAbstractOrderEntrythat is the base order entry for the objectquantity- The quantity mapped through from the base order entryadjustedUnitPrice- The adjusted unit price- Returns:
- the new
PromotionOrderEntryConsumed
-
createPromotionResult
public PromotionResult createPromotionResult(SessionContext ctx, AbstractPromotion promotion, AbstractOrder order, float certainty)
Create a newPromotionResultinstance.- Parameters:
ctx- The session contextpromotion- TheAbstractPromotionthat created thePromotionResultorder- TheAbstractOrderthat thePromotionResultis related tocertainty- The certainty of firing in the range 0 to 1. 1.0 is fired, less than 1.0 is could fire.- Returns:
- the new
PromotionResult
-
createPromotionOrderAdjustTotalAction
public PromotionOrderAdjustTotalAction createPromotionOrderAdjustTotalAction(SessionContext ctx, double totalAdjustment)
Create a newPromotionOrderAdjustTotalActioninstance.- Parameters:
ctx- The session contexttotalAdjustment- The amount to adjust the order total (positive increases order total, negative decreases)- Returns:
- the new
PromotionOrderAdjustTotalAction
-
createPromotionOrderAddFreeGiftAction
public PromotionOrderAddFreeGiftAction createPromotionOrderAddFreeGiftAction(SessionContext ctx, Product product, PromotionResult result)
Create a newPromotionOrderAddFreeGiftActioninstance.- Parameters:
ctx- The session contextproduct- TheProductto give awayresult- ThePromotionResultthat owns this action.- Returns:
- the new
PromotionOrderAddFreeGiftAction
-
createPromotionOrderChangeDeliveryModeAction
public PromotionOrderChangeDeliveryModeAction createPromotionOrderChangeDeliveryModeAction(SessionContext ctx, DeliveryMode deliveryMode)
Create a newPromotionOrderChangeDeliveryModeActioninstance.- Parameters:
ctx- The session contextdeliveryMode- TheDeliveryModeto set on the order- Returns:
- the new
PromotionOrderChangeDeliveryModeAction
-
createPromotionPriceRow
public PromotionPriceRow createPromotionPriceRow(Currency currency, double price)
Create a newPromotionPriceRowinstance.- Parameters:
currency- TheCurrencythat the price is specified inprice- The price value- Returns:
- the new
PromotionPriceRow
-
createPromotionPriceRow
public PromotionPriceRow createPromotionPriceRow(SessionContext ctx, Currency currency, double price)
Create a newPromotionPriceRowinstance.- Parameters:
ctx- The session contextcurrency- TheCurrencythat the price is specifed inprice- The price value- Returns:
- the new
PromotionPriceRow
-
createPromotionQuantityAndPricesRow
public PromotionQuantityAndPricesRow createPromotionQuantityAndPricesRow(SessionContext ctx, long quantity, java.util.Collection<PromotionPriceRow> prices)
Create a newPromotionQuantityAndPricesRowinstance.- Parameters:
ctx- The session contextquantity- The quantityprices- The prices for the quantity- Returns:
- the new
PromotionQuantityAndPricesRow
-
createPromotionOrderEntryAdjustAction
public PromotionOrderEntryAdjustAction createPromotionOrderEntryAdjustAction(SessionContext ctx, AbstractOrderEntry entry, long quantity, double adjustment)
Create a newPromotionOrderEntryAdjustActioninstance.- Parameters:
ctx- The session contextentry- TheAbstractOrderEntryto adjustquantity- The quantity to adjustadjustment- The adjustment to make- Returns:
- the new
PromotionOrderEntryAdjustAction - Since:
- 4.4
-
createPromotionOrderEntryAdjustAction
public PromotionOrderEntryAdjustAction createPromotionOrderEntryAdjustAction(SessionContext ctx, AbstractOrderEntry entry, double adjustment)
This does not store the order entry but records its information so that a similar order entry with the same product and quantity can be located in this and other orders.- Parameters:
ctx- The session contextentry- TheAbstractOrderEntryto adjustadjustment- The adjustment to make- Returns:
- the new
PromotionOrderEntryAdjustAction
-
createPromotionGroup
public PromotionGroup createPromotionGroup(SessionContext ctx, java.lang.String identifier)
Create a newPromotionGroupinstance.- Parameters:
ctx- The session contextidentifier- The identifier for the promotion group- Returns:
- the new
PromotionGroup
-
createPromotionNullAction
public PromotionNullAction createPromotionNullAction(SessionContext ctx)
Create a newPromotionNullActioninstance.- Parameters:
ctx- The session context- Returns:
- the new
PromotionNullAction
-
makeActionGUID
protected static java.lang.String makeActionGUID()
Create a new unique string to identify an action instance.- Returns:
- a unique identifier
-
-