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