Class DiscountValue

java.lang.Object
de.hybris.platform.util.DiscountValue
All Implemented Interfaces:
PDTValue, Serializable, Cloneable

public class DiscountValue extends Object implements Cloneable, Serializable, PDTValue
string-storeable discount value object.
See Also:
  • Constructor Details

    • DiscountValue

      public DiscountValue(String code, double value, boolean absolute, String currencyIsoCode)
      creates a new discount value without applied value ( will be 0.0 ).
      Parameters:
      code - the code of the actual discount item - cannot be null
      value - the discount rate or value
      absolute - tells whether this value is relative or absolute
    • DiscountValue

      public DiscountValue(String code, double value, String currencyIsoCode, boolean asTargetPrice)
      Creates a new un-applied absolute discount value.
    • DiscountValue

      public DiscountValue(String code, double value, boolean absolute, double appliedValue, String isoCode)
      creates a new discount value with applied value.
      Parameters:
      code - the code of the actual discount item - cannot be null
      value - the discount rate or value
      absolute - tells whether this value is relative or absolute
      appliedValue - the applied value of this discount
    • DiscountValue

      public DiscountValue(String code, double value, boolean absolute, double appliedValue, String isoCode, boolean asTargetPrice)
  • Method Details

    • createRelative

      public static DiscountValue createRelative(String code, Double doubleValue)
    • createAbsolute

      public static DiscountValue createAbsolute(String code, Double doubleValue, String currencyIsoCode)
    • createTargetPrice

      public static DiscountValue createTargetPrice(String code, Double doubleValue, String currencyIsoCode)
    • apply

      public DiscountValue apply(double quantity, double price, int digits, String currencyIsoCode)
      Creates a copy of this discount value holding the applied value for a given price rounded to given digits.
      Parameters:
      price - the price to apply this tax value to
      digits - the digits to round the value to, if < 0 no rounding is done
      Returns:
      the copy of this discount vale
      Since:
      2.20
    • createRelativeAppliedValue

      protected DiscountValue createRelativeAppliedValue(double price, int digits, String currencyIsoCode)
    • createAbsoluteAppliedValue

      protected DiscountValue createAbsoluteAppliedValue(double quantity, int digits, String currencyIsoCode)
    • createTargetPriceAppliedValue

      protected DiscountValue createTargetPriceAppliedValue(double quantity, double totalPriceWithoutDiscounts, int digits, String currencyIsoCode)
    • apply

      public static List apply(double quantity, double startPrice, int digits, List values, String currencyIsoCode)
      Creates a collection of applied discount values for a given price and a tax value collection. All resulting applied values prices are rounded to the given number of digits.
      Parameters:
      values - the collection of discount values to apply to the price
      startPrice - the price to apply these discounts to - the discount values are applied iteratively decreasing the (start)price each time !
      digits - the number of digits to round, if < 0 no rounding is done
      Returns:
      a list containing all applied discount values for a given price and a tax value collection.
      Since:
      2.20
    • sumAppliedValues

      public static double sumAppliedValues(Collection values)
    • getCode

      public String getCode()
      Returns:
      the code this values discount. normally this should match a @see de.hybris.platform.jalo.order.price.Discount item's code but dont rely on it (e.g. when discount values are imported along with their orders and the actual discount doesnt exist )
    • getCurrencyIsoCode

      public String getCurrencyIsoCode()
      Returns:
      the currency isocode
    • getValue

      public double getValue()
      The discount value. This value represent the discount rate ( or discount value for absolute discount ) only - use @see #getAppliedValue() to get the actual (absolute) discout value for the order or entry.
      Specified by:
      getValue in interface PDTValue
      Returns:
      the value of the DiscountValue.
    • isAsTargetPrice

      public boolean isAsTargetPrice()
      If true the contained value represents the intended target price. Therefore the applied value is determined from the difference between the base price and the target price.

      A target price discount value must also contain a currency iso code!

    • getAppliedValue

      public double getAppliedValue()
      the actual value of this discount. means this is the value you get when the discount was applied to the order or entry which this value relates to.
      Returns:
      the applied value of the DiscountValue.
    • isAbsolute

      public boolean isAbsolute()
      Returns true if the DiscountValue is an absolute discount, otherwise false is returned.
      Returns:
      true if the DiscountValue is an absolute discount, otherwise false.
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      string representation of this discount value. you may restore this object via @see #parseDiscountValue(String).
    • toString

      public static String toString(Collection discountValueCollection)
      creates the string representation of a collection of discount values. you may restore this collection via @see #parseDiscountValueCollection(String)(String).
      Parameters:
      discountValueCollection - a collection containing StandardDiscountValues
      Returns:
      the string representation of a collection of discount values.
    • parseDiscountValueCollection

      public static Collection parseDiscountValueCollection(String str) throws IllegalArgumentException
      creates a discount value collection from its string representation created via @see #toString(Collection).
      Parameters:
      str - the string representation of the discount values.
      Returns:
      a discount value collection from its string representation.
      Throws:
      IllegalArgumentException - if a parse error occured
    • parseDiscountValue

      public static DiscountValue parseDiscountValue(String str) throws IllegalArgumentException
      creates a discount value object from its string representation created via @see #toString().
      Parameters:
      str - the string representation of the discount values.
      Returns:
      a discount value object from its string representation.
      Throws:
      IllegalArgumentException - if the string is not valid
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • equalsIgnoreAppliedValue

      public boolean equalsIgnoreAppliedValue(DiscountValue discountValue)