Class CartItemPricingUtils
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.pricing.CartItemPricingUtils
-
public class CartItemPricingUtils extends Object
Utility to aid in pricingCartItems.- Author:
- Chad Harchar (charchar), Nathan Moore (nathandmoore)
-
-
Constructor Summary
Constructors Constructor Description CartItemPricingUtils(CartItemPriceableTargetUtils cartItemPriceableTargetUtils, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory factory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidattachBundleItemProratedPrices(@NonNull com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, Map<String,javax.money.MonetaryAmount> roundedDependentItemProratedPrice, javax.money.CurrencyUnit expectedCurrency)protected voidattachBundleItemProratedPrices(List<com.broadleafcommerce.cart.client.domain.CartItem> dependentCartItems, Map<String,javax.money.MonetaryAmount> roundedDependentItemProratedPrice, javax.money.CurrencyUnit expectedCurrency)Deprecated.protected voidcalculateAndAttachBundleItemProratedPrices(@NonNull com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, @NonNull javax.money.CurrencyUnit expectedCurrency)voidcalculateAndAttachBundleItemProratedPrices(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Calculates the prorated prices for the dependent cart items based on the bundle item total price.protected Map<String,javax.money.MonetaryAmount>calculateBundleDependentItemPriceProration(com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, javax.money.CurrencyUnit expectedCurrency, javax.money.MonetaryAmount bundleTotalAmount)protected javax.money.MonetaryAmountcalculateBundleDependentItemProratedPrice(com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem, javax.money.MonetaryAmount bundleSubtotal, javax.money.MonetaryAmount dependentItemsTotal, javax.money.CurrencyUnit expectedCurrency)protected com.broadleafcommerce.order.common.domain.AdjustmentcreateBundleDependentItemAdjustment(javax.money.MonetaryAmount adjustmentAmount)Deprecated.protected com.broadleafcommerce.order.common.domain.AdjustmentcreateBundleDependentItemAdjustment(javax.money.MonetaryAmount adjustmentAmount, Integer bundleItemQuantity)<P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<P>determineMatchingPriceInfo(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Collection<P> priceInfos)Determines the matchingPriceInfofor aCartItemfrom among the givenpriceInfos.<P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<P>determineMatchingPriceInfo(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Collection<P> priceInfos, String variantId)Determines the matchingPriceInfofor aCartItemfrom among the givenpriceInfos.protected CartItemPriceableTargetUtilsgetCartItemPriceableTargetUtils()protected com.broadleafcommerce.common.extension.TypeFactorygetFactory()protected com.broadleafcommerce.pricing.client.domain.PriceableTargetgetItemChoiceTarget(com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)Builds aPriceableTargetfor the parentItemChoiceof a dependentCartItemrepresenting aSpecificItemChoice.protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<P>getItemPriceInfo(com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem)protected com.fasterxml.jackson.databind.ObjectMappergetMapper()Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>getPriceableTargets(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)Builds thePriceableTargetsfor the givenCartItemand itsdependents.protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<P>getPriceInfoForDependentItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Collection<P> priceInfos)Determines the matchingPriceInfofor a dependentCartItem.protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<P>getPriceInfoForDependentItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Collection<P> priceInfos, String variantId)Determines the matchingPriceInfofor a dependentCartItem.protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Map<String,P>getPriceInfos(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)protected ObjectgetProductType(com.broadleafcommerce.cart.client.domain.CartItem cartItem)protected CartPricingRoundingHelpergetRoundingHelper()protected com.broadleafcommerce.pricing.client.domain.PriceableTargetgetSpecificChoiceTarget(@NonNull com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)Builds aPriceableTargetfor a dependentCartItem.protected com.broadleafcommerce.pricing.client.domain.PriceableTargetgetSpecificChoiceVariantOverrideTarget(@NonNull com.broadleafcommerce.cart.client.domain.SpecificItemChoiceVariantPricingOverride override, String vendorRef, int quantity)protected List<com.broadleafcommerce.pricing.client.domain.PriceableTarget>getTargetsForDependentItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Map<String,Integer> totalQuantityForTargetId, String parentCartItemVariantId)Builds the list ofPriceableTargetsfor the given dependentCartItem.protected List<com.broadleafcommerce.pricing.client.domain.PriceableTarget>getTargetsForDependentItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)Builds the list ofPriceableTargetsfor the given dependentCartItem.voidsetRoundingHelper(CartPricingRoundingHelper roundingHelper)
-
-
-
Constructor Detail
-
CartItemPricingUtils
public CartItemPricingUtils(CartItemPriceableTargetUtils cartItemPriceableTargetUtils, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory factory)
-
-
Method Detail
-
getPriceableTargets
public Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget> getPriceableTargets(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
Builds thePriceableTargetsfor the givenCartItemand itsdependents.- Parameters:
cartItem-CartItemfor which to buildPriceableTargetstotalQuantityForTargetId- A map of the SKU or pricing key of an underlying item from a cart item to the total quantity of that item across all cart items.- Returns:
- the
PriceableTargetsforcartItemand itsdependents.
-
determineMatchingPriceInfo
public <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<P> determineMatchingPriceInfo(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Collection<P> priceInfos)
Determines the matchingPriceInfofor aCartItemfrom among the givenpriceInfos.- Type Parameters:
P- The type of thePriceInfoin the collection- Parameters:
cartItem- TheCartItemfor which to determine aPriceInfopriceInfos- Collection ofPriceInfosfrom which to choose a match- Returns:
- The matching
PriceInfoforcartItem.
-
determineMatchingPriceInfo
public <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<P> determineMatchingPriceInfo(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Collection<P> priceInfos, @Nullable String variantId)
Determines the matchingPriceInfofor aCartItemfrom among the givenpriceInfos. When given a variantId, this will prioritize aPriceInfofor a variant override pricing if it exists.- Type Parameters:
P- The type of thePriceInfoin the collection- Parameters:
cartItem- TheCartItemfor which to determine aPriceInfopriceInfos- Collection ofPriceInfosfrom which to choose a matchvariantId- The variant ID of a parentCartItem, if it exists- Returns:
- The matching
PriceInfoforcartItem.
-
calculateAndAttachBundleItemProratedPrices
public void calculateAndAttachBundleItemProratedPrices(com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Calculates the prorated prices for the dependent cart items based on the bundle item total price. For example, item 1: $6 and item 2: $4, then item 1 takes 60% of the bundle price and item 2 takes 40%. It creates an item adjustment that represents the normal merchandise total minus the prorated merchandise total. For example: unitPrice = $5 | quantity = 2 | proratedMerchTotal = $8 >> item adjustment of $2 (ie = ($5 * 2) - $8) This method also rounds the prorated prices usingCartPricingRoundingHelper.roundListOfMonetaryAmounts(java.util.Map, javax.money.MonetaryAmount, javax.money.CurrencyUnit)to the bundle total to add the remainder unit amounts. This prevents the situation e.g when the bundle total is $40 but the sum of the prorated item prices is $39.99.- Parameters:
cart- the cart that contains the bundle products to calculate the prorated price
-
getProductType
@Nullable protected Object getProductType(com.broadleafcommerce.cart.client.domain.CartItem cartItem)
-
calculateAndAttachBundleItemProratedPrices
protected void calculateAndAttachBundleItemProratedPrices(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency)
-
calculateBundleDependentItemPriceProration
protected Map<String,javax.money.MonetaryAmount> calculateBundleDependentItemPriceProration(com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, javax.money.CurrencyUnit expectedCurrency, javax.money.MonetaryAmount bundleTotalAmount)
-
attachBundleItemProratedPrices
protected void attachBundleItemProratedPrices(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, Map<String,javax.money.MonetaryAmount> roundedDependentItemProratedPrice, javax.money.CurrencyUnit expectedCurrency)
-
createBundleDependentItemAdjustment
protected com.broadleafcommerce.order.common.domain.Adjustment createBundleDependentItemAdjustment(javax.money.MonetaryAmount adjustmentAmount, Integer bundleItemQuantity)
-
attachBundleItemProratedPrices
@Deprecated(since="1.7.2") protected void attachBundleItemProratedPrices(List<com.broadleafcommerce.cart.client.domain.CartItem> dependentCartItems, Map<String,javax.money.MonetaryAmount> roundedDependentItemProratedPrice, javax.money.CurrencyUnit expectedCurrency)
Deprecated.
-
createBundleDependentItemAdjustment
@Deprecated(since="1.7.2") protected com.broadleafcommerce.order.common.domain.Adjustment createBundleDependentItemAdjustment(javax.money.MonetaryAmount adjustmentAmount)
Deprecated.
-
getItemPriceInfo
protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<P> getItemPriceInfo(com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem)
-
getPriceInfos
protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Map<String,P> getPriceInfos(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
-
calculateBundleDependentItemProratedPrice
protected javax.money.MonetaryAmount calculateBundleDependentItemProratedPrice(com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem, javax.money.MonetaryAmount bundleSubtotal, javax.money.MonetaryAmount dependentItemsTotal, javax.money.CurrencyUnit expectedCurrency)
-
getPriceInfoForDependentItem
protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<P> getPriceInfoForDependentItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Collection<P> priceInfos)
Determines the matchingPriceInfofor a dependentCartItem.- It checks its
AdditionalItemPricingfrom among the givenpriceInfos. - Then, it checks based on its parent
ItemChoice'spricing in theDependentItemDetails.
- Type Parameters:
P- The type of thePriceInfoin the collection- Parameters:
cartItem- The dependentCartItemfor which to determine aPriceInfopriceInfos- Collection ofPriceInfosfrom which to choose a match- Returns:
- The matching
PriceInfoforcartItem.
- It checks its
-
getPriceInfoForDependentItem
protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<P> getPriceInfoForDependentItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Collection<P> priceInfos, @Nullable String variantId)
Determines the matchingPriceInfofor a dependentCartItem.- It checks based on its
DependentItemDetails.getVariantPricing()for an override price that matches the parentCartItem's Variantif present. - Then, it checks its
AdditionalItemPricingfrom among the givenpriceInfos. - Finally, it checks based on its parent
ItemChoice'spricing in theDependentItemDetails.
- Type Parameters:
P- The type of thePriceInfoin the collection- Parameters:
cartItem- The dependentCartItemfor which to determine aPriceInfopriceInfos- Collection ofPriceInfosfrom which to choose a matchvariantId- The variant ID of a parentCartItem, if it exists- Returns:
- The matching
PriceInfoforcartItem.
- It checks based on its
-
getTargetsForDependentItem
protected List<com.broadleafcommerce.pricing.client.domain.PriceableTarget> getTargetsForDependentItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
Builds the list ofPriceableTargetsfor the given dependentCartItem. Assumes that the parentCartItemis not based on a variant, e.g.,CartItem.getVariantId()is null—otherwise usegetTargetsForDependentItem(CartItem, Map, String)to ensure that any override pricing for the dependent cart item (e.g., a warranty) that matches the parent's variant ID is used.- Parameters:
cartItem-CartItemfor which to buildPriceableTargetstotalQuantityForTargetId- A map of the SKU or pricing key of an underlying item from a cart item to the total quantity of that item across all cart items.- Returns:
- The
PriceableTargetsforcartItem
-
getTargetsForDependentItem
protected List<com.broadleafcommerce.pricing.client.domain.PriceableTarget> getTargetsForDependentItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Map<String,Integer> totalQuantityForTargetId, @Nullable String parentCartItemVariantId)
Builds the list ofPriceableTargetsfor the given dependentCartItem.- Parameters:
cartItem-CartItemfor which to buildPriceableTargetstotalQuantityForTargetId- A map of the SKU or pricing key of an underlying item from a cart item to the total quantity of that item across all cart items.parentCartItemVariantId- The ID of theVariantof the parentCartItemifCartItem.getVariantId()is present. This can affect the pricing of the dependent item.- Returns:
- The
PriceableTargetsforcartItem
-
getItemChoiceTarget
protected com.broadleafcommerce.pricing.client.domain.PriceableTarget getItemChoiceTarget(com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)Builds aPriceableTargetfor the parentItemChoiceof a dependentCartItemrepresenting aSpecificItemChoice.- Parameters:
details- TheDependentItemDetailsof the dependentCartItemvendorRef- ThevendorRefquantity- The quantity of the dependentCartItem- Returns:
- A
PriceableTargetfor the parentItemChoiceof a dependentCartItemrepresenting aSpecificItemChoice.
-
getSpecificChoiceTarget
protected com.broadleafcommerce.pricing.client.domain.PriceableTarget getSpecificChoiceTarget(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.DependentItemDetails details, @Nullable String vendorRef, int quantity)Builds aPriceableTargetfor a dependentCartItem.- Parameters:
details- TheDependentItemDetailsof the dependentCartItemvendorRef- ThevendorRefquantity- The quantity of the dependentCartItem- Returns:
- A
PriceableTargetfor a dependentCartItem.
-
getSpecificChoiceVariantOverrideTarget
protected com.broadleafcommerce.pricing.client.domain.PriceableTarget getSpecificChoiceVariantOverrideTarget(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.SpecificItemChoiceVariantPricingOverride override, @Nullable String vendorRef, int quantity)
-
getCartItemPriceableTargetUtils
protected CartItemPriceableTargetUtils getCartItemPriceableTargetUtils()
-
getMapper
protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
-
getFactory
protected com.broadleafcommerce.common.extension.TypeFactory getFactory()
-
getRoundingHelper
protected CartPricingRoundingHelper getRoundingHelper()
-
setRoundingHelper
@Autowired public void setRoundingHelper(CartPricingRoundingHelper roundingHelper)
-
-