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 String
convertNonStringAttributeToCharacteristicString
(@NonNull Object attribute) Extension point to handle converting complex attributes representingCharacteristics
to a string representation compatible withPriceableTarget.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 thePriceableTarget
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 aCartItem
in a request toPricingProvider
.Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>
createTargets
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, Map<String, Integer> totalQuantityForTargetId) CreatesPriceableTargets
for aCartItem
.getCharacteristics
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Builds a map of the attributes oncartItem
that relate toCharacteristics
whereCharacteristic.isTargetableForPricing()
is true.protected com.fasterxml.jackson.databind.ObjectMapper
getPriceableFields
(@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 aPriceInfo
that 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.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 thetarget
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 givenPriceableTarget
represents theCartItem
.void
populateTargetCharacteristics
(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getCharacteristics()
based on attributes from thecartItem
.void
populateTargetTerms
(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTarget target, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) PopulatePriceableTarget.getTermDurationLength()
andPriceableTarget.getTermDurationType()
based on thecartItem
.boolean
priceInfoMatchesCartItem
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo info) Determines if the giveCartItem
matches thePriceInfo
.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 dependentCartItem
matches thePriceableTarget
.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 dependentCartItem
matches 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) CreatesPriceableTargets
for aCartItem
. This will create as many targets as there are priceable fields in theSKU price info
andpricing key price info
attributes inCartItem.getInternalAttributes()
.- Parameters:
cartItem
-CartItem
for 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:
PriceableTargets
for 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 aCartItem
in a request toPricingProvider
. This will create as many targets are there are fields inpriceableFields
for the giventargetType
. UsecreateTargets(CartItem, Map)
to automatically determine the priceable fields from thecartItem
.- Parameters:
cartItem
-CartItem
to 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_CHARACTERISTICS
for the list of names to be picked fromCartItem.getAttributes()
andCartItem.getAttributeChoices()
.- Parameters:
target
-PriceableTarget
being constructed to represent thecartItem
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 giveCartItem
matches thePriceInfo
.- Parameters:
cartItem
- TheCartItem
being priced.info
- The candidatePriceInfo
that might have the price forcartItem
.- Returns:
- Whether
info
matchescartItem
. - 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 dependentCartItem
matches thePriceableTarget
.- Parameters:
cartItem
- TheCartItem
being priced.info
- The candidatePriceInfo
that 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
CartItem
matches 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 dependentCartItem
matches thePriceableTarget
.- Parameters:
cartItem
- TheCartItem
being priced.info
- The candidatePriceInfo
that might have the price forcartItem
.details
- The dependent'sDependentItemDetails
indicating the caller is looking for an explicit match forItemChoice
-based item pricing.- Returns:
- Whether the give dependent
CartItem
matches 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
-PriceableTarget
being constructed to represent thecartItem
cartItem
-CartItem
to 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
- theCartItem
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 aPriceInfo
that could later be added asPriceableTarget.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 thePriceableTarget
with 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
-CartItem
to build a target for.priceableFields
- Map of the priceable fields for the sku to add asPriceableTarget.getPriceableFields()
.- Returns:
- the
PriceableTarget
withsku
asPriceableTarget.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 thetarget
matches the provided conditions.- Parameters:
target
- ThePriceableTarget
targetId
- 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
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 givenPriceableTarget
represents theCartItem
. This allows comparisons for target types not covered out of box—seeCartPricingTargetType
.- Parameters:
cartItem
- TheCartItem
to be priced.target
- The candidatePriceableTarget
belonging to aPriceInfo
.- Returns:
- Whether the
target
matches 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 oncartItem
that relate toCharacteristics
whereCharacteristic.isTargetableForPricing()
is true.- Parameters:
cartItem
- The sourceCartItem
.- Returns:
- A map of the attributes on
cartItem
that relate toCharacteristics
whereCharacteristic.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 representingCharacteristics
to 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)