com.ibm.commerce.marketing.promotion.reward

Class PercentOffAdjustment

  • java.lang.Object
    • com.ibm.commerce.marketing.promotion.reward.PercentOffAdjustment
  • All Implemented Interfaces:
    Adjustment, MonetaryAdjustment, XMLizable, java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    PercentOffPriceAdjustment, PercentOffShippingAdjustment


    public class PercentOffAdjustment
    extends java.lang.Object
    implements MonetaryAdjustment
    PercentOffAdjustment offers a percentage discount, including a cap on the maximum amount of money to be given as a discount. It provides percentage-off implementation of a monetary adjustment. The fragment of promotion runtime promotion XML for this type of Adjustment is as follows:
     <p>
       <Adjustment impl="com.ibm.commerce.marketing.promotion.reward.PercentOffAdjustment">
          <Percentage>15</Percentage>
          <!-- wholeOrder or AllAffectedItems or IndividualAffectedItems -->
          <AdjustmentType>wholeOrder</AdjustmentType>
          <!-- Max Amount is the cap (optional) -->
          <MaxAmount>20</MaxAmount>
          <!-- If the above Max Amount is provided, the following should be provided too -->
          <Currency>USD</Currency>
          <!-- -1 for Standard Offer Price, -2 for Contract Price, -3 for Discounted Price -->
          <PriceAdjustmentBase>-3</PriceAdjustmentBase>
       </Adjustment>
     </p>
     
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      PercentOffAdjustment()
      Constructor for PercentOffAdjustment.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean apply(LineItemSet targeted, java.math.BigDecimal targetedAmount, int targetedAmountTypes, LineItemSet affected, java.util.Vector affectedVector, java.util.Vector adjustmentVector, PromotionContext context)
      This method evaluates the targeted order items to see if they fulfill the conditions of this adjustment ( for example, if the quantity of the order items falls into one of the ranges of the adjustment).
      java.lang.Object clone()
      Returns null if the CloneNotSupportedException is thrown.
      void fromXML(org.w3c.dom.Node anXMLNode)
      Transforms the XML node into its corresponding real Object.
      java.lang.Integer getAdjustmentType()
      This method gets the type of Adjustment.
      java.lang.String getCurrency()
      This method gets the currency.
      java.math.BigDecimal getMaxAmount()
      This method gets a maximum amount as the discount.
      java.math.BigDecimal getPercent()
      This method gets the percent to be given as discount.
      java.math.BigDecimal getPerUnitAdjustment(AssociatedOrderItem one, AssociatedOrderItem[] all, PromotionContext context)
      This method returns the monetary adjustment that needs to be applied to each unit.
      int getPriceAdjustmentBasis()
      This method gets the price adjustment base.
      int getTheTypeOfMonetaryValueToBeAdjusted()
      Returns the target of a monetary adjustment.
      void setAdjustmentType(java.lang.Integer _adjustmentType)
      This method sets the type of Adjustment.
      void setCurrency(java.lang.String currency)
      This method sets the currency.
      void setMaxAmount(java.math.BigDecimal newMaxAmount)
      This method sets the maximum amount to be given as the discount.
      void setPercent(java.math.BigDecimal newPercent)
      This method sets the percent to be given as discount.
      void setPriceAdjustmentBasis(int priceAdjustmentBasis)
      This method sets the price adjustment base.
      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
      • STANDARD_OFFER_PRICE

        public static final int STANDARD_OFFER_PRICE
        The basis for price adjustment. This flag value means all adjustments are on standard offer price
        See Also:
        Constant Field Values
      • CONTRACT_PRICE

        public static final int CONTRACT_PRICE
        The basis for price adjustment. This flag value means all adjustments are on contract price
        See Also:
        Constant Field Values
      • DISCOUNTED_PRICE

        public static final int DISCOUNTED_PRICE
        The basis for price adjustment. This flag value means all adjustments are on discounted price. That is, the running total of order items after any applicable discounts have been taken into account.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PercentOffAdjustment

        public PercentOffAdjustment()
        Constructor for PercentOffAdjustment.
    • Method Detail

      • getMaxAmount

        public java.math.BigDecimal getMaxAmount()
        This method gets a maximum amount as the discount.
        Returns:
        java.math.BigDecimal Get a maximum amount as the discount.
      • setMaxAmount

        public void setMaxAmount(java.math.BigDecimal newMaxAmount)
        This method sets the maximum amount to be given as the discount.
        Parameters:
        java - .math.BigDecimal newMaxAmount the max amount to set as the discount.
      • getPercent

        public java.math.BigDecimal getPercent()
        This method gets the percent to be given as discount.
        Returns:
        java.math.BigDecimal Percent to be given as discount
      • setPercent

        public void setPercent(java.math.BigDecimal newPercent)
        This method sets the percent to be given as discount.
        Parameters:
        newPercent - Sets the percent to be given as discount.
      • getAdjustmentType

        public java.lang.Integer getAdjustmentType()
        Description copied from interface: Adjustment
        This method gets the type of Adjustment. An adjustment can be of the following types: for the whole Order, for All the Affected Items, or for Individual Affected Items.
        Specified by:
        getAdjustmentType in interface Adjustment
        Returns:
        one of the defined constants of WHOLE_ORDER, ALL_AFFECTED_ITEMS or INDIVIDUAL_AFFECTED_ITEMS.
        See Also:
        Adjustment.getAdjustmentType()
      • setAdjustmentType

        public void setAdjustmentType(java.lang.Integer _adjustmentType)
        Description copied from interface: Adjustment
        This method sets the type of Adjustment. An adjustment can be of the following types for whole Order, for All Affected Items, and for Individual Affected Items. Set adjustmentType to one of the defined constants of WHOLE_ORDER, ALL_AFFECTED_ITEMS or INDIVIDUAL_AFFECTED_ITEMS.
        Specified by:
        setAdjustmentType in interface Adjustment
        See Also:
        Adjustment.setAdjustmentType(Integer)
      • clone

        public java.lang.Object clone()
        Returns null if the CloneNotSupportedException is thrown.
        Specified by:
        clone in interface Adjustment
        Overrides:
        clone in class java.lang.Object
        See Also:
        Object.clone()
      • getTheTypeOfMonetaryValueToBeAdjusted

        public int getTheTypeOfMonetaryValueToBeAdjusted()
        Description copied from interface: MonetaryAdjustment
        Returns the target of a monetary adjustment. Possible values are: SUBTOTAL=1, SHIPPING=2, SHIPPING_TAX=4, TAX=8.
        Specified by:
        getTheTypeOfMonetaryValueToBeAdjusted in interface MonetaryAdjustment
        Returns:
        target of a monetary adjustment
        See Also:
        com.ibm.commerce.marketing.promotion.reward.MonetaryAdjustment#getAdjustmentTarget()
      • getPerUnitAdjustment

        public java.math.BigDecimal getPerUnitAdjustment(AssociatedOrderItem one,
                                                         AssociatedOrderItem[] all,
                                                         PromotionContext context)
        Description copied from interface: MonetaryAdjustment
        This method returns the monetary adjustment that needs to be applied to each unit. One unit could be an order item or a portion of an order item (as identified by the AssociationOrderItem). It is guaranteed that all units in one have been adjusted by exactly the same set of monetary adjustments.
        Specified by:
        getPerUnitAdjustment in interface MonetaryAdjustment
        Parameters:
        one - the order item or portion of an order item for which a per unit adjustment amount needs to be calculated.
        all - all of the AssociatedOrderItems to which this adjustment applies.
        context - PromotionContext
        Returns:
        a perUnit value, value could be positive which means a discount, negative which means a markup or zero which means no change is needed.
        See Also:
        MonetaryAdjustment.getPerUnitAdjustment(AssociatedOrderItem, AssociatedOrderItem[], PromotionContext)
      • apply

        public boolean apply(LineItemSet targeted,
                             java.math.BigDecimal targetedAmount,
                             int targetedAmountTypes,
                             LineItemSet affected,
                             java.util.Vector affectedVector,
                             java.util.Vector adjustmentVector,
                             PromotionContext context)
                      throws PromotionRuntimeException
        Description copied from interface: Adjustment
        This method evaluates the targeted order items to see if they fulfill the conditions of this adjustment ( for example, if the quantity of the order items falls into one of the ranges of the adjustment). Depending upon if and what conditions are fulfilled, an Adjustment object is added to the adjustmentVector Vector object passed as a parameter. The affectedVector Vector object passed as a parameter is updated by adding the affected order items. This method is called in the invoke(LineItemSet, BigDecimal, int, Vector, Vector, PromotionContext) method of AdjustmentFunction.
        Specified by:
        apply in interface Adjustment
        Parameters:
        targeted - The targeted order items. This is a set of order items (or portions of order items) that are used to qualify for the promotion of which this adjustment is a part.
        affected - The affected order items. This is a set of order items, identified by the promotion, to which this adjustment will be attached.
        affectedVector - A Vector which contains the affected LineItemSets.
        adjustmentVector - A Vector which contains the Adjustment objects.
        context - The PromotionContext object which may be used to build the Adjustment to add to the adjustmentVector parameter.
        Returns:
        A boolean value indicating whether the conditions of the adjustment were fulfilled successfully or not. A true value indicates that the conditions of the adjustment were fulfilled successully, otherwise a false value is returned.
        Throws:
        PromotionRuntimeException - when the computation encounters a problem.
        See Also:
        com.ibm.commerce.marketing.promotion.reward.Adjustment#apply(com.ibm.commerce.marketing.promotion.runtime.LineItemSet, com.ibm.commerce.marketing.promotion.runtime.LineItemSet, com.ibm.commerce.marketing.promotion.runtime.PromotionContext)
      • getCurrency

        public java.lang.String getCurrency()
        This method gets the currency.
        Returns:
        String the currency.
      • setCurrency

        public void setCurrency(java.lang.String currency)
        This method sets the currency.
        Parameters:
        String - currency is the currency to set.
      • getPriceAdjustmentBasis

        public int getPriceAdjustmentBasis()
        This method gets the price adjustment base. The price adjustment base can be STANDARD_OFFER_PRICE, CONTRACT_PRICE or DISCOUNTED_PRICE.
        Returns:
        integer value of price adjustment base (-1 for STANDARD_OFFER_PRICE, -2 for CONTRACT_PRICE, -3 for DISCOUNTED_PRICE).
      • setPriceAdjustmentBasis

        public void setPriceAdjustmentBasis(int priceAdjustmentBasis)
        This method sets the price adjustment base. The price adjustment base can be STANDARD_OFFER_PRICE, CONTRACT_PRICE or DISCOUNTED_PRICE.
        Parameters:
        int - priceAdjustmentBasis is the value of price adjustment base (-1 for STANDARD_OFFER_PRICE, -2 for CONTRACT_PRICE, -3 for DISCOUNTED_PRICE).