Class AbstractPromotion

All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
GeneratedOrderPromotion, GeneratedProductPromotion, GeneratedRuleBasedPromotion

public abstract class AbstractPromotion extends GeneratedAbstractPromotion
AbstractPromotion. The base class for all promotions.
See Also:
  • Constructor Details

    • AbstractPromotion

      public AbstractPromotion()
  • Method Details

    • createItem

      protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
      Create the item.
      Overrides:
      createItem in class GeneratedAbstractPromotion
      Parameters:
      ctx - the current session context which this item is created within
      type - the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )
      Returns:
      the new item instance
      Throws:
      JaloBusinessException - indicates an error during creation - any changes will be rollbacked
    • remove

      public void remove(SessionContext ctx) throws ConsistencyCheckException
      Remove the item. When the promotion is removed any associated restriction items are also removed.
      Overrides:
      remove in class Item
      Parameters:
      ctx - A SessionContext object
      Throws:
      ConsistencyCheckException - if this item could not be removed for some reason
    • toString

      public String toString()
      Get a simple description of promotion object.
      Overrides:
      toString in class Item
      Returns:
      string with type name, code and PK.
    • getPromotionType

      public String getPromotionType(SessionContext ctx)
      Return the type name for this promotion instance.
      Specified by:
      getPromotionType in class GeneratedAbstractPromotion
      Parameters:
      ctx - The hybris context
      Returns:
      the type name for this instance.
    • getAllPromotionType

      public Map getAllPromotionType(SessionContext ctx)
      Get promotionType for all supported languages.
      Specified by:
      getAllPromotionType in class GeneratedAbstractPromotion
      Parameters:
      ctx - The hybris context
      Returns:
      a map of the type names keyed by language.
    • setPromotionGroup

      public void setPromotionGroup(SessionContext ctx, PromotionGroup promotionGroup)
      Override the default behaviour to prevent PromotionGroup from being set to null.
      Overrides:
      setPromotionGroup in class GeneratedAbstractPromotion
      Parameters:
      ctx - The hybris context
      promotionGroup - The promotion group to set
    • evaluate

      public abstract List<PromotionResult> evaluate(SessionContext ctx, PromotionEvaluationContext promoContext)
      Evaluate whether a promotion can fire or not.
      Parameters:
      ctx - The context to run the operation in
      promoContext - The evaluation context
      Returns:
      the list of promotion results that this promotions creates
    • getResultDescription

      public abstract String getResultDescription(SessionContext ctx, PromotionResult promotionResult, Locale locale)
      Get a localized user presentable description for the result of this promotion.
      Parameters:
      ctx - The context
      promotionResult - The promotion result to be described
      locale - The locale to use to generate the message
      Returns:
      a string description
    • getPriceForOrder

      protected final Double getPriceForOrder(SessionContext ctx, Collection<PromotionPriceRow> prices, AbstractOrder order, String fieldLabel)
      Lookup the price for an order. Lookup the price for the currency specified on the order.
      Parameters:
      ctx - The hybris context
      prices - The collection of PromotionPriceRow which is the set of prices
      order - The order to lookup the price for
      fieldLabel - A string label to use when generating error messages.
      Returns:
      The price for the order's currency or null if not specified
    • formatMessage

      protected static final String formatMessage(String pattern, Object[] arguments, Locale locale)
      Format a message pattern using the MessageFormat
      Parameters:
      pattern - the message pattern
      arguments - the arguments to pass into the pattern
      locale - the rendering locale
      Returns:
      a formatted string
    • findOrCreateImmutableClone

      protected final AbstractPromotion findOrCreateImmutableClone(SessionContext ctx)
      Find or create an immutable clone of this promotion.
      Parameters:
      ctx - the hybris context
      Returns:
      the immutable version of this promotion
    • buildMD5Hash

      protected static final String buildMD5Hash(String message)
    • createImmutableDeepClone

      protected final AbstractPromotion createImmutableDeepClone(SessionContext ctx, String immutableKeyHash, String immutableKey)
    • findImmutablePromotionByUniqueKey

      protected static final AbstractPromotion findImmutablePromotionByUniqueKey(JaloSession jaloSession, SessionContext ctx, String immutableKeyHash, String immutableKey)
    • getDataUniqueKey

      protected final String getDataUniqueKey(SessionContext ctx)
      Build a unique data driven key. Build a unique key that is data driven. This will uniquely identify the rules used in this promotion and will form the immutable key for stored promotions.
      Parameters:
      ctx - The hybris context
      Returns:
      A StringBuilder used to build up the immutable key
    • buildDataUniqueKey

      protected void buildDataUniqueKey(SessionContext ctx, StringBuilder builder)
      Build a unique data driven key. Build a unique key that is data driven. This will uniquely identify the rules used in this promotion and will form the immutable key for stored promotions. This method may be overridden in a subclass to customize the identifier.
      Parameters:
      ctx - The hybris context
      builder - A StringBuilder used to build up the immutable key
    • deepCloneAttributes

      protected void deepCloneAttributes(SessionContext ctx, Map values)
      Called to deep clone attributes of this instance. The values map contains all the attributes defined on this instance. The map will be used to initialize a new instance of the Action that is a clone of this instance. This method can remove, replace or add to the Map of attributes.
      Parameters:
      ctx - The hybris context
      values - The map to write into
    • deepClonePriceRows

      protected static final Collection<PromotionPriceRow> deepClonePriceRows(SessionContext ctx, Collection<PromotionPriceRow> priceRows)
    • buildDataUniqueKeyForPriceRows

      protected static final void buildDataUniqueKeyForPriceRows(SessionContext ctx, StringBuilder builder, Collection<PromotionPriceRow> priceRows)
    • buildDataUniqueKeyForProducts

      protected static final void buildDataUniqueKeyForProducts(SessionContext ctx, StringBuilder builder, Collection<Product> products)
    • buildDataUniqueKeyForCategories

      protected static final void buildDataUniqueKeyForCategories(SessionContext ctx, StringBuilder builder, Collection<Category> categories)
    • getRestrictions

      public final Collection getRestrictions(SessionContext ctx)
      Get the collection of AbstractPromotionRestriction instances.
      Specified by:
      getRestrictions in class GeneratedAbstractPromotion
      Parameters:
      ctx - The hybris session context
      Returns:
      A collection of AbstractPromotionRestriction instances attached to this promotion.
    • setRestrictions

      public final void setRestrictions(SessionContext ctx, Collection restrictions)
      Set the collection of AbstractPromotionRestriction instance. The AbstractPromotionRestriction instances associated with this promotion are owned (and part of) this promotion. They cannot belong to another instance, therefore when setting the collection any AbstractPromotionRestriction instances previously associated with this promotion, that are no longer associated are deleted from the database.
      Specified by:
      setRestrictions in class GeneratedAbstractPromotion
      Parameters:
      ctx - The hybris session context
      restrictions - the collection of restrictions
    • deletePromotionPriceRows

      public static void deletePromotionPriceRows(SessionContext ctx, Collection<PromotionPriceRow> prices) throws ConsistencyCheckException
      Helper method to delete promotion price rows from the database.
      Parameters:
      ctx - The hybris context
      prices - The prices to delete
      Throws:
      ConsistencyCheckException
    • getPromotionResultDataUnigueKey

      protected final String getPromotionResultDataUnigueKey(SessionContext ctx, PromotionResult 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 the buildPromotionResultDataUnigueKey(de.hybris.platform.jalo.SessionContext, de.hybris.platform.promotions.jalo.PromotionResult, java.lang.StringBuilder) method to allow subclasses to affect the way the identifier is built.

      Parameters:
      ctx - The hybris context
      promotionResult - The promotion result
      Returns:
      a string that identifies this promotion result
    • buildPromotionResultDataUnigueKey

      protected void buildPromotionResultDataUnigueKey(SessionContext ctx, PromotionResult promotionResult, StringBuilder builder)
      Build a unique identifier for a PromotionResult. This method is called from getPromotionResultDataUnigueKey(de.hybris.platform.jalo.SessionContext, de.hybris.platform.promotions.jalo.PromotionResult). This method may be overridden by a subclass to customize how the identifier is built.
      Parameters:
      ctx - The hybris context
      promotionResult - The promotion result
      builder - A StringBuilder used to build up the identifier