Class DefaultFeePricingService
java.lang.Object
com.broadleafcommerce.cartoperation.service.pricing.DefaultFeePricingService
- All Implemented Interfaces:
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 -
Constructor Summary
ConstructorsConstructorDescriptionDefaultFeePricingService(com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, PricingProvider pricingProvider, CartTotalsCalculator cartTotalsCalculator) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddNonZeroFeeCartItem(@NonNull Fee fee, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToAdd, @NonNull javax.money.MonetaryAmount multiplier) Creates a newCartItemrepresenting the currentFeethat is being evaluated that is to be added to theCart.<T extends Fee>
voidapplyFeesAfterAdjustments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) <T extends Fee>
voidapplyFeesBeforeAdjustments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.cart.client.domain.CartItembuildFeeCartItem(@NonNull Fee fee, @NonNull javax.money.MonetaryAmount multiplier) Build aCartItemthat represents aFee.<T extends Fee>
voidcalculateAndApplyFees(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<T> feesToBeApplied, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Calculates theFeespassed in and applies them to theCartby addingCartItems of typeDefaultCartItemTypes.EXTRA_FEE, which should update theCartPricing.feesTotalwhen totals are calculated for the cart.protected javax.money.MonetaryAmountcalculateFeeAmount(@NonNull Fee fee, @NonNull javax.money.MonetaryAmount multiplier) Represents the calculatedFeeamount based on theFee.feeCalculationMethodandFee.feeCalculationOperation.protected com.broadleafcommerce.common.extension.cache.CacheStateManagerprotected CartTotalsCalculatorprotected javax.money.MonetaryAmountgetFeeMultiplier(@NonNull Fee fee, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets the multiplier to be used for calculating theFeebased on theFee.feeCalculationMethod.getFeesByApplication(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Fetches and returns a list ofFeesmatching the passed inContextInfo'sapplication information.protected PricingProviderprotected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanisCartItemAMatchingFeeItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull javax.money.CurrencyUnit cartCurrency, @NonNull Fee fee) Whether the givenCartItemis a match for the givenFeeby checking the following conditions: the cart item is anDefaultCartItemTypes.EXTRA_FEEitem the cart item matches the givenFee.feeCodethe fee's currency matches the givenCartcurrencyprotected booleanisFeeAmountNonZero(@NonNull Fee fee) Whether theFeeis one of the expected fee types and theFee.rateorFee.fixedAmountis a positive amount.protected booleanisFeeAmountNonZero(@NonNull Fee fee, @NonNull javax.money.MonetaryAmount feeAmount) Whether theFeeis one of the expected fee types,Fee.rateorFee.fixedAmountis a positive amount, and the calculated fee amount is a positive amount.protected booleanisFixedAmountFeeNonZero(@NonNull Fee fee) Whether theFeeis a fixed fee and the fixed fee amount is a positive amount.protected booleanisRateFeeNonZero(@NonNull Fee fee) Whether theFeeis a rate-based fee and the fee rate is a positive amount.protected voidupdateOrRemoveFeeCartItem(@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 theCartItemthat matches the currentFeebeing 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.
-
Field Details
-
BY_APPLICATION_IN_CACHE
- See Also:
-
SECURE_RANDOM
-
-
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:FeePricingServiceFetchesFeesfor theContextInfo'sapplication, then calculates and applies them to the givenCart. Expected to be called before adjustments / offers are applied onto the cart.- Specified by:
applyFeesBeforeAdjustmentsin interfaceFeePricingService- Type Parameters:
T- The domain type for the fees to be applied- Parameters:
cart- theCartto apply the fees tocontextInfo- 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:FeePricingServiceFetchesFeesfor theContextInfo'sapplication, then calculates and applies them to the givenCart. Expected to be called after adjustments / offers have been applied onto the cart.- Specified by:
applyFeesAfterAdjustmentsin interfaceFeePricingService- Type Parameters:
T- The domain type for the fees to be applied- Parameters:
cart- theCartto apply the fees tocontextInfo- 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:FeePricingServiceCalculates theFeespassed in and applies them to theCartby addingCartItems of typeDefaultCartItemTypes.EXTRA_FEE, which should update theCartPricing.feesTotalwhen totals are calculated for the cart.- Specified by:
calculateAndApplyFeesin interfaceFeePricingService- Type Parameters:
T- The domain type for the fees to be applied- Parameters:
cart- theCartto apply the fees tofeesToBeApplied- the list ofFeesto apply onto the cartcontextInfo- 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:FeePricingServiceFetches and returns a list ofFeesmatching the passed inContextInfo'sapplication information. The list is either fetched from the cache or fetched by the external Pricing provider.- Specified by:
getFeesByApplicationin interfaceFeePricingService- Type Parameters:
T- The domain type for the fees being fetched- Parameters:
contextInfo- Context information around sandbox and multitenant state- Returns:
- the list of
Feesmatching 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 aCartItemthat represents aFee. -
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 givenCartItemis a match for the givenFeeby checking the following conditions:- the cart item is an
DefaultCartItemTypes.EXTRA_FEEitem - the cart item matches the given
Fee.feeCode - the fee's currency matches the given
Cartcurrency
- Parameters:
cartItem- theCartItemto checkcartCurrency- the currency of theCartfee- theFeeto match the cart item with- Returns:
trueif the cart item matches the fee,falseif not
- the cart item is an
-
isFeeAmountNonZero
Whether theFeeis one of the expected fee types and theFee.rateorFee.fixedAmountis a positive amount. -
isFeeAmountNonZero
protected boolean isFeeAmountNonZero(@NonNull @NonNull Fee fee, @NonNull @NonNull javax.money.MonetaryAmount feeAmount) Whether theFeeis one of the expected fee types,Fee.rateorFee.fixedAmountis a positive amount, and the calculated fee amount is a positive amount.- Parameters:
fee- theFeeto checkfeeAmount- the calculated amount of theFee- Returns:
trueif theFeeis an expected fee type, the rate/fixed amount is a * positive amount, and the calculated fee amount is a positive amount;falseif theFeeis 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
Whether theFeeis a fixed fee and the fixed fee amount is a positive amount. -
isRateFeeNonZero
Whether theFeeis a rate-based fee and the fee rate is a positive amount. -
calculateFeeAmount
protected javax.money.MonetaryAmount calculateFeeAmount(@NonNull @NonNull Fee fee, @NonNull @NonNull javax.money.MonetaryAmount multiplier) Represents the calculatedFeeamount based on theFee.feeCalculationMethodandFee.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 theFeebased on theFee.feeCalculationMethod.- Parameters:
fee- theFeeto be calculated using this multipliercart- theCartwhose 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 theCartItemthat matches the currentFeebeing 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- theCartItemthat matches the current fee being evaluatedfee- the currentFeethat is being evaluated for update or removalcartItemsToRemove- the list ofCartItemsthat will be removed from theCartmultiplier- theMonetaryAmountto 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 newCartItemrepresenting the currentFeethat is being evaluated that is to be added to theCart.- Parameters:
fee- the currentFeethat is being evaluated to create and add a fee cart itemcartItemsToAdd- the list ofCartItemsthat will be added to theCartmultiplier- theMonetaryAmountto 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
-
getCartTotalsCalculator
-