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().protected com.broadleafcommerce.pricing.client.domain.PriceableTargetcreateTarget(@NonNull String targetId, @NonNull String targetType, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Integer quantity, @NonNull Map<String, javax.money.MonetaryAmount> priceableFields) Creates thePriceableTargetwith 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 aCartItemin a request toPricingProvider.Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>createTargets(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String, Integer> totalQuantityForTargetId) CreatesPriceableTargetsfor aCartItem.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.ObjectMappergetPriceableFields(@NonNull Map<String, com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) getPriceableFields(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) Builds the map of priceable fields for aPriceInfothat could later be added asPriceableTarget.getPriceableFields().getPriceableFieldsByTargetType(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) getPriceInfos(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) getPriceInfosByTargetType(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets a map of PriceInfo map by the target type.getSkuPriceInfos(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Deprecated.protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanisMatchWithTarget(com.broadleafcommerce.pricing.client.domain.PriceableTarget target, String targetId, String targetType, Map<String, String> characteristics, String termsDurationType, Integer termsDurationLength) 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.voidpopulateTargetCharacteristics(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getCharacteristics()based on attributes from 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.
-
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) 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.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:
PriceableTargetsfor aCartItem.
-
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 aCartItemin a request toPricingProvider. This will create as many targets are there are fields inpriceableFieldsfor the giventargetType. UsecreateTargets(CartItem, Map)to automatically determine the priceable fields from thecartItem.- Parameters:
cartItem-CartItemto be pricedtargetType- Type of target to build, e.g., SKU or PRICING_KEYpriceableFields- Map of priceable fields from the item represented bycartItem, 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) 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:
-
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
-
getPriceableFieldsByTargetType
-
getPriceableFields
-
getSkuPriceInfos
@Deprecated protected Map<String,com.broadleafcommerce.pricing.client.domain.PriceInfo> getSkuPriceInfos(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Deprecated.in favor ofgetPriceInfos(CartItem) -
getPriceInfos
-
getPriceInfosByTargetType
protected Map<String,Map<String, getPriceInfosByTargetTypecom.broadleafcommerce.pricing.client.domain.PriceInfo>> (@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gets a map of PriceInfo map by the target type.- Parameters:
cartItem- theCartItemto 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 aPriceInfothat could later be added asPriceableTarget.getPriceableFields(). The key is the type of the priceable field and the value is the amount.- Parameters:
priceInfo-PriceInfofor 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 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:
-
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 thetargetmatches the provided conditions.- Parameters:
target- ThePriceableTargettargetId- The id of the expected targettargetType- The type of the expected targetcharacteristics- The characteristics of the expected targettermsDurationType- The terms duration type of the expected targettermsDurationLength- The terms duration length of the expected target- 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()
-
getPriceInfos(CartItem)