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 Modifier and Type Method Description protected void
attachBundleItemProratedPrices(List<com.broadleafcommerce.cart.client.domain.CartItem> dependentCartItems, Map<String,javax.money.MonetaryAmount> roundedDependentItemProratedPrice, javax.money.CurrencyUnit expectedCurrency)
protected void
calculateAndAttachBundleItemProratedPrices(@NonNull com.broadleafcommerce.cart.client.domain.CartItem bundleCartItem, @NonNull javax.money.CurrencyUnit expectedCurrency)
void
calculateAndAttachBundleItemProratedPrices(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.MonetaryAmount
calculateBundleDependentItemProratedPrice(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.Adjustment
createBundleDependentItemAdjustment(javax.money.MonetaryAmount adjustmentAmount)
<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 matchingPriceInfo
for aCartItem
from 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 matchingPriceInfo
for aCartItem
from among the givenpriceInfos
.protected CartItemPriceableTargetUtils
getCartItemPriceableTargetUtils()
protected com.broadleafcommerce.common.extension.TypeFactory
getFactory()
protected com.broadleafcommerce.pricing.client.domain.PriceableTarget
getItemChoiceTarget(com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)
Builds aPriceableTarget
for the parentItemChoice
of a dependentCartItem
representing 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.ObjectMapper
getMapper()
Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>
getPriceableTargets(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
Builds thePriceableTargets
for the givenCartItem
and 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 matchingPriceInfo
for 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 matchingPriceInfo
for a dependentCartItem
.protected <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Map<String,P>getPriceInfos(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
protected Object
getProductType(com.broadleafcommerce.cart.client.domain.CartItem cartItem)
protected CartPricingRoundingHelper
getRoundingHelper()
protected com.broadleafcommerce.pricing.client.domain.PriceableTarget
getSpecificChoiceTarget(@NonNull com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)
Builds aPriceableTarget
for a dependentCartItem
.protected com.broadleafcommerce.pricing.client.domain.PriceableTarget
getSpecificChoiceVariantOverrideTarget(@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 ofPriceableTargets
for 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 ofPriceableTargets
for the given dependentCartItem
.void
setRoundingHelper(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 thePriceableTargets
for the givenCartItem
and itsdependents
.- Parameters:
cartItem
-CartItem
for which to buildPriceableTargets
totalQuantityForTargetId
- 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
PriceableTargets
forcartItem
and 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 matchingPriceInfo
for aCartItem
from among the givenpriceInfos
.- Type Parameters:
P
- The type of thePriceInfo
in the collection- Parameters:
cartItem
- TheCartItem
for which to determine aPriceInfo
priceInfos
- Collection ofPriceInfos
from which to choose a match- Returns:
- The matching
PriceInfo
forcartItem
.
-
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 matchingPriceInfo
for aCartItem
from among the givenpriceInfos
. When given a variantId, this will prioritize aPriceInfo
for a variant override pricing if it exists.- Type Parameters:
P
- The type of thePriceInfo
in the collection- Parameters:
cartItem
- TheCartItem
for which to determine aPriceInfo
priceInfos
- Collection ofPriceInfos
from which to choose a matchvariantId
- The variant ID of a parentCartItem
, if it exists- Returns:
- The matching
PriceInfo
forcartItem
.
-
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(List<com.broadleafcommerce.cart.client.domain.CartItem> dependentCartItems, Map<String,javax.money.MonetaryAmount> roundedDependentItemProratedPrice, javax.money.CurrencyUnit expectedCurrency)
-
createBundleDependentItemAdjustment
protected com.broadleafcommerce.order.common.domain.Adjustment createBundleDependentItemAdjustment(javax.money.MonetaryAmount adjustmentAmount)
-
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 matchingPriceInfo
for a dependentCartItem
.- It checks its
AdditionalItemPricing
from among the givenpriceInfos
. - Then, it checks based on its parent
ItemChoice's
pricing in theDependentItemDetails
.
- Type Parameters:
P
- The type of thePriceInfo
in the collection- Parameters:
cartItem
- The dependentCartItem
for which to determine aPriceInfo
priceInfos
- Collection ofPriceInfos
from which to choose a match- Returns:
- The matching
PriceInfo
forcartItem
.
- 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 matchingPriceInfo
for a dependentCartItem
.- It checks based on its
DependentItemDetails.getVariantPricing()
for an override price that matches the parentCartItem's Variant
if present. - Then, it checks its
AdditionalItemPricing
from among the givenpriceInfos
. - Finally, it checks based on its parent
ItemChoice's
pricing in theDependentItemDetails
.
- Type Parameters:
P
- The type of thePriceInfo
in the collection- Parameters:
cartItem
- The dependentCartItem
for which to determine aPriceInfo
priceInfos
- Collection ofPriceInfos
from which to choose a matchvariantId
- The variant ID of a parentCartItem
, if it exists- Returns:
- The matching
PriceInfo
forcartItem
.
- 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 ofPriceableTargets
for the given dependentCartItem
. Assumes that the parentCartItem
is 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
-CartItem
for which to buildPriceableTargets
totalQuantityForTargetId
- 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
PriceableTargets
forcartItem
-
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 ofPriceableTargets
for the given dependentCartItem
.- Parameters:
cartItem
-CartItem
for which to buildPriceableTargets
totalQuantityForTargetId
- 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 theVariant
of the parentCartItem
ifCartItem.getVariantId()
is present. This can affect the pricing of the dependent item.- Returns:
- The
PriceableTargets
forcartItem
-
getItemChoiceTarget
protected com.broadleafcommerce.pricing.client.domain.PriceableTarget getItemChoiceTarget(com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)
Builds aPriceableTarget
for the parentItemChoice
of a dependentCartItem
representing aSpecificItemChoice
.- Parameters:
details
- TheDependentItemDetails
of the dependentCartItem
vendorRef
- ThevendorRef
quantity
- The quantity of the dependentCartItem
- Returns:
- A
PriceableTarget
for the parentItemChoice
of a dependentCartItem
representing 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 aPriceableTarget
for a dependentCartItem
.- Parameters:
details
- TheDependentItemDetails
of the dependentCartItem
vendorRef
- ThevendorRef
quantity
- The quantity of the dependentCartItem
- Returns:
- A
PriceableTarget
for 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)
-
-