Class AbstractPromotion

    • Constructor Detail

      • AbstractPromotion

        public AbstractPromotion()
    • Method Detail

      • toString

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

        public java.lang.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 java.util.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.
      • evaluate

        public abstract java.util.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 java.lang.String getResultDescription​(SessionContext ctx,
                                                              PromotionResult promotionResult,
                                                              java.util.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 java.lang.Double getPriceForOrder​(SessionContext ctx,
                                                          java.util.Collection<PromotionPriceRow> prices,
                                                          AbstractOrder order,
                                                          java.lang.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 java.lang.String formatMessage​(java.lang.String pattern,
                                                              java.lang.Object[] arguments,
                                                              java.util.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 java.lang.String buildMD5Hash​(java.lang.String message)
      • createImmutableDeepClone

        protected final AbstractPromotion createImmutableDeepClone​(SessionContext ctx,
                                                                   java.lang.String immutableKeyHash,
                                                                   java.lang.String immutableKey)
      • findImmutablePromotionByUniqueKey

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

        protected final java.lang.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,
                                          java.lang.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,
                                           java.util.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
      • buildDataUniqueKeyForPriceRows

        protected static final void buildDataUniqueKeyForPriceRows​(SessionContext ctx,
                                                                   java.lang.StringBuilder builder,
                                                                   java.util.Collection<PromotionPriceRow> priceRows)
      • buildDataUniqueKeyForProducts

        protected static final void buildDataUniqueKeyForProducts​(SessionContext ctx,
                                                                  java.lang.StringBuilder builder,
                                                                  java.util.Collection<Product> products)
      • buildDataUniqueKeyForCategories

        protected static final void buildDataUniqueKeyForCategories​(SessionContext ctx,
                                                                    java.lang.StringBuilder builder,
                                                                    java.util.Collection<Category> categories)