Class CartItemPriceableTargetUtils
java.lang.Object
com.broadleafcommerce.cartoperation.service.provider.external.pricing.CartItemPriceableTargetUtils
Collection of utilities for
PriceableTargets related to CartItem.- Author:
- Nathan Moore (nathandmoore), Erin Pennington (epenning)
-
Constructor Summary
ConstructorsConstructorDescriptionCartItemPriceableTargetUtils(com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected StringconvertNonStringAttributeToCharacteristicString(@NonNull Object attribute) Extension point to handle converting complex attributes representingCharacteristicsto a string representation compatible withPriceableTarget.getCharacteristics().createPriceInfoMap(com.broadleafcommerce.cart.client.domain.CartItem item, String attrName) createPriceInfoMapForSkuTargetType(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) protected com.broadleafcommerce.pricing.client.domain.PriceableTargetcreateTarget(String targetId, String targetType, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Integer quantity, com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) Creates thePriceableTargetwith 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) CreatesPriceableTargetsfor aCartItem.protected Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>createTargets(String targetType, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String, Integer> totalQuantityForTargetId) getCharacteristics(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Builds a map of the attributes oncartItemthat relate toCharacteristicswhereCharacteristic.isTargetableForPricing()is true.protected com.fasterxml.jackson.databind.ObjectMapperprotected ProductDefaultConfigurationUtilsprotected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanisMatchWithTarget(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, String targetId, @NonNull String targetType, @NonNull com.broadleafcommerce.cart.client.domain.CartItem item) Determines whether thetargetmatches the provided conditions.protected booleanisMatchWithTargetCustom(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target) Extension point to use to determine if the givenPriceableTargetrepresents theCartItem.protected voidpopulatePriceableFields(com.broadleafcommerce.pricing.client.domain.PriceableTarget target, com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) voidpopulatePricingCategory(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getPricingCategory()based on attributes from thecartItem.voidpopulateTargetCharacteristics(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getCharacteristics()based on attributes from thecartItem.voidpopulateTargetFrequency(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getRecurringPeriodFrequency()andPriceableTarget.getRecurringPeriodType()based on thecartItem.voidpopulateTargetTerms(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getTermDurationLength()andPriceableTarget.getTermDurationType()based on thecartItem.booleanpriceInfoMatchesCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info) Determines if the giveCartItemmatches thePriceInfo.booleanpriceInfoMatchesCartItem(@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 dependentCartItemmatches thePriceableTarget.booleanpriceInfoMatchesCartItem(@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 dependentCartItemmatches thePriceableTarget.voidsetProductDefaultConfigurationUtils(ProductDefaultConfigurationUtils productDefaultConfigurationUtils)
-
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) CreatesPriceableTargetsfor aCartItem. This will create as many targets as there are priceable fields in theSKU price infoandpricing key price infoattributes inCartItem.getInternalAttributes().- Parameters:
cartItem-CartItemfor which to createPriceableTargets.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:
PriceableTargetsfor aCartItem.
-
createTargets
-
createPriceInfoMapForSkuTargetType
-
createPriceInfoMap
-
populateTargetCharacteristics
public void populateTargetCharacteristics(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getCharacteristics()based on attributes from thecartItem. By default this will look atCartItemAttributeConstants.Internal.PRICEABLE_CHARACTERISTICSfor the list of names to be picked fromCartItem.getAttributes()andCartItem.getAttributeChoices().- Parameters:
target-PriceableTargetbeing constructed to represent thecartItemcartItem-CartItemto 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) PopulatePriceableTarget.getPricingCategory()based on attributes from thecartItem. By default, this will look atCartItemAttributeConstants.Internal.PRICING_CATEGORYfor the key to be picked fromCartItem.getAttributes().- Parameters:
target-PriceableTargetbeing constructed to represent thecartItemcartItem-CartItemto 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 giveCartItemmatches thePriceInfo.- Parameters:
cartItem- TheCartItembeing priced.info- The candidatePriceInfothat might have the price forcartItem.- Returns:
- Whether
infomatchescartItem. - 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 dependentCartItemmatches thePriceableTarget.- Parameters:
cartItem- TheCartItembeing priced.info- The candidatePriceInfothat might have the price forcartItem.itemPricing- The dependent'sAdditionalItemPricing, indicating the caller is looking for an explicit match forSpecificItemChoice-based item pricing.- Returns:
- Whether the give dependent
CartItemmatches thePriceableTarget. - 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 dependentCartItemmatches thePriceableTarget.- Parameters:
cartItem- TheCartItembeing priced.info- The candidatePriceInfothat might have the price forcartItem.details- The dependent'sDependentItemDetailsindicating the caller is looking for an explicit match forItemChoice-based item pricing.- Returns:
- Whether the give dependent
CartItemmatches thePriceableTarget. - 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) PopulatePriceableTarget.getTermDurationLength()andPriceableTarget.getTermDurationType()based on thecartItem.- Parameters:
target-PriceableTargetbeing constructed to represent thecartItemcartItem-CartItemto 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) PopulatePriceableTarget.getRecurringPeriodFrequency()andPriceableTarget.getRecurringPeriodType()based on thecartItem.- Parameters:
target-PriceableTargetbeing constructed to represent thecartItemcartItem-CartItemto 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 thePriceableTargetwith the specified identifier and type.- Parameters:
targetId- the target identifier for which to create aPriceableTarget.targetType- the target type for which to create aPriceableTarget.cartItem-CartItemto build a target for.priceableFields- Map of the priceable fields for the sku to add asPriceableTarget.getPriceableFields().- Returns:
- the
PriceableTargetwithskuasPriceableTarget.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 thetargetmatches the provided conditions.By default, it checks against the characteristics, term, and frequency of the
CartItem.If the
CartItemdoesn't have frequency defined, the frequency is skipped, allowing for a match with the default frequency from pricing.- Parameters:
target- ThePriceableTargettargetId- 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 targetitem- TheCartItemto be checked- Returns:
- Whether the
targetmatches 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 givenPriceableTargetrepresents theCartItem. This allows comparisons for target types not covered out of box—seeCartPricingTargetType.- Parameters:
cartItem- TheCartItemto be priced.target- The candidatePriceableTargetbelonging to aPriceInfo.- Returns:
- Whether the
targetmatches thecartItem. - 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 oncartItemthat relate toCharacteristicswhereCharacteristic.isTargetableForPricing()is true.- Parameters:
cartItem- The sourceCartItem.- Returns:
- A map of the attributes on
cartItemthat relate toCharacteristicswhereCharacteristic.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 representingCharacteristicsto a string representation compatible withPriceableTarget.getCharacteristics(). By default, this just callsObject.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
-
setProductDefaultConfigurationUtils
@Autowired public void setProductDefaultConfigurationUtils(ProductDefaultConfigurationUtils productDefaultConfigurationUtils)
-