Class CartItemPriceableTargetUtils

java.lang.Object
com.broadleafcommerce.cartoperation.service.provider.external.pricing.CartItemPriceableTargetUtils

public class CartItemPriceableTargetUtils extends Object
Collection of utilities for PriceableTargets related to CartItem.
Author:
Nathan Moore (nathandmoore), Erin Pennington (epenning)
  • Constructor Summary

    Constructors
    Constructor
    Description
    CartItemPriceableTargetUtils(com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Extension point to handle converting complex attributes representing Characteristics to a string representation compatible with PriceableTarget.getCharacteristics().
    protected com.broadleafcommerce.pricing.client.domain.PriceableTarget
    createTarget(@NonNull String targetId, @NonNull String targetType, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Integer quantity, @NonNull Map<String,javax.money.MonetaryAmount> priceableFields)
    Creates the PriceableTarget with the specified identifier and type.
    Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>
    createTargets(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull String targetType, @NonNull Map<String,Map<String,javax.money.MonetaryAmount>> priceableFields, Map<String,Integer> totalQuantityForTargetId)
    Build targets to represent a CartItem in a request to PricingProvider.
    Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>
    createTargets(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
    Creates PriceableTargets for a CartItem.
    protected Map<String,String>
    getCharacteristics(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Builds a map of the attributes on cartItem that relate to Characteristics where Characteristic.isTargetableForPricing() is true.
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    protected Map<String,Map<String,javax.money.MonetaryAmount>>
    getPriceableFields(@NonNull Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos)
     
    protected Map<String,javax.money.MonetaryAmount>
    getPriceableFields(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
    Builds the map of priceable fields for a PriceInfo that could later be added as PriceableTarget.getPriceableFields().
    protected Map<String,Map<String,Map<String,javax.money.MonetaryAmount>>>
    getPriceableFieldsByTargetType(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
     
    protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo>
    getPriceInfos(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
     
    protected Map<String,Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo>>
    getPriceInfosByTargetType(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Gets a map of PriceInfo map by the target type.
    protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo>
    getSkuPriceInfos(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Deprecated.
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    protected boolean
    isMatchWithTarget(com.broadleafcommerce.pricing.client.domain.PriceableTarget target, String targetId, String targetType, Map<String,String> characteristics, String termsDurationType, Integer termsDurationLength)
    Determines whether the target matches the provided conditions.
    protected boolean
    isMatchWithTargetCustom(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target)
    Extension point to use to determine if the given PriceableTarget represents the CartItem.
    void
    populateTargetCharacteristics(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Populate PriceableTarget.getCharacteristics() based on attributes from the cartItem.
    void
    populateTargetTerms(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Populate PriceableTarget.getTermDurationLength() and PriceableTarget.getTermDurationType()based on the cartItem.
    boolean
    priceInfoMatchesCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info)
    Determines if the give CartItem matches the PriceInfo.
    boolean
    priceInfoMatchesCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info, @NonNull com.broadleafcommerce.cart.client.domain.AdditionalItemPricing itemPricing)
    Determines if the give dependent CartItem matches the PriceableTarget.
    boolean
    priceInfoMatchesCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info, @NonNull com.broadleafcommerce.cart.client.domain.DependentItemDetails details)
    Determines if the give dependent CartItem matches the PriceableTarget.

    Methods inherited from class java.lang.Object

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

    • CartItemPriceableTargetUtils

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

    • createTargets

      public Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget> createTargets(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
      Creates PriceableTargets for a CartItem. This will create as many targets as there are priceable fields in the SKU price info and pricing key price info attributes in CartItem.getInternalAttributes().
      Parameters:
      cartItem - CartItem for which to create 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:
      PriceableTargets for a CartItem.
    • createTargets

      public Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget> createTargets(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull String targetType, @NonNull @NonNull Map<String,Map<String,javax.money.MonetaryAmount>> priceableFields, Map<String,Integer> totalQuantityForTargetId)
      Build targets to represent a CartItem in a request to PricingProvider. This will create as many targets are there are fields in priceableFields for the given targetType. Use createTargets(CartItem, Map) to automatically determine the priceable fields from the cartItem.
      Parameters:
      cartItem - CartItem to be priced
      targetType - Type of target to build, e.g., SKU or PRICING_KEY
      priceableFields - Map of priceable fields from the item represented by cartItem, e.g., basePrice, baseCost.
      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:
      Targets built to represent the cartItem.
    • populateTargetCharacteristics

      public void populateTargetCharacteristics(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Populate PriceableTarget.getCharacteristics() based on attributes from the cartItem. By default this will look at CartItemAttributeConstants.Internal.PRICEABLE_CHARACTERISTICS for the list of names to be picked from CartItem.getAttributes() and CartItem.getAttributeChoices().
      Parameters:
      target - PriceableTarget being constructed to represent the cartItem
      cartItem - CartItem to be priced
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
      See Also:
    • priceInfoMatchesCartItem

      public boolean priceInfoMatchesCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info)
      Determines if the give CartItem matches the PriceInfo.
      Parameters:
      cartItem - The CartItem being priced.
      info - The candidate PriceInfo that might have the price for cartItem.
      Returns:
      Whether info matches cartItem.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
    • priceInfoMatchesCartItem

      public boolean priceInfoMatchesCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.AdditionalItemPricing itemPricing)
      Determines if the give dependent CartItem matches the PriceableTarget.
      Parameters:
      cartItem - The CartItem being priced.
      info - The candidate PriceInfo that might have the price for cartItem.
      itemPricing - The dependent's AdditionalItemPricing, indicating the caller is looking for an explicit match for SpecificItemChoice-based item pricing.
      Returns:
      Whether the give dependent CartItem matches the PriceableTarget.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
    • priceInfoMatchesCartItem

      public boolean priceInfoMatchesCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.DependentItemDetails details)
      Determines if the give dependent CartItem matches the PriceableTarget.
      Parameters:
      cartItem - The CartItem being priced.
      info - The candidate PriceInfo that might have the price for cartItem.
      details - The dependent's DependentItemDetails indicating the caller is looking for an explicit match for ItemChoice-based item pricing.
      Returns:
      Whether the give dependent CartItem matches the PriceableTarget.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
    • populateTargetTerms

      public void populateTargetTerms(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Populate PriceableTarget.getTermDurationLength() and PriceableTarget.getTermDurationType()based on the cartItem.
      Parameters:
      target - PriceableTarget being constructed to represent the cartItem
      cartItem - CartItem to be priced
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
    • getPriceableFieldsByTargetType

      protected Map<String,Map<String,Map<String,javax.money.MonetaryAmount>>> getPriceableFieldsByTargetType(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    • getPriceableFields

      protected Map<String,Map<String,javax.money.MonetaryAmount>> getPriceableFields(@NonNull @NonNull Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos)
    • getSkuPriceInfos

      @Deprecated protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo> getSkuPriceInfos(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Deprecated.
    • getPriceInfos

      protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo> getPriceInfos(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    • getPriceInfosByTargetType

      protected Map<String,Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo>> getPriceInfosByTargetType(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Gets a map of PriceInfo map by the target type.
      Parameters:
      cartItem - the CartItem to get the ap from
      Returns:
      a map of PriceInfo map by the target type
    • getPriceableFields

      protected Map<String,javax.money.MonetaryAmount> getPriceableFields(@Nullable com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
      Builds the map of priceable fields for a PriceInfo that could later be added as PriceableTarget.getPriceableFields(). The key is the type of the priceable field and the value is the amount.
      Parameters:
      priceInfo - PriceInfo for which to determine the priceable fields.
      Returns:
      map of priceable fields for a PriceInfo
      See Also:
    • createTarget

      protected com.broadleafcommerce.pricing.client.domain.PriceableTarget createTarget(@NonNull @NonNull String targetId, @NonNull @NonNull String targetType, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Integer quantity, @NonNull @NonNull Map<String,javax.money.MonetaryAmount> priceableFields)
      Creates the PriceableTarget with the specified identifier and type.
      Parameters:
      targetId - the target identifier for which to create a PriceableTarget.
      targetType - the target type for which to create a PriceableTarget.
      cartItem - CartItem to build a target for.
      priceableFields - Map of the priceable fields for the sku to add as PriceableTarget.getPriceableFields().
      Returns:
      the PriceableTarget with sku as PriceableTarget.getTargetId().
      See Also:
    • isMatchWithTarget

      protected boolean isMatchWithTarget(com.broadleafcommerce.pricing.client.domain.PriceableTarget target, String targetId, String targetType, Map<String,String> characteristics, @Nullable String termsDurationType, @Nullable Integer termsDurationLength)
      Determines whether the target matches the provided conditions.
      Parameters:
      target - The PriceableTarget
      targetId - The id of the expected target
      targetType - The type of the expected target
      characteristics - The characteristics of the expected target
      termsDurationType - The terms duration type of the expected target
      termsDurationLength - The terms duration length of the expected target
      Returns:
      Whether the target matches the provided conditions.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
      See Also:
    • isMatchWithTargetCustom

      protected boolean isMatchWithTargetCustom(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target)
      Extension point to use to determine if the given PriceableTarget represents the CartItem. This allows comparisons for target types not covered out of box—see CartPricingTargetType.
      Parameters:
      cartItem - The CartItem to be priced.
      target - The candidate PriceableTarget belonging to a PriceInfo.
      Returns:
      Whether the target matches the cartItem.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
      See Also:
    • getCharacteristics

      protected Map<String,String> getCharacteristics(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Builds a map of the attributes on cartItem that relate to Characteristics where Characteristic.isTargetableForPricing() is true.
      Parameters:
      cartItem - The source CartItem.
      Returns:
      A map of the attributes on cartItem that relate to Characteristics where Characteristic.isTargetableForPricing() is true.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
    • convertNonStringAttributeToCharacteristicString

      protected String convertNonStringAttributeToCharacteristicString(@NonNull @NonNull Object attribute)
      Extension point to handle converting complex attributes representing Characteristics to a string representation compatible with PriceableTarget.getCharacteristics(). By default, this just calls Object.toString().
      Parameters:
      attribute - The attribute to convert.
      Returns:
      The converted attribute.
      Since:
      Cart Operation Service 2.2.0, Release Train 2.2.0
      See Also:
    • getMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
    • getTypeFactory

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