Class CartPricingRoundingHelper

java.lang.Object
com.broadleafcommerce.cartoperation.service.pricing.CartPricingRoundingHelper

public class CartPricingRoundingHelper extends Object
Helper class to calculate rounding of monetary unit amounts for cart pricing.
Author:
Marie Standeven (marieStandeven)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected javax.money.MonetaryAmount
    getUnitAmount(javax.money.CurrencyUnit currency)
    Determines the smallest unit amount of money for the CurrencyUnit.
    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.
    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.
    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>
    void
    roundProratedOrderAdjustmentsAcrossFulfillmentItems(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>
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 items
      orderAdjustmentsTotal - the total adjustment amount
      currency - 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 OfferServices
      Rounds prorated amounts for prorated fulfillment group adjustments on fulfillment items and group.
      Parameters:
      group - the FulfillmentGroup with prices to be rounded
      currency - 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 return
      totalAmount - 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 items
      proratedOrderAdjustmentAmounts - a mapping of fulfillment item reference numbers to the rounded adjustment amount
      currency - 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 return
      totalAmount - the total adjustment amount
      unitAmount - 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 the CurrencyUnit.

      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