Class CartPricingRoundingHelper
java.lang.Object
com.broadleafcommerce.cartoperation.service.pricing.CartPricingRoundingHelper
Helper class to calculate rounding of monetary unit amounts for cart pricing.
- Author:
- Marie Standeven (marieStandeven)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected javax.money.MonetaryAmount
getUnitAmount
(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit
.roundListOfMonetaryAmounts
(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.CurrencyUnit currency) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.roundListOfMonetaryAmounts
(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.MonetaryAmount unitAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.void
roundProratedFulfillmentGroupAdjustments
(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, @NonNull javax.money.CurrencyUnit currency) Deprecated, for removal: This API element is subject to removal in a future version.since 1.7.2, adjustment prorations are now done in OfferServices<D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem>
voidroundProratedOrderAdjustmentsAcrossFulfillmentItems
(Collection<D> fulfillmentItems, javax.money.MonetaryAmount orderAdjustmentsTotal, javax.money.CurrencyUnit currency) Rounds prorated amounts for prorated order adjustments on fulfillment items.protected <D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem>
voidupdateFulfillmentItemsWithRoundedAdjustments
(Collection<D> fulfillmentItems, Map<String, javax.money.MonetaryAmount> proratedOrderAdjustmentAmounts, javax.money.CurrencyUnit currency) Sets the new rounded adjustment values on the fulfillment items.
-
Constructor Details
-
CartPricingRoundingHelper
public CartPricingRoundingHelper()
-
-
Method Details
-
roundProratedOrderAdjustmentsAcrossFulfillmentItems
public <D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem> void roundProratedOrderAdjustmentsAcrossFulfillmentItems(Collection<D> fulfillmentItems, javax.money.MonetaryAmount orderAdjustmentsTotal, javax.money.CurrencyUnit currency) Rounds prorated amounts for prorated order adjustments on fulfillment items.- Parameters:
fulfillmentItems
- the collection of fulfillment itemsorderAdjustmentsTotal
- the total adjustment amountcurrency
- the currency of the amounts to round
-
roundProratedFulfillmentGroupAdjustments
@Deprecated(since="1.7.2", forRemoval=true) public void roundProratedFulfillmentGroupAdjustments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, @NonNull @NonNull javax.money.CurrencyUnit currency) Deprecated, for removal: This API element is subject to removal in a future version.since 1.7.2, adjustment prorations are now done in OfferServicesRounds prorated amounts for prorated fulfillment group adjustments on fulfillment items and group.- Parameters:
group
- theFulfillmentGroup
with prices to be roundedcurrency
- the currency of the amounts to round
-
roundListOfMonetaryAmounts
public Map<String,javax.money.MonetaryAmount> roundListOfMonetaryAmounts(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.CurrencyUnit currency) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.- Parameters:
amounts
- list of amounts to round, mapped to a key for lookup on returntotalAmount
- the total adjustment amount
-
updateFulfillmentItemsWithRoundedAdjustments
protected <D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem> void updateFulfillmentItemsWithRoundedAdjustments(Collection<D> fulfillmentItems, Map<String, javax.money.MonetaryAmount> proratedOrderAdjustmentAmounts, javax.money.CurrencyUnit currency) Sets the new rounded adjustment values on the fulfillment items.- Parameters:
fulfillmentItems
- the collection of fulfillment itemsproratedOrderAdjustmentAmounts
- a mapping of fulfillment item reference numbers to the rounded adjustment amountcurrency
- the currency of the amounts to round
-
roundListOfMonetaryAmounts
protected Map<String,javax.money.MonetaryAmount> roundListOfMonetaryAmounts(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.MonetaryAmount unitAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.- Parameters:
amounts
- list of amounts to round, mapped to a key for lookup on returntotalAmount
- the total adjustment amountunitAmount
- the smallest unit amount of money for the currency
-
getUnitAmount
protected javax.money.MonetaryAmount getUnitAmount(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit
.For example, a currency with 2 fraction digits (like USD) will provide the amount "0.01".
- Parameters:
currency
- the currency to get the smallest unit amount for- Returns:
- the smallest unit amount of money for the currency
-