Class PromotionResult
- java.lang.Object
-
- de.hybris.platform.util.BridgeAbstraction
-
- de.hybris.platform.jalo.Item
-
- de.hybris.platform.jalo.ExtensibleItem
-
- de.hybris.platform.jalo.c2l.LocalizableItem
-
- de.hybris.platform.jalo.GenericItem
-
- de.hybris.platform.promotions.jalo.GeneratedPromotionResult
-
- de.hybris.platform.promotions.jalo.PromotionResult
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable
- Direct Known Subclasses:
GeneratedCachedPromotionResult
public class PromotionResult extends GeneratedPromotionResult
PromotionResult. The result of evaluating a promotion against a cart or order is a set of promotion results. Each promotion my produce zero or more results to express the results of its evaluation. APromotionResultis associated with a singleAbstractPromotionand is either fired (getFired()) or potentially could fire (getCouldFire()). A result that has fired as met all the requirements of the promotion. A result that potentially could fire has not met all the requirements of the promotion. When the result could fire the promotion also assigns a certainty (GeneratedPromotionResult.getCertainty()) value to the result to indicate how close the result is to firing. This is a value in the range 0 to 1, where 1 indicates that the promotion has fired. This value can be used to rank potential promotion results. A promotion result holds a number ofPromotionOrderEntryConsumedinstances to represent the entries in the order that have been consumed by the promotion in generating this result. If the promotion has fired then these consumed entries are not available to other promotions. If the promotion has not fired then these consumed entries are just an indication of the entries that will be consumed when the promotion can fire. If the promotion has fired the promotion result also holds a number ofAbstractPromotionActioninstances to represent the actions that the promotion takes. These actions are either applied or not (isApplied()). When the promotions are evaluated byPromotionsManager.updatePromotions(SessionContext, Collection, de.hybris.platform.jalo.order.AbstractOrder, boolean, de.hybris.platform.promotions.jalo.PromotionsManager.AutoApplyMode, de.hybris.platform.promotions.jalo.PromotionsManager.AutoApplyMode, java.util.Date)a firing promotion result may be automatically applied depending on the parameters passed to the method. The actions of a specific promotion result can be applied by calling theapply()method. The actions of a specific promotion result can be reversed by calling theundo()method.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.GenericItem
GenericItem.GenericItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LocalizableItem.LocalizableItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.ExtensibleItem
ExtensibleItem.ExtensibleItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.Item
Item.AttributeFilter, Item.AttributeMode, Item.CachedGetter, Item.CachedSetter, Item.ItemAttributeMap, Item.ItemConstraint, Item.ItemImpl, Item.JaloCachedComputationException
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.promotions.jalo.GeneratedPromotionResult
ACTIONS, ALLPROMOTIONACTIONS, ALLPROMOTIONACTIONSHANDLER, CERTAINTY, CONSUMEDENTRIES, CUSTOM, DEFAULT_INITIAL_ATTRIBUTES, ORDER, ORDERHANDLER, PROMOTION
-
Fields inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LANGUAGE_FALLBACK_ENABLED
-
Fields inherited from class de.hybris.platform.jalo.Item
_CREATION_TIME_INTERNAL, _MODIFIED_TIME_INTERNAL, accessorLog, CREATION_TIME, DISABLE_ATTRIBUTE_CHECK, DISABLE_ITEMCHECK_BEFORE_REMOVABLE, EVEN, FEATURE_ACCESSMAP_QUALIFIER, HJMPTS, INITIAL_CREATION_FLAG, isJaloOnly, MODIFIED_TIME, NEGATIVE, NOT_FOUND, OWNER, PK, POSITIVE, SAVE_FROM_SERVICE_LAYER, staticTransientObjects, TYPE
-
Fields inherited from class de.hybris.platform.util.BridgeAbstraction
impl, tenant
-
-
Constructor Summary
Constructors Constructor Description PromotionResult()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAction(SessionContext ctx, AbstractPromotionAction action)Adds an action to the promotion results.voidaddConsumedEntry(SessionContext ctx, PromotionOrderEntryConsumed poec)Adds a consumed entry to the current result.booleanapply()Applies all of the actions that this promotion generated to the order.booleanapply(SessionContext ctx)Applies all of the actions that this promotion generated to the order.protected java.util.Collection<AbstractPromotionAction>deepCloneAllActions(SessionContext ctx)Clones all the actions attached to this promotion result.protected java.util.Collection<PromotionOrderEntryConsumed>deepCloneConsumedEntriesAndAttachToOrder(SessionContext ctx, Order target)Clones of the consumed order entries attached to this promotion result and attach them to order entries in the specified order.protected static PromotionOrderEntryConsumeddeepCloneConsumedEntryAndAttachToOrder(SessionContext ctx, PromotionOrderEntryConsumed source, java.util.List<AbstractOrderEntry> allTargetEntries)Clones a consumed order entry and attach it to an order entry from the list specified.protected static AbstractOrderEntryfindOrderEntryWithEntryNumber(java.util.List<AbstractOrderEntry> allTargetEntries, int entryNumber)Finds the order entry with the specified entry number.java.util.CollectiongetActions(SessionContext ctx)Gets the collection ofAbstractPromotionActioninstances.longgetConsumedCount(boolean includeCouldFirePromotions)Gets the total number of items consumed by this promotion.longgetConsumedCount(SessionContext ctx, boolean includeCouldFirePromotions)Gets the total number of items consumed by this promotion.java.util.CollectiongetConsumedEntries(SessionContext ctx)Gets the collection ofPromotionOrderEntryConsumedconsumed.booleangetCouldFire()Is this a potential result.booleangetCouldFire(SessionContext ctx)Is this a potential result.protected java.lang.StringgetDataUnigueKey(SessionContext ctx)Generates a string identifier that can be used to establish if 2 PromotionResults are the same.java.lang.StringgetDescription()Gets the description of this promotion result.java.lang.StringgetDescription(SessionContext ctx, java.util.Locale locale)Gets the description of this promotion result.java.lang.StringgetDescription(java.util.Locale locale)Gets the description of this promotion result.booleangetFired()Returns true if the promotion fired and has produced a result.booleangetFired(SessionContext ctx)Returns true if the promotion fired and has produced a result.doublegetTotalDiscount()Gets the total value of all discounts in this result.doublegetTotalDiscount(SessionContext ctx)Gets the total value of all discounts in this result.booleanisApplied()Returns true if the promotion fired and all of its actions have been applied to the order.booleanisApplied(SessionContext ctx)Returns true if the promotion fired and all of its actions have been applied to the order.booleanisAppliedToOrder(SessionContext ctx)Returns true if the promotion fired and all of its actions have been applied to the order.protected booleanisValid(SessionContext ctx)Is this promotion result valid.voidremove(SessionContext ctx)Removes the item.voidremoveConsumedEntry(SessionContext ctx, PromotionOrderEntryConsumed poec)Removes a consumed entry from the current result.voidsetActions(SessionContext ctx, java.util.Collection actions)Sets the collection ofAbstractPromotionActioninstance.voidsetConsumedEntries(SessionContext ctx, java.util.Collection promotionOrderEntryConsumeds)Sets the collection ofPromotionOrderEntryConsumedconsumed.PromotionResulttransferToOrder(SessionContext ctx, Order target)Creates a deep clone of this promotion result and attach it to the specified order.booleanundo()Undoes all of the changes that this promotion made to the order.booleanundo(SessionContext ctx)Undoes all of the changes that this promotion made to the order.-
Methods inherited from class de.hybris.platform.promotions.jalo.GeneratedPromotionResult
addToAllPromotionActions, addToAllPromotionActions, createItem, getActions, getAllPromotionActions, getAllPromotionActions, getCertainty, getCertainty, getCertaintyAsPrimitive, getCertaintyAsPrimitive, getConsumedEntries, getCustom, getCustom, getDefaultAttributeModes, getOrder, getOrder, getPromotion, getPromotion, removeFromAllPromotionActions, removeFromAllPromotionActions, setActions, setAllPromotionActions, setAllPromotionActions, setCertainty, setCertainty, setCertainty, setCertainty, setConsumedEntries, setCustom, setCustom, setOrder, setOrder, setPromotion, setPromotion
-
Methods inherited from class de.hybris.platform.jalo.GenericItem
getImplementation, getInitialProperties, getNonInitialAttributes, getRelatedItems, setRelatedItems
-
Methods inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllValuesSessionContext, getLocalizedProperty, getLocalizedProperty, getLocalizedPropertyInternal, getLocalizedPropertyNames, getLocalizedPropertyNames, hasLanguage, isEmptyValue, isFallbackEnabled, removeLocalizedProperty, removeLocalizedProperty, setAllLocalizedProperties, setAllLocalizedProperties, setLocalizedProperty, setLocalizedProperty
-
Methods inherited from class de.hybris.platform.jalo.ExtensibleItem
createNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setProperty
-
Methods inherited from class de.hybris.platform.jalo.Item
addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addNegativePermission, addPermission, addPositivePermission, assureExtensionsLoaded, changeTypeAfterCreation, checkConstraint, checkItemPermission, checkMandatoryAttribute, checkMandatoryAttribute, checkPermission, checkPermission, checkRemovable, clearPermission, compareTo, ctx, doAfterRemove, doBeforeRemove, equals, getAccessorFor, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributesInternal, getAllLinkedItems, getAndCheckCacheBoundItem, getAttribute, getAttribute, getCacheBoundItem, getComposedType, getComposedTypePK, getCreationTime, getCurrentlyRemovingCount, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItemsCount, getLinkedItemsCount, getLinkedItemsCount, getModificationTime, getNegativePermissions, getOwner, getPermissionMap, getPermissions, getPersistenceVersion, getPK, getPositivePermissions, getRestrictedPrincipals, getSession, getSyncObject, getTenant, getTransientObject, getTransientObjectMap, hashCode, hasRegisteredClassAccessorFor, internal_registerClassAccessorFor, internal_registerNonClassAccessorFor, invalidateLocalCaches, isAlive, isCacheBound, isCurrentlyRemoving, isCurrentlyRemoving, isEmptyRelationValue, isInCreate, isInstanceOf, isItemCheckBeforeRemoveableDisabled, isMarkModifiedDisabled, isRelationLocalizationFallbackEnabled, newInstance, notifyExtensionsAfterItemCreation, notifyExtensionsBeforeItemCreation, notifyItemRemoval, notifyManagerAboutItemRemoval, readResolve, registerAccessFor, registerAccessFor, registerJaloInvalidationListeners, remove, removeItemCollection, removeItemCollection, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinks, removePartOfItems, removePartOfItems, setAllAttributes, setAllAttributes, setAllAttributesInternal, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAttribute, setAttribute, setAttributeFromString, setAttributeFromString, setCacheBound, setComposedType, setCreationTime, setImplementation, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setModificationTime, setNonInitialAttributes, setOwner, setPermissionsByMap, setTransientObject, setUseTA, toString, useTA, writeReplace
-
Methods inherited from class de.hybris.platform.util.BridgeAbstraction
setTenant
-
-
-
-
Method Detail
-
remove
public void remove(SessionContext ctx) throws ConsistencyCheckException
Removes the item. When this item is removed the associated consumed order entries and actions will also be removed.- Overrides:
removein classItem- Parameters:
ctx- A SessionContext object- Throws:
ConsistencyCheckException- if this item could not be removed for some reason
-
isApplied
public final boolean isApplied()
Returns true if the promotion fired and all of its actions have been applied to the order.- Returns:
- Whether the promotion has been applied
-
isApplied
public boolean isApplied(SessionContext ctx)
Returns true if the promotion fired and all of its actions have been applied to the order. This method just checks that all the actions have been asked to apply themselves to the order.- Parameters:
ctx- The hybris session context- Returns:
- Whether the promotion has been applied
-
isAppliedToOrder
public boolean isAppliedToOrder(SessionContext ctx)
Returns true if the promotion fired and all of its actions have been applied to the order. This method checks that all the actions are still applied to the order.- Parameters:
ctx- The hybris session context- Returns:
- Whether the promotion has been applied
-
getFired
public final boolean getFired()
Returns true if the promotion fired and has produced a result.- Returns:
- Whether the promotion fired
-
getFired
public boolean getFired(SessionContext ctx)
Returns true if the promotion fired and has produced a result. When the certainty is 1 the promotion has fired.- Parameters:
ctx- The hybris session context- Returns:
- Whether the promotion fired
-
getCouldFire
public final boolean getCouldFire()
Is this a potential result. Returns true if the promotion believes it has a chance of firing, for instance if it requires 3 qualifying products but can only find 1.- Returns:
- Whether the promotion could fire
-
getCouldFire
public boolean getCouldFire(SessionContext ctx)
Is this a potential result. Returns true if the promotion believes it has a chance of firing, for instance if it requires 3 qualifying products but can only find 1. When the certainty is less than 1 the promotion has not fired.- Parameters:
ctx- The hybris session context- Returns:
- Whether the promotion could fire
-
getDescription
public final java.lang.String getDescription()
Gets the description of this promotion result. This method uses the default locale (Locale.getDefault())- Returns:
- A description of the promotion result
- See Also:
getDescription(java.util.Locale)
-
getDescription
public final java.lang.String getDescription(java.util.Locale locale)
Gets the description of this promotion result. Gets the description for this promotion result. This description is based on the state of the result, the promotion that generated the result and the user supplied formatting strings. TheLocalespecified is used to format any numbers, dates or currencies for display to the user. It is important that this locale best represents the formatting options appropriate for display to the user. The default currency for the locale is ignored. The currency is always explicitly taken from theGeneratedAbstractOrder.getCurrency(). The currency is then formatted appropriately in the locale specified. For example, this does mean that values in the EURO currency will be formatted differently depending on the locale specified as each locale can specify currency specific formatting. The currency formatting is part of the Java VM configuration to support multiple locales. If the formatting is incorrect check your VM configuration for the locale and currency combination.- Parameters:
locale- The locale to use to format the messages. This locale must support currency formatting, i.e. this should be a region specific local. e.g de_DE, en_US, en_GB- Returns:
- A description of the promotion result
-
getDescription
public java.lang.String getDescription(SessionContext ctx, java.util.Locale locale)
Gets the description of this promotion result. Gets the description for this promotion result. This description is based on the state of the result, the promotion that generated the result and the user supplied formatting strings. TheLocalespecified is used to format any numbers, dates or currencies for display to the user. It is important that this locale best represents the formatting options appropriate for display to the user. The default currency for the locale is ignored. The currency is always explicitly taken from theGeneratedAbstractOrder.getCurrency(). The currency is then formatted appropriately in the locale specified. For example, this does mean that values in the EURO currency will be formatted differently depending on the locale specified as each locale can specify currency specific formatting. The currency formatting is part of the Java VM configuration to support multiple locales. If the formatting is incorrect check your VM configuration for the locale and currency combination.- Parameters:
ctx- The hybris session contextlocale- The locale to use to format the messages. This locale must support currency formatting, i.e. this must be a region specific local. e.g de_DE, en_US, en_GB- Returns:
- A description of the promotion result
-
apply
public final boolean apply()
Applies all of the actions that this promotion generated to the order.- Returns:
- true if calculateTotals() should be called to update the order totals.
-
apply
public boolean apply(SessionContext ctx)
Applies all of the actions that this promotion generated to the order.- Parameters:
ctx- The hybris session context- Returns:
- true if calculateTotals() should be called to update the order totals.
-
undo
public final boolean undo()
Undoes all of the changes that this promotion made to the order.- Returns:
- true if calculateTotals() should be called to update the order totals.
-
undo
public boolean undo(SessionContext ctx)
Undoes all of the changes that this promotion made to the order.- Parameters:
ctx- The hybris session context- Returns:
- true if calculateTotals() should be called to update the order totals.
-
getConsumedCount
public final long getConsumedCount(boolean includeCouldFirePromotions)
Gets the total number of items consumed by this promotion.- Parameters:
includeCouldFirePromotions- include could fire promotions- Returns:
- The total number of items consumed
-
getConsumedCount
public long getConsumedCount(SessionContext ctx, boolean includeCouldFirePromotions)
Gets the total number of items consumed by this promotion.- Parameters:
ctx- The hybris session contextincludeCouldFirePromotions- include could fire promotions- Returns:
- The total number of items consumed
-
getTotalDiscount
public final double getTotalDiscount()
Gets the total value of all discounts in this 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
-
getTotalDiscount
public double getTotalDiscount(SessionContext ctx)
Gets the total value of all discounts in this 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.- Parameters:
ctx- The session context- Returns:
- The double value for the total discount value
-
isValid
protected boolean isValid(SessionContext ctx)
Is this promotion result valid. This method checks to ensure that the promotion exists.- Parameters:
ctx- The hybris context- Returns:
- true if the promotion result is valid
-
addAction
public void addAction(SessionContext ctx, AbstractPromotionAction action)
Adds an action to the promotion results.- Parameters:
ctx- The hybris contextaction- The action to add
-
addConsumedEntry
public void addConsumedEntry(SessionContext ctx, PromotionOrderEntryConsumed poec)
Adds a consumed entry to the current result.- Parameters:
ctx- the hybris contextpoec- the entry to add
-
removeConsumedEntry
public void removeConsumedEntry(SessionContext ctx, PromotionOrderEntryConsumed poec)
Removes a consumed entry from the current result.- Parameters:
ctx- the hybris contextpoec- the entry to remove
-
transferToOrder
public PromotionResult transferToOrder(SessionContext ctx, Order target)
Creates a deep clone of this promotion result and attach it to the specified order.- Parameters:
ctx- The hybris contexttarget- the target order to transfer to- Returns:
- the cloned promotion result
-
deepCloneAllActions
protected java.util.Collection<AbstractPromotionAction> deepCloneAllActions(SessionContext ctx)
Clones all the actions attached to this promotion result.- Parameters:
ctx- the hybris context- Returns:
- the cloned actions
-
deepCloneConsumedEntriesAndAttachToOrder
protected java.util.Collection<PromotionOrderEntryConsumed> deepCloneConsumedEntriesAndAttachToOrder(SessionContext ctx, Order target)
Clones of the consumed order entries attached to this promotion result and attach them to order entries in the specified order.- Parameters:
ctx- the hybris contexttarget- the target order to attach the consumed order entries to- Returns:
- the cloned order entries
-
deepCloneConsumedEntryAndAttachToOrder
protected static PromotionOrderEntryConsumed deepCloneConsumedEntryAndAttachToOrder(SessionContext ctx, PromotionOrderEntryConsumed source, java.util.List<AbstractOrderEntry> allTargetEntries)
Clones a consumed order entry and attach it to an order entry from the list specified.- Parameters:
ctx- the hybris contextsource- the consumed entry to cloneallTargetEntries- the list of order entries in the target order- Returns:
- the cloned consumed order entry
-
findOrderEntryWithEntryNumber
protected static AbstractOrderEntry findOrderEntryWithEntryNumber(java.util.List<AbstractOrderEntry> allTargetEntries, int entryNumber)
Finds the order entry with the specified entry number.- Parameters:
allTargetEntries- the list of order entriesentryNumber- the entry number to search for- Returns:
- the order entry with the entry number specified or null of not found.
-
getConsumedEntries
public java.util.Collection getConsumedEntries(SessionContext ctx)
Gets the collection ofPromotionOrderEntryConsumedconsumed.- Specified by:
getConsumedEntriesin classGeneratedPromotionResult- Parameters:
ctx- The hybris session context- Returns:
- A collection of
PromotionOrderEntryConsumedconsumed by this result.
-
setConsumedEntries
public void setConsumedEntries(SessionContext ctx, java.util.Collection promotionOrderEntryConsumeds)
Sets the collection ofPromotionOrderEntryConsumedconsumed. ThePromotionOrderEntryConsumedinstances associated with this promotion result are owned (and part of) this result. They cannot belong to another instance, therefore when setting the collection anyPromotionOrderEntryConsumedinstances previously associated with this result, that are no longer associated are deleted from the database.- Specified by:
setConsumedEntriesin classGeneratedPromotionResult- Parameters:
ctx- The hybris session contextpromotionOrderEntryConsumeds- the collection of consumed entries
-
getActions
public java.util.Collection getActions(SessionContext ctx)
Gets the collection ofAbstractPromotionActioninstances.- Specified by:
getActionsin classGeneratedPromotionResult- Parameters:
ctx- The hybris session context- Returns:
- A collection of
AbstractPromotionActioninstances attached to this result.
-
setActions
public void setActions(SessionContext ctx, java.util.Collection actions)
Sets the collection ofAbstractPromotionActioninstance. TheAbstractPromotionActioninstances associated with this promotion result are owned (and part of) this result. They cannot belong to another instance, therefore when setting the collection anyAbstractPromotionActioninstances previously associated with this result, that are no longer associated are deleted from the database.- Specified by:
setActionsin classGeneratedPromotionResult- Parameters:
ctx- The hybris session contextactions- the collection of actions
-
getDataUnigueKey
protected java.lang.String getDataUnigueKey(SessionContext ctx)
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:
ctx- The hybris context- Returns:
- a string that identifies this promotion result
-
-