com.ibm.commerce.marketing.promotion.condition

Class FreeGiftPurchaseCondition

  • java.lang.Object
    • com.ibm.commerce.marketing.promotion.condition.FreeGiftPurchaseCondition
  • All Implemented Interfaces:
    Condition, XMLizable, java.io.Serializable


    public class FreeGiftPurchaseCondition
    extends java.lang.Object
    implements Condition
    The FreeGiftPurchaseCondition is a customized pattern definition for free gift promotions. This pattern definition assumes that there is only one group of base products (specified using the BaseItemSelection node) and one group of gift items (specified using the Gift and GiftQuantity nodes). There are 2 different strategies to handle the free gift if there is a cross section between the base products and the gift groups:
  • ADD_WHEN_NEEDED (0), which indicates that the free gift is added only when there is no purchased item that is the same as the free gift. If a purchased item in the shopping cart is identical to the free gift, then the promotion gives the purchased item a 100% off discount. This option should only be used when such behavior does not interfere with the overall promotion rule. This option turns an existing purchased item into the free gift, which can affect the promotion qualification in some situations.
  • ALWAYS_ADD (1), which indicates that the system always adds the free gift, regardless whether or not the shopper already has an item that is identical to the free gift within the shopping cart. This is the default implementation option.

    XML Snippet for FreeGiftPurchaseCondition:

       <PurchaseCondition impl="com.ibm.commerce.marketing.promotion.condition.FreeGiftPurchaseCondition">
            <BaseItemSelection>
                    <Quantity>5</Quantity>
                    <FilterChain impl="com.ibm.commerce.marketing.promotion.condition.FilterChain">
                            <Filter impl="com.ibm.commerce.marketing.promotion.condition.MultiSKUFilter">
                                    <IncludeCatEntryKey>
                                            <CatalogEntryKey>
                                                    <SKU>ABCD-01</SKU>
                                                    <DN>sample distinguished name</DN>
                                            </CatalogEntryKey>
                                    </IncludeCatEntryKey>
                            </Filter>
                    </FilterChain>
            </BaseItemSelection>
            <GiftQuantity>2</GiftQuantity>
            <Gift>
                    <CatalogEntryKey>
                            <SKU>DCBA-01</SKU>
                            <DN>sample distinguished name</DN>
                    </CatalogEntryKey>
            </Gift>
            <AddStrategy>1</AddStrategy>
       </PurchaseCondition>
     
     
