Class Helper
- java.lang.Object
-
- de.hybris.platform.promotions.util.Helper
-
public class Helper extends java.lang.ObjectStatic helper methods for the promotions extension.- Version:
- v1
-
-
Constructor Summary
Constructors Constructor Description Helper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.text.DecimalFormatadjustDigits(java.text.DecimalFormat format, Currency currency)AdjustsDecimalFormat's fraction digits according to givenCurrency.protected static java.text.DecimalFormatadjustSymbol(java.text.DecimalFormat format, Currency currency)AdjustsDecimalFormat's symbol according to givenCurrency.static voidadjustUnitPrices(SessionContext ctx, PromotionEvaluationContext promoContext, java.util.List<PromotionOrderEntryConsumed> consumedEntries, double targetTotal, double originalTotal)Adjust the unit prices of the PromotionOrderEntryConsumed items specified to match the target totalstatic java.util.DatebuildDateForYear(int year)Create a Date for the first day of the specified year.protected static java.math.BigDecimalcalculateOrderEntryAdjustedTotal(SessionContext ctx, Currency currency, java.util.List<PromotionOrderEntryConsumed> entries)Helper method to calculate the sum of the AdjustedEntryPrice for each of the PromotionOrderEntryConsumed items.static java.lang.StringdumpOrder(SessionContext ctx, AbstractOrder order)Method to dump an order and its entries into a string.protected static voiddumpOrder(SessionContext ctx, AbstractOrder order, java.lang.StringBuilder builder)protected static voiddumpOrderEntry(SessionContext ctx, AbstractOrderEntry orderEntry, java.lang.StringBuilder builder)static DiscountValuefindGlobalDiscountValue(SessionContext ctx, AbstractOrder order, java.lang.String discountValueCode)Find a global discount value with specified Codestatic java.lang.StringformatCurrencyAmount(SessionContext ctx, java.util.Locale locale, Currency currency, double amount)Format an amount in a currency for a locale.static ProductgetBaseProduct(SessionContext ctx, Product product)Return the base product for the product specified.static java.util.List<Product>getBaseProducts(SessionContext ctx, Product product)This is a recursive variant of the method above.protected static voidgetBaseProducts(SessionContext ctx, Product product, java.util.List<Product> result)Internal recursive method to get all base products of a given product.static java.util.DategetDateNowRoundedToMinute()returns aDateof the current minute to assure that queries can be cached for up to 1 minute.protected static java.math.BigDecimalgetSmallestCurrencyUnit(SessionContext ctx, Currency currency)Get the smallest value that can be represented as a whole unit in the specified currency.static java.lang.Stringjoin(java.util.Collection items)Join collection of objects together to form a delimited stringstatic java.lang.Stringjoin(java.util.Collection items, java.lang.String delimiter)Join collection of objects together to form a delimited stringstatic java.math.BigDecimalroundCurrencyValue(SessionContext ctx, Currency currency, double amount)Round the specified amount to the nearest whole unit in the specified currency.static java.math.BigDecimalroundCurrencyValue(SessionContext ctx, Currency currency, java.math.BigDecimal amount)Round the specified amount to the nearest whole unit in the specified currency.
-
-
-
Method Detail
-
buildDateForYear
public static java.util.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 java.lang.String formatCurrencyAmount(SessionContext ctx, java.util.Locale locale, Currency currency, double amount)
Format an amount in a currency for a locale.- Parameters:
ctx- the hybris contextlocale- the java locale that the amount should be rendered incurrency- the hybris currency for the amountamount- the value- Returns:
- a formatted string
-
adjustDigits
protected static java.text.DecimalFormat adjustDigits(java.text.DecimalFormat format, Currency currency)AdjustsDecimalFormat's fraction digits according to givenCurrency.
-
adjustSymbol
protected static java.text.DecimalFormat adjustSymbol(java.text.DecimalFormat format, Currency currency)AdjustsDecimalFormat's symbol according to givenCurrency.
-
getSmallestCurrencyUnit
protected static java.math.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 contextcurrency- the hybris currency- Returns:
- A BigDecimal that represents the smallest unit in the currency
-
roundCurrencyValue
public static java.math.BigDecimal roundCurrencyValue(SessionContext ctx, Currency currency, java.math.BigDecimal amount)
Round the specified amount to the nearest whole unit in the specified currency.- Parameters:
ctx- the hybris contextcurrency- the hybris currencyamount- the amount- Returns:
- A BigDecimal that represents the amount rounded to the precision of the currency
-
roundCurrencyValue
public static java.math.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 contextcurrency- the hybris currencyamount- 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, java.util.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 contextpromoContext- the promotion evaluation contextconsumedEntries- the list of consumed entriestargetTotal- the target total value for the consumed entriesoriginalTotal- the current total value for the consumed entries
-
calculateOrderEntryAdjustedTotal
protected static java.math.BigDecimal calculateOrderEntryAdjustedTotal(SessionContext ctx, Currency currency, java.util.List<PromotionOrderEntryConsumed> entries)
Helper method to calculate the sum of the AdjustedEntryPrice for each of the PromotionOrderEntryConsumed items.- Parameters:
ctx- the hybris contextcurrency- the hybris currencyentries- 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 ofVariantProductand the result ofGeneratedVariantProduct.getBaseProduct()if it is.- Parameters:
ctx- The hybris contextproduct- The product to get the base product for- Returns:
- the base product for the product specified
-
getBaseProducts
public static java.util.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, java.util.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, java.lang.String discountValueCode)
Find a global discount value with specified Code- Parameters:
ctx- the hybris contextorder- the order to lookup the discounts ondiscountValueCode- the code for the discount to find- Returns:
- the discount value found
-
dumpOrder
public static java.lang.String dumpOrder(SessionContext ctx, AbstractOrder order)
Method to dump an order and its entries into a string.- Parameters:
ctx- the hybris contextorder- the order to dump- Returns:
- the string dump of the order
-
dumpOrder
protected static void dumpOrder(SessionContext ctx, AbstractOrder order, java.lang.StringBuilder builder)
-
dumpOrderEntry
protected static void dumpOrderEntry(SessionContext ctx, AbstractOrderEntry orderEntry, java.lang.StringBuilder builder)
-
join
public static java.lang.String join(java.util.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 java.lang.String join(java.util.Collection items, java.lang.String delimiter)Join collection of objects together to form a delimited string- Parameters:
items- the collection of items to join togetherdelimiter- the delimiter to place between the items- Returns:
- a joined string
-
getDateNowRoundedToMinute
public static java.util.Date getDateNowRoundedToMinute()
returns aDateof the current minute to assure that queries can be cached for up to 1 minute.- Returns:
- the truncated Date
-
-