Class DefaultFeePricingService

java.lang.Object
com.broadleafcommerce.cartoperation.service.pricing.DefaultFeePricingService
All Implemented Interfaces:
FeePricingService

public class DefaultFeePricingService extends Object implements FeePricingService
The implementation of FeePricingService and its methods.
Since:
Cart Operation Services 2.3.0, Release Train 2.3.0
Author:
Julia Lopez-Pozas (jlopezpozas)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    protected static final SecureRandom
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultFeePricingService(com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, PricingProvider pricingProvider, CartTotalsCalculator cartTotalsCalculator)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addNonZeroFeeCartItem(@NonNull Fee fee, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToAdd, @NonNull javax.money.MonetaryAmount multiplier)
    Creates a new CartItem representing the current Fee that is being evaluated that is to be added to the Cart.
    <T extends Fee>
    void
    applyFeesAfterAdjustments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Fetches Fees for the ContextInfo's application, then calculates and applies them to the given Cart.
    <T extends Fee>
    void
    applyFeesBeforeAdjustments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Fetches Fees for the ContextInfo's application, then calculates and applies them to the given Cart.
    protected com.broadleafcommerce.cart.client.domain.CartItem
    buildFeeCartItem(@NonNull Fee fee, @NonNull javax.money.MonetaryAmount multiplier)
    Build a CartItem that represents a Fee.
    <T extends Fee>
    void
    calculateAndApplyFees(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<T> feesToBeApplied, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Calculates the Fees passed in and applies them to the Cart by adding CartItems of type DefaultCartItemTypes.EXTRA_FEE, which should update the CartPricing.feesTotal when totals are calculated for the cart.
    protected javax.money.MonetaryAmount
    calculateFeeAmount(@NonNull Fee fee, @NonNull javax.money.MonetaryAmount multiplier)
    Represents the calculated Fee amount based on the Fee.feeCalculationMethod and Fee.feeCalculationOperation.
    protected com.broadleafcommerce.common.extension.cache.CacheStateManager
     
     
    protected javax.money.MonetaryAmount
    getFeeMultiplier(@NonNull Fee fee, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
    Gets the multiplier to be used for calculating the Fee based on the Fee.feeCalculationMethod.
    <T extends Fee>
    List<T>
    getFeesByApplication(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Fetches and returns a list of Fees matching the passed in ContextInfo's application information.
    protected PricingProvider
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    protected boolean
    isCartItemAMatchingFeeItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull javax.money.CurrencyUnit cartCurrency, @NonNull Fee fee)
    Whether the given CartItem is a match for the given Fee by checking the following conditions: the cart item is an DefaultCartItemTypes.EXTRA_FEE item the cart item matches the given Fee.feeCode the fee's currency matches the given Cart currency
    protected boolean
    isFeeAmountNonZero(@NonNull Fee fee)
    Whether the Fee is one of the expected fee types and the Fee.rate or Fee.fixedAmount is a positive amount.
    protected boolean
    isFeeAmountNonZero(@NonNull Fee fee, @NonNull javax.money.MonetaryAmount feeAmount)
    Whether the Fee is one of the expected fee types, Fee.rate or Fee.fixedAmount is a positive amount, and the calculated fee amount is a positive amount.
    protected boolean
    Whether the Fee is a fixed fee and the fixed fee amount is a positive amount.
    protected boolean
    isRateFeeNonZero(@NonNull Fee fee)
    Whether the Fee is a rate-based fee and the fee rate is a positive amount.
    protected void
    updateOrRemoveFeeCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem matchingFeeItem, @NonNull Fee fee, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToRemove, @NonNull javax.money.MonetaryAmount multiplier)
    Updates or removes the CartItem that matches the current Fee being evaluated depending on whether the fee's amount is now zero, or whether the matching fee cart item's subtotal does not match the expected fee amount.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • DefaultFeePricingService

      public DefaultFeePricingService(com.broadleafcommerce.common.extension.TypeFactory typeFactory, @Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, PricingProvider pricingProvider, CartTotalsCalculator cartTotalsCalculator)
  • Method Details

    • applyFeesBeforeAdjustments

      public <T extends Fee> void applyFeesBeforeAdjustments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FeePricingService
      Fetches Fees for the ContextInfo's application, then calculates and applies them to the given Cart. Expected to be called before adjustments / offers are applied onto the cart.
      Specified by:
      applyFeesBeforeAdjustments in interface FeePricingService
      Type Parameters:
      T - The domain type for the fees to be applied
      Parameters:
      cart - the Cart to apply the fees to
      contextInfo - Context information around sandbox and multitenant state
    • applyFeesAfterAdjustments

      public <T extends Fee> void applyFeesAfterAdjustments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FeePricingService
      Fetches Fees for the ContextInfo's application, then calculates and applies them to the given Cart. Expected to be called after adjustments / offers have been applied onto the cart.
      Specified by:
      applyFeesAfterAdjustments in interface FeePricingService
      Type Parameters:
      T - The domain type for the fees to be applied
      Parameters:
      cart - the Cart to apply the fees to
      contextInfo - Context information around sandbox and multitenant state
    • calculateAndApplyFees

      public <T extends Fee> void calculateAndApplyFees(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<T> feesToBeApplied, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FeePricingService
      Calculates the Fees passed in and applies them to the Cart by adding CartItems of type DefaultCartItemTypes.EXTRA_FEE, which should update the CartPricing.feesTotal when totals are calculated for the cart.
      Specified by:
      calculateAndApplyFees in interface FeePricingService
      Type Parameters:
      T - The domain type for the fees to be applied
      Parameters:
      cart - the Cart to apply the fees to
      feesToBeApplied - the list of Fees to apply onto the cart
      contextInfo - Context information around sandbox and multitenant state
    • getFeesByApplication

      public <T extends Fee> List<T> getFeesByApplication(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FeePricingService
      Fetches and returns a list of Fees matching the passed in ContextInfo's application information. The list is either fetched from the cache or fetched by the external Pricing provider.
      Specified by:
      getFeesByApplication in interface FeePricingService
      Type Parameters:
      T - The domain type for the fees being fetched
      Parameters:
      contextInfo - Context information around sandbox and multitenant state
      Returns:
      the list of Fees matching the context's application that is fetched from the cache or fetched by the external Pricing provider
    • buildFeeCartItem

      protected com.broadleafcommerce.cart.client.domain.CartItem buildFeeCartItem(@NonNull @NonNull Fee fee, @NonNull @NonNull javax.money.MonetaryAmount multiplier)
      Build a CartItem that represents a Fee.
      Parameters:
      fee - the Fee build the CartItem on
      multiplier - the MonetaryAmount representing where to apply the fee onto
      Returns:
      the CartItem representing the Fee
    • isCartItemAMatchingFeeItem

      protected boolean isCartItemAMatchingFeeItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull javax.money.CurrencyUnit cartCurrency, @NonNull @NonNull Fee fee)
      Whether the given CartItem is a match for the given Fee by checking the following conditions:
      • the cart item is an DefaultCartItemTypes.EXTRA_FEE item
      • the cart item matches the given Fee.feeCode
      • the fee's currency matches the given Cart currency
      Parameters:
      cartItem - the CartItem to check
      cartCurrency - the currency of the Cart
      fee - the Fee to match the cart item with
      Returns:
      true if the cart item matches the fee, false if not
    • isFeeAmountNonZero

      protected boolean isFeeAmountNonZero(@NonNull @NonNull Fee fee)
      Whether the Fee is one of the expected fee types and the Fee.rate or Fee.fixedAmount is a positive amount.
      Parameters:
      fee - the Fee to check
      Returns:
      true if the Fee is an expected fee type and the rate/fixed amount is a positive amount, false if the Fee is not an expected fee type or the rate/fixed amount is zero or a negative amount
    • isFeeAmountNonZero

      protected boolean isFeeAmountNonZero(@NonNull @NonNull Fee fee, @NonNull @NonNull javax.money.MonetaryAmount feeAmount)
      Whether the Fee is one of the expected fee types, Fee.rate or Fee.fixedAmount is a positive amount, and the calculated fee amount is a positive amount.
      Parameters:
      fee - the Fee to check
      feeAmount - the calculated amount of the Fee
      Returns:
      true if the Fee is an expected fee type, the rate/fixed amount is a * positive amount, and the calculated fee amount is a positive amount; false if the Fee is not an expected fee type, or the * rate/fixed amount is zero or a negative amount, or the calculated fee amount is a zero or a negative amount
    • isFixedAmountFeeNonZero

      protected boolean isFixedAmountFeeNonZero(@NonNull @NonNull Fee fee)
      Whether the Fee is a fixed fee and the fixed fee amount is a positive amount.
      Parameters:
      fee - the Fee to check
      Returns:
      true if the Fee is a fixed fee and the fixed fee amount is a positive amount, false if the Fee is not a fixed fee or the fixed fee amount is zero or a negative amount
    • isRateFeeNonZero

      protected boolean isRateFeeNonZero(@NonNull @NonNull Fee fee)
      Whether the Fee is a rate-based fee and the fee rate is a positive amount.
      Parameters:
      fee - the Fee to check
      Returns:
      true if the Fee is a rate-based fee and the fee rate is a positive amount, false if the Fee is not a rate-based fee or the fee rate is zero or a negative amount
    • calculateFeeAmount

      protected javax.money.MonetaryAmount calculateFeeAmount(@NonNull @NonNull Fee fee, @NonNull @NonNull javax.money.MonetaryAmount multiplier)
      Represents the calculated Fee amount based on the Fee.feeCalculationMethod and Fee.feeCalculationOperation.
      Parameters:
      fee - the Fee to calculate
      multiplier - the MonetaryAmount representing where to apply the fee onto
      Returns:
      the calculated Fee amount based on the Fee.feeCalculationMethod and Fee.feeCalculationOperation
    • getFeeMultiplier

      protected javax.money.MonetaryAmount getFeeMultiplier(@NonNull @NonNull Fee fee, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
      Gets the multiplier to be used for calculating the Fee based on the Fee.feeCalculationMethod.
      Parameters:
      fee - the Fee to be calculated using this multiplier
      cart - the Cart whose price totals will be used to get the multiplier
      Returns:
      the multiplier to be used for calculating the fee
    • updateOrRemoveFeeCartItem

      protected void updateOrRemoveFeeCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem matchingFeeItem, @NonNull @NonNull Fee fee, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToRemove, @NonNull @NonNull javax.money.MonetaryAmount multiplier)
      Updates or removes the CartItem that matches the current Fee being evaluated depending on whether the fee's amount is now zero, or whether the matching fee cart item's subtotal does not match the expected fee amount.
      Parameters:
      matchingFeeItem - the CartItem that matches the current fee being evaluated
      fee - the current Fee that is being evaluated for update or removal
      cartItemsToRemove - the list of CartItems that will be removed from the Cart
      multiplier - the MonetaryAmount to be used to calculate the fee amount
    • addNonZeroFeeCartItem

      protected void addNonZeroFeeCartItem(@NonNull @NonNull Fee fee, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToAdd, @NonNull @NonNull javax.money.MonetaryAmount multiplier)
      Creates a new CartItem representing the current Fee that is being evaluated that is to be added to the Cart.
      Parameters:
      fee - the current Fee that is being evaluated to create and add a fee cart item
      cartItemsToAdd - the list of CartItems that will be added to the Cart
      multiplier - the MonetaryAmount to be used to calculate the fee amount
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getCacheStateManager

      @Nullable protected com.broadleafcommerce.common.extension.cache.CacheStateManager getCacheStateManager()
    • getPricingProvider

      protected PricingProvider getPricingProvider()
    • getCartTotalsCalculator

      protected CartTotalsCalculator getCartTotalsCalculator()