Class PromotionResult

    • Constructor Detail

      • PromotionResult

        public PromotionResult()
    • Method Detail

      • 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.

        The Locale specified 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 the GeneratedAbstractOrder.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.

        The Locale specified 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 the GeneratedAbstractOrder.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 context
        locale - 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 context
        includeCouldFirePromotions - 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 context
        action - The action to add
      • addConsumedEntry

        public void addConsumedEntry​(SessionContext ctx,
                                     PromotionOrderEntryConsumed poec)
        Adds a consumed entry to the current result.
        Parameters:
        ctx - the hybris context
        poec - the entry to add
      • removeConsumedEntry

        public void removeConsumedEntry​(SessionContext ctx,
                                        PromotionOrderEntryConsumed poec)
        Removes a consumed entry from the current result.
        Parameters:
        ctx - the hybris context
        poec - 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 context
        target - 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 context
        target - 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 context
        source - the consumed entry to clone
        allTargetEntries - 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 entries
        entryNumber - the entry number to search for
        Returns:
        the order entry with the entry number specified or null of not found.
      • setConsumedEntries

        public void setConsumedEntries​(SessionContext ctx,
                                       java.util.Collection promotionOrderEntryConsumeds)
        Sets the collection of PromotionOrderEntryConsumed consumed.

        The PromotionOrderEntryConsumed instances associated with this promotion result are owned (and part of) this result. They cannot belong to another instance, therefore when setting the collection any PromotionOrderEntryConsumed instances previously associated with this result, that are no longer associated are deleted from the database.

        Specified by:
        setConsumedEntries in class GeneratedPromotionResult
        Parameters:
        ctx - The hybris session context
        promotionOrderEntryConsumeds - the collection of consumed entries
      • setActions

        public void setActions​(SessionContext ctx,
                               java.util.Collection actions)
        Sets the collection of AbstractPromotionAction instance.

        The AbstractPromotionAction instances associated with this promotion result are owned (and part of) this result. They cannot belong to another instance, therefore when setting the collection any AbstractPromotionAction instances previously associated with this result, that are no longer associated are deleted from the database.

        Specified by:
        setActions in class GeneratedPromotionResult
        Parameters:
        ctx - The hybris session context
        actions - 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