See Also:
Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int ADD_WHEN_NEEDED
      Add gift to the shop cart if shop cart does not contain one
      static int ALWAYS_ADD
      Always add gift to the shop cart
      static java.lang.String COPYRIGHT
      IBM copyright notice field.
      static java.lang.String TAG_ADD_STRATEGY
      XML tag - AddStrategy
      static java.lang.String TAG_MERGE_PATTERN
      XML tag - MergePattern
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean evaluate(PromotionContext context)
      This function finds all the line items that can be targeted by current promotion and groups them into line item sets.
      void fromXML(org.w3c.dom.Node anXMLNode)
      Transforms the XML node into its corresponding real Object.
      int getAddStrategy()
      Gets gift add strategy.
      FilterChain getBaseItemFilterChain()
      This method returns the base item filter chain in the condition.
      java.math.BigDecimal getBaseItemQuantity()
      This method returns the base item quantity in the condition.
      CatalogEntryKey getGiftKey()
      This method returns the CatalogEntryKey of the gift item in the condition.
      java.math.BigDecimal getGiftQuantity()
      This method returns the gift quantity in the condition.
      boolean isMergePattern()
      Gets the merge pattern flag.
      void setAddStrategy(int aAddStrategy)
      Sets the gift add strategy.
      void setBaseItemFilterChain(FilterChain aBaseItemFilters)
      This method sets the base item filter chain in the condition to the passed parameter.
      void setBaseItemQuantity(java.math.BigDecimal aBaseItemQuantity)
      This method sets the base item quantity in the condition to the passed parameter.
      void setGiftKey(CatalogEntryKey aGiftKey)
      This method sets the CatalogEntryKey of the gift item in the condition.
      void setGiftQuantity(java.math.BigDecimal aGiftQuantity)
      This method sets the gift quantity in the condition to the passed parameter.
      void setMergePattern(boolean mergePattern)
      Sets the merge pattern flag.
      java.lang.String toXML()
      Converts the object into its corresponding XML format representation.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM copyright notice field.
        See Also:
        Constant Field Values
      • TAG_ADD_STRATEGY

        public static final java.lang.String TAG_ADD_STRATEGY
        XML tag - AddStrategy
        See Also:
        Constant Field Values
      • TAG_MERGE_PATTERN

        public static final java.lang.String TAG_MERGE_PATTERN
        XML tag - MergePattern
        See Also:
        Constant Field Values
      • ADD_WHEN_NEEDED

        public static final int ADD_WHEN_NEEDED
        Add gift to the shop cart if shop cart does not contain one
        See Also:
        Constant Field Values
      • ALWAYS_ADD

        public static final int ALWAYS_ADD
        Always add gift to the shop cart
        See Also:
        Constant Field Values
    • Constructor Detail

      • FreeGiftPurchaseCondition

        public FreeGiftPurchaseCondition()
        Constructor.
    • Method Detail

      • getAddStrategy

        public int getAddStrategy()
        Gets gift add strategy. Possible values are 0: ADD_WHEN_NEEDED, 1: ALWAYS_ADD,
        Returns:
        the add strategy
      • setAddStrategy

        public void setAddStrategy(int aAddStrategy)
        Sets the gift add strategy. Possible values are 0: ADD_WHEN_NEEDED, 1: ALWAYS_ADD
        Parameters:
        aAddStrategy - The add strategy to set.
      • evaluate

        public boolean evaluate(PromotionContext context)
                         throws PromotionRuntimeException
        This function finds all the line items that can be targeted by current promotion and groups them into line item sets. The constraints that make up the pattern will try to spot as many matched items as possible in a single test. If a matched pattern is found, the method returns true and appends one or more PromotionExecutionRecord (depending on how many times this promotion can be applied to the current order) to the PromotionContext.

        If the promotion does not have redemption limits and is not a coupon promotion, the MergePattern flag is used to improve overall performance by merging all matched items into a single pattern and increase the gift quantity according to number of times this promotion can be applied to the current order. If the business requirement needs to track individual redemption information, the MergePattern flag can be turn off by setting its value to false.

        Specified by:
        evaluate in interface Condition
        Parameters:
        context - PromotionContext
        Returns:
        true if this promotion is applicable, false otherwise
        Throws:
        PromotionRuntimeException - is thrown if the evaluation encounters unexpected problems.
      • getBaseItemFilterChain

        public FilterChain getBaseItemFilterChain()
        This method returns the base item filter chain in the condition.
        Returns:
        the filter chain.
      • setBaseItemFilterChain

        public void setBaseItemFilterChain(FilterChain aBaseItemFilters)
        This method sets the base item filter chain in the condition to the passed parameter.
        Parameters:
        aBaseItemFilters - the filter chain to set
      • getBaseItemQuantity

        public java.math.BigDecimal getBaseItemQuantity()
        This method returns the base item quantity in the condition.
        Returns:
        the baseItemQuantity
      • setBaseItemQuantity

        public void setBaseItemQuantity(java.math.BigDecimal aBaseItemQuantity)
        This method sets the base item quantity in the condition to the passed parameter.
        Parameters:
        aBaseItemQuantity - the baseItemQuantity to set
      • getGiftKey

        public CatalogEntryKey getGiftKey()
        This method returns the CatalogEntryKey of the gift item in the condition.
        Returns:
        the giftKey
      • setGiftKey

        public void setGiftKey(CatalogEntryKey aGiftKey)
        This method sets the CatalogEntryKey of the gift item in the condition.
        Parameters:
        aGiftKey - the giftKey to set
      • getGiftQuantity

        public java.math.BigDecimal getGiftQuantity()
        This method returns the gift quantity in the condition.
        Returns:
        the giftQuantity
      • setGiftQuantity

        public void setGiftQuantity(java.math.BigDecimal aGiftQuantity)
        This method sets the gift quantity in the condition to the passed parameter.
        Parameters:
        aGiftQuantity - the giftQuantity to set
      • isMergePattern

        public boolean isMergePattern()
        Gets the merge pattern flag.
        Returns:
        true or false.
      • setMergePattern

        public void setMergePattern(boolean mergePattern)
        Sets the merge pattern flag.
        Parameters:
        mergePattern - true or false.