Class CartItemPricingUtils

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

public class CartItemPricingUtils extends Object
Utility to aid in pricing CartItems.
Author:
Chad Harchar (charchar), Nathan Moore (nathandmoore)
  • Constructor Details

    • CartItemPricingUtils

      public CartItemPricingUtils(CartItemPriceableTargetUtils cartItemPriceableTargetUtils, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory factory)
  • Method Details

    • getPriceableTargets

      public Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget> getPriceableTargets(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
      Builds the PriceableTargets for the given CartItem and its dependents.
      Parameters:
      cartItem - CartItem for which to build PriceableTargets
      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 for cartItem and its dependents.
    • determineMatchingPriceInfo

      @Deprecated(since="2.1.0", forRemoval=true) 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)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • determineMatchingPriceInfo

      @Deprecated(since="2.1.0", forRemoval=true) 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)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • determineMatchingPriceInfo

      public <P extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<P> determineMatchingPriceInfo(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Collection<P> priceInfos, @Nullable String variantId)
      Determines the matching PriceInfo for a CartItem from among the given priceInfos. When given a variantId, this will prioritize a PriceInfo for a variant override pricing if it exists.
      Type Parameters:
      P - The type of the PriceInfo in the collection
      Parameters:
      priceContext - The PriceContext
      cartItem - The CartItem for which to determine a PriceInfo
      priceInfos - Collection of PriceInfos from which to choose a match
      variantId - The variant ID of a parent CartItem, if it exists
      Returns:
      The matching PriceInfo for cartItem.
    • 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 using CartPricingRoundingHelper.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)
    • createBundleDependentItemAdjustment

      @Deprecated(since="1.7.2") 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 matching PriceInfo for a dependent CartItem.
      1. It checks its AdditionalItemPricing from among the given priceInfos.
      2. Then, it checks based on its parent ItemChoice's pricing in the DependentItemDetails.
      Type Parameters:
      P - The type of the PriceInfo in the collection
      Parameters:
      cartItem - The dependent CartItem for which to determine a PriceInfo
      priceInfos - Collection of PriceInfos from which to choose a match
      Returns:
      The matching PriceInfo for cartItem.
    • 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 matching PriceInfo for a dependent CartItem.
      1. It checks based on its DependentItemDetails.getVariantPricing() for an override price that matches the parent CartItem's Variant if present.
      2. Then, it checks its AdditionalItemPricing from among the given priceInfos.
      3. Finally, it checks based on its parent ItemChoice's pricing in the DependentItemDetails.
      Type Parameters:
      P - The type of the PriceInfo in the collection
      Parameters:
      cartItem - The dependent CartItem for which to determine a PriceInfo
      priceInfos - Collection of PriceInfos from which to choose a match
      variantId - The variant ID of a parent CartItem, if it exists
      Returns:
      The matching PriceInfo for cartItem.
    • 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 of PriceableTargets for the given dependent CartItem. Assumes that the parent CartItem is not based on a variant, e.g., CartItem.getVariantId() is null—otherwise use getTargetsForDependentItem(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 build PriceableTargets
      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 for cartItem
    • 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 of PriceableTargets for the given dependent CartItem.
      Parameters:
      cartItem - CartItem for which to build PriceableTargets
      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 the Variant of the parent CartItem if CartItem.getVariantId() is present. This can affect the pricing of the dependent item.
      Returns:
      The PriceableTargets for cartItem
    • getItemChoiceTarget

      protected com.broadleafcommerce.pricing.client.domain.PriceableTarget getItemChoiceTarget(com.broadleafcommerce.cart.client.domain.DependentItemDetails details, String vendorRef, int quantity)
      Builds a PriceableTarget for the parent ItemChoice of a dependent CartItem representing a SpecificItemChoice.
      Parameters:
      details - The DependentItemDetails of the dependent CartItem
      vendorRef - The vendorRef
      quantity - The quantity of the dependent CartItem
      Returns:
      A PriceableTarget for the parent ItemChoice of a dependent CartItem representing a SpecificItemChoice.
    • getSpecificChoiceTarget

      protected com.broadleafcommerce.pricing.client.domain.PriceableTarget getSpecificChoiceTarget(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.DependentItemDetails details, @Nullable String vendorRef, int quantity)
      Builds a PriceableTarget for a dependent CartItem.
      Parameters:
      details - The DependentItemDetails of the dependent CartItem
      vendorRef - The vendorRef
      quantity - The quantity of the dependent CartItem
      Returns:
      A PriceableTarget for a dependent CartItem.
    • 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)