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 Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo>
    createPriceInfoMap(com.broadleafcommerce.cart.client.domain.CartItem item, String attrName)
     
    protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo>
    createPriceInfoMapForSkuTargetType(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
     
    protected com.broadleafcommerce.pricing.client.domain.PriceableTarget
    createTarget(String targetId, String targetType, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Integer quantity, com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
    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, Map<String,Integer> qtyTargetIdMap)
    Creates PriceableTargets for a CartItem.
    protected Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>
    createTargets(String targetType, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
     
    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 com.broadleafcommerce.common.extension.TypeFactory
     
    protected boolean
    isMatchWithTarget(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, String targetId, @NonNull String targetType, @NonNull com.broadleafcommerce.cart.client.domain.CartItem item)
    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.
    protected void
    populatePriceableFields(com.broadleafcommerce.pricing.client.domain.PriceableTarget target, com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
     
    void
    populatePricingCategory(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Populate PriceableTarget.getPricingCategory() based on attributes from 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
    populateTargetFrequency(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
    Populate PriceableTarget.getRecurringPeriodFrequency() and PriceableTarget.getRecurringPeriodType() based on 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.
    void
     

    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> qtyTargetIdMap)
      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.
      qtyTargetIdMap - 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

      protected Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget> createTargets(String targetType, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String,Integer> totalQuantityForTargetId)
    • createPriceInfoMapForSkuTargetType

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

      protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo> createPriceInfoMap(com.broadleafcommerce.cart.client.domain.CartItem item, String attrName)
    • 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:
    • populatePricingCategory

      public void populatePricingCategory(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Populate PriceableTarget.getPricingCategory() based on attributes from the cartItem. By default, this will look at CartItemAttributeConstants.Internal.PRICING_CATEGORY for the key to be picked from CartItem.getAttributes().
      Parameters:
      target - PriceableTarget being constructed to represent the cartItem
      cartItem - CartItem to be priced
    • 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
    • populateTargetFrequency

      public void populateTargetFrequency(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      Populate PriceableTarget.getRecurringPeriodFrequency() and PriceableTarget.getRecurringPeriodType() based on the cartItem.
      Parameters:
      target - PriceableTarget being constructed to represent the cartItem
      cartItem - CartItem to be priced
      Since:
      Cart Operation Service 2.3.0, Release Train 2.3.0
    • createTarget

      protected com.broadleafcommerce.pricing.client.domain.PriceableTarget createTarget(String targetId, String targetType, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Integer quantity, com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
      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:
    • populatePriceableFields

      protected void populatePriceableFields(com.broadleafcommerce.pricing.client.domain.PriceableTarget target, com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
    • isMatchWithTarget

      protected boolean isMatchWithTarget(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @Nullable String targetId, @NonNull @NonNull String targetType, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem item)
      Determines whether the target matches the provided conditions.

      By default, it checks against the characteristics, term, and frequency of the CartItem.

      If the CartItem doesn't have frequency defined, the frequency is skipped, allowing for a match with the default frequency from pricing.

      Parameters:
      target - The PriceableTarget
      targetId - The id of the expected target. The id is nullable as sometimes the target id may not be present. For example, bundle item doesn't have a SKU.
      targetType - The type of the expected target
      item - The CartItem to be checked
      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()
    • getProductDefaultConfigurationUtils

      protected ProductDefaultConfigurationUtils getProductDefaultConfigurationUtils()
    • setProductDefaultConfigurationUtils

      @Autowired public void setProductDefaultConfigurationUtils(ProductDefaultConfigurationUtils productDefaultConfigurationUtils)