Class DefaultPromotionsService
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.service.AbstractService
-
- de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
-
- de.hybris.platform.promotions.impl.AbstractPromotionsService
-
- de.hybris.platform.promotions.impl.DefaultPromotionsService
-
- All Implemented Interfaces:
PromotionsService,java.io.Serializable,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.InitializingBean
public class DefaultPromotionsService extends AbstractPromotionsService implements PromotionsService
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDefaultPromotionsService.ProductComparator-
Nested classes/interfaces inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
AbstractService.SerializableDTO
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringORDER_PROMOTIONS_QUERYprotected static java.lang.StringPRODUCT_PROMOTIONS_QUERYprotected static java.lang.StringPRODUCT_PROMOTIONS_QUERY_DESCprotected static java.lang.StringPRODUCT_PROMTIONS_QUERY_UNIONprotected static java.lang.StringPROMOTION_GROUP_QUERYprotected static java.lang.StringPROMOTION_RESULTS_QUERYprotected static java.lang.StringSORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_CATEGORIES_PARTprotected static java.lang.StringSORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_ORDER_PARTprotected static java.lang.StringSORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_PRODUCTS_PARTprotected static java.lang.StringSORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_STARTprotected static java.lang.StringSORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_UNION_ALL_PART-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
modelService, sessionService, txManager
-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
tenant
-
-
Constructor Summary
Constructors Constructor Description DefaultPromotionsService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanautoApplyApplies(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotionModel promotion)protected voidbuildPromotionResultDataUniqueKey(PromotionResultModel promotionResult, java.lang.StringBuilder builder)Build a unique identifier for a PromotionResult.protected java.lang.StringbuildQueryForDistinctProductPromotionQuery(ProductModel product, java.util.Map<java.lang.String,java.lang.Object> args)protected voidcheckLegacyMode()voidcleanupCart(CartModel cart)Delete the the stored promotion results for a Cart.protected voiddeleteStoredPromotionResults(AbstractOrderModel order, boolean undoActions)Delete the the stored promotion results for an AbstractOrder.protected java.util.List<PromotionResultModel>evaluatePromotion(PromotionEvaluationContext promoContext, AbstractPromotionModel promotion)protected <T extends AbstractPromotionModel>
java.util.List<T>filterPromotionsByRestrictions(java.util.List<T> allPromotions, ProductModel product, java.util.Date date)Filter a list of promotions by their restrictionsjava.util.List<AbstractPromotionModel>findOrderAndProductPromotionsSortByPriority(java.util.Collection<PromotionGroupModel> promotionGroups, java.util.Collection<ProductModel> products, java.util.Date date)Find all promotions that can be evaluated on the list of product specified.protected voidfixupVouchersReapplyVouchers(AbstractOrderModel order, java.util.List<VoucherModel> vouchers)Method to fixup the vouchers applied to the order.protected java.util.List<VoucherModel>fixupVouchersRemoveVouchers(AbstractOrderModel order)Method to fixup the vouchers applied to the order.java.util.List<? extends AbstractPromotionModel>getAbstractProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product)Get the ordered list ofAbstractPromotionModelinstances that are related to theProductModelspecified.java.util.List<? extends AbstractPromotionModel>getAbstractProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product, boolean evaluateRestrictions, java.util.Date date)Get the ordered list ofAbstractPromotionModelinstances that are related to theProductModelspecified.protected ProductModelgetBaseProduct(ProductModel product)Return the base product for the product specified.protected java.util.List<ProductModel>getBaseProducts(ProductModel product)This is a recursive variant of the method above.protected voidgetBaseProducts(ProductModel product, java.util.List<ProductModel> result)Internal recursive method to get all base products of a given product.protected java.util.Collection<ProductModel>getBaseProductsForOrder(AbstractOrderModel order)Get the list of products and base products in the order.protected CalculationServicegetCalculationService()protected java.lang.StringgetDataUniqueKey(PromotionResultModel result)Generates a string identifier that can be used to establish if 2 PromotionResults are the same.PromotionGroupModelgetDefaultPromotionGroup()Lookup the default promotion group created by the promotions extension.protected FlexibleSearchServicegetFlexibleSearchService()protected LegacyModeCheckergetLegacyModeChecker()java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions, ProductModel product)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions, ProductModel product, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<OrderPromotionModel>getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, java.util.Date date)Get the ordered list ofOrderPromotioninstances.java.util.List<ProductPromotionModel>getProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product)Get the ordered list ofProductPromotioninstances that are related to theProductModelspecified.java.util.List<ProductPromotionModel>getProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product, boolean evaluateRestrictions, java.util.Date date)Get the ordered list ofProductPromotioninstances that are related to theProductModelspecified.java.lang.StringgetPromotionDescription(AbstractPromotionModel promotion)Get the description of given promotion.PromotionGroupModelgetPromotionGroup(java.lang.String identifier)Lookup a promotion group with the given identifier.protected java.lang.StringgetPromotionResultDataUniqueKey(PromotionResultModel promotionResult)Generate a string identifier that can be used to establish if 2 PromotionResults are the same.PromotionOrderResultsgetPromotionResults(AbstractOrderModel order)Get the promotion results for the specified order.PromotionOrderResultsgetPromotionResults(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel 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<PromotionResultModel>getPromotionResultsInternal(AbstractOrderModel order)Get the list of promotion results for the specified order.protected doublegetPromotionResultTotalDiscount(PromotionResultModel result)protected PromotionsManagergetPromotionsManager()java.util.Collection<AbstractPromotionRestrictionModel>getRestrictions(AbstractPromotionModel promotion)Get the collection ofAbstractPromotionRestrictionModelinstances.protected JaloSessiongetSession()protected doublegetTotalDiscount(PromotionResultModel result)Gets the total value of all discounts in the result.protected booleanisDiscountAbsolute(DiscountModel discount)protected booleanisPromotionResultApplied(PromotionResultModel result)protected booleanisPromotionResultFired(PromotionResultModel result)protected booleanisPromotionResultValid(PromotionResultModel result)protected booleankeepApplied(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotionModel promotion, boolean autoApply)protected voidrefreshOrder(AbstractOrderModel order)protected voidsaveIfModified(AbstractOrderModel order)voidsetCalculationService(CalculationService calculationService)voidsetFlexibleSearchService(FlexibleSearchService flexibleSearchService)voidsetLegacyModeChecker(LegacyModeChecker legacyModeChecker)protected java.util.Comparator<PromotionResultModel>sortByPromotionPriority()returns a comparator that sorts promotionresults by their promotion's priorityvoidtransferPromotionsToOrder(AbstractOrderModel source, OrderModel target, boolean onlyTransferAppliedPromotions)Transfer the promotions applied to a cart to a new order.protected doubleupdateForActivePromotions(AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date, java.util.List<java.lang.String> promotionResultsToKeepApplied, java.util.List<PromotionResultModel> results, double newTotalAppliedDiscount, java.util.List<AbstractPromotionModel> activePromotions)PromotionOrderResultsupdatePromotions(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order)Update the promotions on the specifiedAbstractOrderobject.PromotionOrderResultsupdatePromotions(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)Update the promotions on the specifiedAbstractOrderModelobject.protected PromotionOrderResultsupdatePromotionsInternal(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)protected PromotionOrderResultsupdatePromotionsNotThreadSafe(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)protected booleanusingPolyglotPersistence()-
Methods inherited from class de.hybris.platform.promotions.impl.AbstractPromotionsService
getCart, getOrder, getOrder, getProduct, getPromotion, getPromotion, getPromotion, getPromotionGroup, getResult, getSessionContext, refreshModifiedModelsAfter
-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
getModelService, getSessionService, getTxManager, setModelService, setSessionService, setTxManager
-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
afterPropertiesSet, getCurrentTenant, setBeanName, setCurrentTenant, writeReplace
-
-
-
-
Field Detail
-
PROMOTION_RESULTS_QUERY
protected static final java.lang.String PROMOTION_RESULTS_QUERY
-
ORDER_PROMOTIONS_QUERY
protected static final java.lang.String ORDER_PROMOTIONS_QUERY
- See Also:
- Constant Field Values
-
PRODUCT_PROMOTIONS_QUERY
protected static final java.lang.String PRODUCT_PROMOTIONS_QUERY
- See Also:
- Constant Field Values
-
PRODUCT_PROMTIONS_QUERY_UNION
protected static final java.lang.String PRODUCT_PROMTIONS_QUERY_UNION
- See Also:
- Constant Field Values
-
PROMOTION_GROUP_QUERY
protected static final java.lang.String PROMOTION_GROUP_QUERY
-
PRODUCT_PROMOTIONS_QUERY_DESC
protected static final java.lang.String PRODUCT_PROMOTIONS_QUERY_DESC
- See Also:
- Constant Field Values
-
SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_START
protected static final java.lang.String SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_START
- See Also:
- Constant Field Values
-
SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_PRODUCTS_PART
protected static final java.lang.String SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_PRODUCTS_PART
- See Also:
- Constant Field Values
-
SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_CATEGORIES_PART
protected static final java.lang.String SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_CATEGORIES_PART
- See Also:
- Constant Field Values
-
SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_UNION_ALL_PART
protected static final java.lang.String SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_UNION_ALL_PART
- See Also:
- Constant Field Values
-
SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_ORDER_PART
protected static final java.lang.String SORTED_ORDER_AND_PRODUCT_PROMOTIONS_QUERY_ORDER_PART
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPromotionsManager
protected PromotionsManager getPromotionsManager()
-
getSession
protected JaloSession getSession()
-
cleanupCart
public void cleanupCart(CartModel cart)
Description copied from interface:PromotionsServiceDelete the the stored promotion results for a Cart.- Specified by:
cleanupCartin interfacePromotionsService- Parameters:
cart- TheCartto delete the results for
-
deleteStoredPromotionResults
protected void deleteStoredPromotionResults(AbstractOrderModel order, boolean undoActions)
Delete the the stored promotion results for an AbstractOrder.- Parameters:
order- The order to delete the results forundoActions- Undo the actions before deleting the promotion results
-
getPromotionResultsInternal
protected java.util.List<PromotionResultModel> getPromotionResultsInternal(AbstractOrderModel order)
Get the list of promotion results for the specified order.- Parameters:
order- The order to get the promotion results for- Returns:
- The promotion results
-
usingPolyglotPersistence
protected boolean usingPolyglotPersistence()
-
sortByPromotionPriority
protected java.util.Comparator<PromotionResultModel> sortByPromotionPriority()
returns a comparator that sorts promotionresults by their promotion's priority
-
getDefaultPromotionGroup
public PromotionGroupModel getDefaultPromotionGroup()
Description copied from interface:PromotionsServiceLookup the default promotion group created by the promotions extension.- Specified by:
getDefaultPromotionGroupin interfacePromotionsService- Returns:
- the default promotion group
-
getOrderPromotions
public java.util.List<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- Parameters:
promotionGroups- The promotion groups to evaluate- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, java.util.Date date)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- 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<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product to pass to restrictions- Returns:
- The list of
OrderPromotion
-
getOrderPromotions
public java.util.List<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product, java.util.Date date)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- 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<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- 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<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions, java.util.Date date)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- 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<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions, ProductModel product)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- 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<OrderPromotionModel> getOrderPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, boolean evaluateRestrictions, ProductModel product, java.util.Date date)
Description copied from interface:PromotionsServiceGet the ordered list ofOrderPromotioninstances.- Specified by:
getOrderPromotionsin interfacePromotionsService- 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
-
filterPromotionsByRestrictions
protected <T extends AbstractPromotionModel> java.util.List<T> filterPromotionsByRestrictions(java.util.List<T> allPromotions, ProductModel 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
-
getProductPromotions
public java.util.List<ProductPromotionModel> getProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product)
Description copied from interface:PromotionsServiceGet the ordered list ofProductPromotioninstances that are related to theProductModelspecified.- Specified by:
getProductPromotionsin interfacePromotionsService- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product that the promotions are related to- Returns:
- The list of
ProductPromotionrelated to theProductModelspecified
-
getProductPromotions
public java.util.List<ProductPromotionModel> getProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product, boolean evaluateRestrictions, java.util.Date date)
Description copied from interface:PromotionsServiceGet the ordered list ofProductPromotioninstances that are related to theProductModelspecified.- Specified by:
getProductPromotionsin interfacePromotionsService- 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 theProductModelspecified
-
buildQueryForDistinctProductPromotionQuery
protected java.lang.String buildQueryForDistinctProductPromotionQuery(ProductModel product, java.util.Map<java.lang.String,java.lang.Object> args)
-
getAbstractProductPromotions
public java.util.List<? extends AbstractPromotionModel> getAbstractProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product)
Description copied from interface:PromotionsServiceGet the ordered list ofAbstractPromotionModelinstances that are related to theProductModelspecified.- Specified by:
getAbstractProductPromotionsin interfacePromotionsService- Parameters:
promotionGroups- The promotion groups to evaluateproduct- The product that the promotions are related to- Returns:
- The list of
AbstractPromotionModelrelated to theProductModelspecified
-
getAbstractProductPromotions
public java.util.List<? extends AbstractPromotionModel> getAbstractProductPromotions(java.util.Collection<PromotionGroupModel> promotionGroups, ProductModel product, boolean evaluateRestrictions, java.util.Date date)
Description copied from interface:PromotionsServiceGet the ordered list ofAbstractPromotionModelinstances that are related to theProductModelspecified.- Specified by:
getAbstractProductPromotionsin interfacePromotionsService- 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
AbstractPromotionModelrelated to theProductModelspecified
-
getPromotionGroup
public PromotionGroupModel getPromotionGroup(java.lang.String identifier)
Lookup a promotion group with the given identifier.- Specified by:
getPromotionGroupin interfacePromotionsService- 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
-
getPromotionResults
public PromotionOrderResults getPromotionResults(AbstractOrderModel order)
Description copied from interface:PromotionsServiceGet 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 toPromotionsService.updatePromotions(java.util.Collection<de.hybris.platform.promotions.model.PromotionGroupModel>, de.hybris.platform.core.model.order.AbstractOrderModel)for the same order. If any of the promotion results are invalid then they will be ignored.- Specified by:
getPromotionResultsin interfacePromotionsService- Parameters:
order- The order to get the promotion results for- Returns:
- The promotion results
-
isPromotionResultValid
protected boolean isPromotionResultValid(PromotionResultModel result)
-
isPromotionResultFired
protected boolean isPromotionResultFired(PromotionResultModel result)
-
isPromotionResultApplied
protected boolean isPromotionResultApplied(PromotionResultModel result)
-
getPromotionResultTotalDiscount
protected double getPromotionResultTotalDiscount(PromotionResultModel result)
-
getDataUniqueKey
protected java.lang.String getDataUniqueKey(PromotionResultModel result)
Generates a string identifier that can be used to establish if 2 PromotionResults are the same. The identifier should be based on the data for the PromotionResult, e.g. the promotion that created it, the number and type of products consumed, the actions created.- Parameters:
promotionResult-- Returns:
- a string that identifies this promotion result
-
getPromotionResultDataUniqueKey
protected final java.lang.String getPromotionResultDataUniqueKey(PromotionResultModel promotionResult)
Generate a string identifier that can be used to establish if 2 PromotionResults are the same. The identifier should be based on the data for the PromotionResult, e.g. the promotion that created it, the number and type of products consumed, the actions created. This method is final, but calls thebuildPromotionResultDataUniqueKey(de.hybris.platform.promotions.model.PromotionResultModel, java.lang.StringBuilder)method to allow subclasses to affect the way the identifier is built.- Parameters:
promotionResult- The promotion result- Returns:
- a string that identifies this promotion result
-
buildPromotionResultDataUniqueKey
protected void buildPromotionResultDataUniqueKey(PromotionResultModel promotionResult, java.lang.StringBuilder builder)
Build a unique identifier for a PromotionResult. This method is called fromgetPromotionResultDataUniqueKey(de.hybris.platform.promotions.model.PromotionResultModel). This method may be overridden by a subclass to customize how the identifier is built.- Parameters:
promotionResult- The promotion resultbuilder- A StringBuilder used to build up the identifier
-
getTotalDiscount
protected double getTotalDiscount(PromotionResultModel result)
Gets the total value of all discounts in the result. This result will be the same regardless of the applied state of this result, i.e. if not applied this is the discount value that would be applied, if it is applied then it is the value of the discount.- Returns:
- The double value for the total discount value
-
getPromotionResults
public PromotionOrderResults getPromotionResults(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
Description copied from interface:PromotionsServiceGet 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 toPromotionsService.updatePromotions(java.util.Collection<de.hybris.platform.promotions.model.PromotionGroupModel>, de.hybris.platform.core.model.order.AbstractOrderModel)for the same order. If any of the promotion results are invalid then this method will recalculate the promotions by callingPromotionsService.updatePromotions(java.util.Collection<de.hybris.platform.promotions.model.PromotionGroupModel>, de.hybris.platform.core.model.order.AbstractOrderModel).- Specified by:
getPromotionResultsin interfacePromotionsService- Parameters:
promotionGroups- 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
-
transferPromotionsToOrder
public void transferPromotionsToOrder(AbstractOrderModel source, OrderModel target, boolean onlyTransferAppliedPromotions)
Description copied from interface:PromotionsServiceTransfer the promotions applied to a cart to a new order. This is used when an order is created from a cart.- Specified by:
transferPromotionsToOrderin interfacePromotionsService- 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
-
updatePromotions
public PromotionOrderResults updatePromotions(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order)
Description copied from interface:PromotionsServiceUpdate 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 callingPromotionsService.getPromotionResults(de.hybris.platform.core.model.order.AbstractOrderModel).- Specified by:
updatePromotionsin interfacePromotionsService- Parameters:
promotionGroups- The promotion groups to evaluateorder- The order object to update with the results of the promotions- Returns:
- The promotion results
-
updatePromotions
public PromotionOrderResults updatePromotions(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
Description copied from interface:PromotionsServiceUpdate the promotions on the specifiedAbstractOrderModelobject. The resulting promotions can be retrieved later by callingPromotionsService.getPromotionResults(de.hybris.platform.core.model.order.AbstractOrderModel). The order must be calculated before calling this method.PromotionsService.updatePromotions(java.util.Collection<de.hybris.platform.promotions.model.PromotionGroupModel>, de.hybris.platform.core.model.order.AbstractOrderModel)must be called after callingAbstractOrder.recalculate()on theAbstractOrderModel. 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 callingPromotionsService.getPromotionResults(de.hybris.platform.core.model.order.AbstractOrderModel). After this method is called, please call getModelService().refresh(order) or getModelService().save(order).- Specified by:
updatePromotionsin interfacePromotionsService- Parameters:
promotionGroups- 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
-
updatePromotionsInternal
protected PromotionOrderResults updatePromotionsInternal(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
-
updatePromotionsNotThreadSafe
protected PromotionOrderResults updatePromotionsNotThreadSafe(java.util.Collection<PromotionGroupModel> promotionGroups, AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date)
-
getBaseProductsForOrder
protected java.util.Collection<ProductModel> getBaseProductsForOrder(AbstractOrderModel 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:
order- the order- Returns:
- the list of products from the order
-
getBaseProduct
protected ProductModel getBaseProduct(ProductModel product)
Return the base product for the product specified. Returns the current product if the product is not an instance of VariantProduct and the result of VariantProductModel.getBaseProduct() if it is.- Parameters:
product- The product to get the base product for- Returns:
- the base product for the product specified
-
getBaseProducts
protected java.util.List<ProductModel> getBaseProducts(ProductModel product)
This is a recursive variant of the method above.
-
getBaseProducts
protected void getBaseProducts(ProductModel product, java.util.List<ProductModel> result)
Internal recursive method to get all base products of a given product.- Parameters:
product-result-
-
findOrderAndProductPromotionsSortByPriority
public java.util.List<AbstractPromotionModel> findOrderAndProductPromotionsSortByPriority(java.util.Collection<PromotionGroupModel> promotionGroups, java.util.Collection<ProductModel> 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:
promotionGroups- 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
-
updateForActivePromotions
protected double updateForActivePromotions(AbstractOrderModel order, boolean evaluateRestrictions, PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, java.util.Date date, java.util.List<java.lang.String> promotionResultsToKeepApplied, java.util.List<PromotionResultModel> results, double newTotalAppliedDiscount, java.util.List<AbstractPromotionModel> activePromotions)
-
fixupVouchersRemoveVouchers
protected java.util.List<VoucherModel> fixupVouchersRemoveVouchers(AbstractOrderModel 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:
order- the order to fixup
-
fixupVouchersReapplyVouchers
protected void fixupVouchersReapplyVouchers(AbstractOrderModel order, java.util.List<VoucherModel> 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:
order- the order to fixupvouchers- the vouchers to reapply
-
isDiscountAbsolute
protected boolean isDiscountAbsolute(DiscountModel discount)
-
evaluatePromotion
protected java.util.List<PromotionResultModel> evaluatePromotion(PromotionEvaluationContext promoContext, AbstractPromotionModel promotion)
-
autoApplyApplies
protected boolean autoApplyApplies(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotionModel promotion)
-
keepApplied
protected boolean keepApplied(PromotionsManager.AutoApplyMode productPromotionMode, PromotionsManager.AutoApplyMode orderPromotionMode, AbstractPromotionModel promotion, boolean autoApply)
-
refreshOrder
protected void refreshOrder(AbstractOrderModel order)
-
saveIfModified
protected void saveIfModified(AbstractOrderModel order)
-
checkLegacyMode
protected void checkLegacyMode()
-
getRestrictions
public java.util.Collection<AbstractPromotionRestrictionModel> getRestrictions(AbstractPromotionModel promotion)
Description copied from interface:PromotionsServiceGet the collection ofAbstractPromotionRestrictionModelinstances.- Specified by:
getRestrictionsin interfacePromotionsService- Parameters:
promotion- the promotion which restrictions should be returned- Returns:
- A collection of
AbstractPromotionRestrictionModelinstances attached to this promotion.
-
getPromotionDescription
public java.lang.String getPromotionDescription(AbstractPromotionModel promotion)
Description copied from interface:PromotionsServiceGet the description of given promotion.- Specified by:
getPromotionDescriptionin interfacePromotionsService- Parameters:
promotion- the promotion to get the description for- Returns:
- String representing promotion description
-
setFlexibleSearchService
public void setFlexibleSearchService(FlexibleSearchService flexibleSearchService)
-
getFlexibleSearchService
protected FlexibleSearchService getFlexibleSearchService()
-
setCalculationService
public void setCalculationService(CalculationService calculationService)
-
getCalculationService
protected CalculationService getCalculationService()
-
getLegacyModeChecker
protected LegacyModeChecker getLegacyModeChecker()
-
setLegacyModeChecker
public void setLegacyModeChecker(LegacyModeChecker legacyModeChecker)
-
-