Class Helper

java.lang.Object
de.hybris.platform.promotions.util.Helper

public class Helper extends Object
Static helper methods for the promotions extension.
Version:
v1
  • Constructor Details

    • Helper

      public Helper()
  • Method Details

    • buildDateForYear

      public static Date buildDateForYear(int year)
      Create a Date for the first day of the specified year.
      Parameters:
      year - the year
      Returns:
      a date that represents the first day of the year
    • formatCurrencyAmount

      public static String formatCurrencyAmount(SessionContext ctx, Locale locale, Currency currency, double amount)
      Format an amount in a currency for a locale.
      Parameters:
      ctx - the hybris context
      locale - the java locale that the amount should be rendered in
      currency - the hybris currency for the amount
      amount - the value
      Returns:
      a formatted string
    • adjustDigits

      protected static DecimalFormat adjustDigits(DecimalFormat format, Currency currency)
      Adjusts DecimalFormat's fraction digits according to given Currency.
    • adjustSymbol

      protected static DecimalFormat adjustSymbol(DecimalFormat format, Currency currency)
      Adjusts DecimalFormat's symbol according to given Currency.
    • getSmallestCurrencyUnit

      protected static BigDecimal getSmallestCurrencyUnit(SessionContext ctx, Currency currency)
      Get the smallest value that can be represented as a whole unit in the specified currency.
      Parameters:
      ctx - the hybris context
      currency - the hybris currency
      Returns:
      A BigDecimal that represents the smallest unit in the currency
    • roundCurrencyValue

      public static BigDecimal roundCurrencyValue(SessionContext ctx, Currency currency, BigDecimal amount)
      Round the specified amount to the nearest whole unit in the specified currency.
      Parameters:
      ctx - the hybris context
      currency - the hybris currency
      amount - the amount
      Returns:
      A BigDecimal that represents the amount rounded to the precision of the currency
    • roundCurrencyValue

      public static BigDecimal roundCurrencyValue(SessionContext ctx, Currency currency, double amount)
      Round the specified amount to the nearest whole unit in the specified currency.
      Parameters:
      ctx - the hybris context
      currency - the hybris currency
      amount - the amount
      Returns:
      A BigDecimal that represents the amount rounded to the precision of the currency
    • adjustUnitPrices

      public static void adjustUnitPrices(SessionContext ctx, PromotionEvaluationContext promoContext, List<PromotionOrderEntryConsumed> consumedEntries, double targetTotal, double originalTotal)
      Adjust the unit prices of the PromotionOrderEntryConsumed items specified to match the target total

      Applies unit price adjustments to the PromotionOrderEntryConsumed items to take the total value of the items from the originalTotal to the targetTotal specified. If necessary this method will split PromotionOrderEntryConsumed items to allow it to match the targetTotal value exactly.

      Parameters:
      ctx - the hybris context
      promoContext - the promotion evaluation context
      consumedEntries - the list of consumed entries
      targetTotal - the target total value for the consumed entries
      originalTotal - the current total value for the consumed entries
    • calculateOrderEntryAdjustedTotal

      protected static BigDecimal calculateOrderEntryAdjustedTotal(SessionContext ctx, Currency currency, List<PromotionOrderEntryConsumed> entries)
      Helper method to calculate the sum of the AdjustedEntryPrice for each of the PromotionOrderEntryConsumed items.
      Parameters:
      ctx - the hybris context
      currency - the hybris currency
      entries - the list of PromotionOrderEntryConsumed items to sum
      Returns:
      A BigDecimal that represents the rounded sum of the adjusted entry prices
    • getBaseProduct

      public static Product getBaseProduct(SessionContext ctx, Product product)
      Return the base product for the product specified. Returns the current product if the product is not an instance of VariantProduct and the result of GeneratedVariantProduct.getBaseProduct() if it is.
      Parameters:
      ctx - The hybris context
      product - The product to get the base product for
      Returns:
      the base product for the product specified
    • getBaseProducts

      public static List<Product> getBaseProducts(SessionContext ctx, Product product)
      This is a recursive variant of the method above.
    • getBaseProducts

      protected static void getBaseProducts(SessionContext ctx, Product product, List<Product> result)
      Internal recursive method to get all base products of a given product.

      Parameters:
      ctx -
      product -
      result -
    • findGlobalDiscountValue

      public static DiscountValue findGlobalDiscountValue(SessionContext ctx, AbstractOrder order, String discountValueCode)
      Find a global discount value with specified Code
      Parameters:
      ctx - the hybris context
      order - the order to lookup the discounts on
      discountValueCode - the code for the discount to find
      Returns:
      the discount value found
    • dumpOrder

      public static String dumpOrder(SessionContext ctx, AbstractOrder order)
      Method to dump an order and its entries into a string.
      Parameters:
      ctx - the hybris context
      order - the order to dump
      Returns:
      the string dump of the order
    • dumpOrder

      protected static void dumpOrder(SessionContext ctx, AbstractOrder order, StringBuilder builder)
    • dumpOrderEntry

      protected static void dumpOrderEntry(SessionContext ctx, AbstractOrderEntry orderEntry, StringBuilder builder)
    • join

      public static String join(Collection items)
      Join collection of objects together to form a delimited string
      Parameters:
      items - the collection of items to join together
      Returns:
      a joined string
    • join

      public static String join(Collection items, String delimiter)
      Join collection of objects together to form a delimited string
      Parameters:
      items - the collection of items to join together
      delimiter - the delimiter to place between the items
      Returns:
      a joined string
    • getDateNowRoundedToMinute

      public static Date getDateNowRoundedToMinute()
      returns a Date of the current minute to assure that queries can be cached for up to 1 minute.
      Returns:
      the truncated Date