Class BandedFulfillmentPricingProvider
- java.lang.Object
-
- com.broadleafcommerce.shipping.service.integrations.banded.BandedFulfillmentPricingProvider
-
- All Implemented Interfaces:
FulfillmentPricingProvider
public class BandedFulfillmentPricingProvider extends Object implements FulfillmentPricingProvider
Banded implementation ofFulfillmentPricingProviderfor implementations that require banded (or tiered) shipping configuration for its fulfillment options based on minimum price or weight. For fixed shipping, seeFixedFulfillmentPricingProvider. Alternatively, aFulfillmentPricingProviderintegrated with a 3rd party, such as ShipEngine, is preferred.This implementation takes in a
BandedFulfillmentPricingConfigprovided byBandedFulfillmentPricingProperties.getConfigPath(). This property can be configured with Spring Config Server, including Broadleaf's own implementation. This will allow changes to the property value to be reinitialized by this provider, as long as the declaring bean for this provider is annotated with@RefreshScope.- Author:
- Chad Harchar (charchar)
- See Also:
BandedFulfillmentPricingConfig
-
-
Constructor Summary
Constructors Constructor Description BandedFulfillmentPricingProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, BandedFulfillmentPricingProperties bandedProps, WeightCalculationService weightCalculationService)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsebuildFulfillmentOptionPricedResponse(@NonNull javax.money.MonetaryAmount price, @NonNull Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem,javax.money.MonetaryAmount> itemToPriceMap, @NonNull BandedFulfillmentPricingOption fulfillmentOption, boolean isEstimate)Builds aFulfillmentOptionPricedResponsewith the given inputs.protected Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem,javax.money.MonetaryAmount>buildItemToPriceMap(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @NonNull BandedFulfillmentPricingOption option, @NonNull FulfillmentOptionBand band)Builds a map ofFulfillmentPricingItemsto the calculated prices.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsecalculateCostForFulfillmentGroup(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Calculate shipping for a request that includes a specified fulfillment option.protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsecalculateCostForFulfillmentGroupInternal(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, boolean isEstimate)Handles the shared logic ofcalculateCostForFulfillmentGroup(FulfillmentPricingRequest)andestimateCostForFulfillmentGroup(FulfillmentPricingRequest).protected javax.money.MonetaryAmountcalculateFixedPriceForItem(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull BandedFulfillmentPricingOption option, @NonNull FulfillmentOptionBand band, @NonNull javax.money.CurrencyUnit currency)protected javax.money.MonetaryAmountcalculateFulfillmentGroupPriceBeforeAdjustments(@NonNull FulfillmentOptionBand band, javax.money.CurrencyUnit expectedCurrency)protected javax.money.MonetaryAmountcalculatePercentageRateForItem(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FulfillmentOptionBand band, @NonNull javax.money.CurrencyUnit currency)Deprecated.protected javax.money.MonetaryAmountcalculatePercentageRateForItems(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FulfillmentOptionBand band, @NonNull javax.money.CurrencyUnit currency)protected javax.money.MonetaryAmountcalculatePriceForItem(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull BandedFulfillmentPricingOption option, @NonNull FulfillmentOptionBand band, @NonNull javax.money.CurrencyUnit currency)protected javax.money.MonetaryAmountcalculatePriceForItems(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull BandedFulfillmentPricingOption option, @NonNull FulfillmentOptionBand band, @NonNull javax.money.CurrencyUnit currency)Calculates the price for a fulfillment items.booleancanCalculateCostForOption(@NonNull String fulfillmentOptionName)Whether this provider has knowledge of the provided option and thus can provide cost information for it.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponseestimateCostForFulfillmentGroup(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Estimate shipping for a request that includes a specified fulfillment option.protected Optional<FulfillmentOptionBand>findBand(@NonNull BandedFulfillmentPricingOption option, @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Finds the correctFulfillmentOptionBandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.protected Optional<FulfillmentOptionBand>findCustomBand(@NonNull BandedFulfillmentPricingOption option, @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Extension point to handleBandTypesnot inDefaultBandTypes.protected Optional<FulfillmentOptionBand>findPriceBand(@NonNull BandedFulfillmentPricingOption option, @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Finds the correctprice-basedbandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.protected Optional<FulfillmentOptionBand>findWeightBand(@NonNull BandedFulfillmentPricingOption option, @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Finds the correctitem-weight-basedbandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.protected BandedFulfillmentPricingConfiggetBandedFulfillmentPricingConfig()protected BandedFulfillmentPricingPropertiesgetBandedProps()protected BandedFulfillmentPricingOptiongetDefaultBandedFulfillmentPricingOption()Builds aBandedFulfillmentPricingOptionwith fields initialized to typical values.protected javax.money.MonetaryAmountgetMonetaryAmount(javax.money.CurrencyUnit expectedCurrency, Set<com.broadleafcommerce.shipping.domain.FulfillmentPriceAmount> fulfillmentPriceAmounts)Find the corresponding price for the expected currency, otherwise return zero.protected com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected WeightCalculationServicegetWeightCalculationService()voidinit()Reads in the configuration file defined byBandedFulfillmentPricingProperties.getConfigPath()and initializesbandedFulfillmentPricingConfigto the result.protected voidpreRequest(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse>providePricedFulfillmentOptions(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Retrieve all possible priced fulfillment options for the provided request.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.shipping.service.integrations.FulfillmentPricingProvider
canProvidePricedFulfillmentOptions, getFulfillmentOptionPricingResponses
-
-
-
-
Constructor Detail
-
BandedFulfillmentPricingProvider
public BandedFulfillmentPricingProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, BandedFulfillmentPricingProperties bandedProps, WeightCalculationService weightCalculationService)
-
-
Method Detail
-
init
@PostConstruct public void init()
Reads in the configuration file defined byBandedFulfillmentPricingProperties.getConfigPath()and initializesbandedFulfillmentPricingConfigto the result.- Throws:
UncheckedIOException- Thrown when there is an error while reading the configuration file or converting its contents into aBandedFulfillmentPricingConfig.IllegalStateException- Thrown when there is not configuration file defined byBandedFulfillmentPricingProperties.getConfigPath().
-
calculateCostForFulfillmentGroup
public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)Description copied from interface:FulfillmentPricingProviderCalculate shipping for a request that includes a specified fulfillment option.- Specified by:
calculateCostForFulfillmentGroupin interfaceFulfillmentPricingProvider- Parameters:
fulfillmentPricingRequest- The request for which to calculate shipping.- Returns:
- Response object with calculated shipping cost for the provided request.
-
canCalculateCostForOption
public boolean canCalculateCostForOption(@NonNull @NonNull String fulfillmentOptionName)Description copied from interface:FulfillmentPricingProviderWhether this provider has knowledge of the provided option and thus can provide cost information for it.- Specified by:
canCalculateCostForOptionin interfaceFulfillmentPricingProvider- Parameters:
fulfillmentOptionName- The option to consider whether this provider can calculate cost information.- Returns:
- Whether this provider has knowledge of the provided option and thus can provide cost information for it.
-
estimateCostForFulfillmentGroup
public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse estimateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)Description copied from interface:FulfillmentPricingProviderEstimate shipping for a request that includes a specified fulfillment option.- Specified by:
estimateCostForFulfillmentGroupin interfaceFulfillmentPricingProvider- Parameters:
request- The request for which to estimate shipping.- Returns:
- Response object with estimated shipping cost for the provided request.
-
providePricedFulfillmentOptions
public List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse> providePricedFulfillmentOptions(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
Description copied from interface:FulfillmentPricingProviderRetrieve all possible priced fulfillment options for the provided request. Intended to be used to display options to the customer for selection.- Specified by:
providePricedFulfillmentOptionsin interfaceFulfillmentPricingProvider- Parameters:
request- The request for which to calculate shipping and return options.- Returns:
- All possible priced fulfillment options for the provided request.
-
calculateCostForFulfillmentGroupInternal
protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroupInternal(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, boolean isEstimate)Handles the shared logic ofcalculateCostForFulfillmentGroup(FulfillmentPricingRequest)andestimateCostForFulfillmentGroup(FulfillmentPricingRequest).
-
findBand
protected final Optional<FulfillmentOptionBand> findBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
Finds the correctFulfillmentOptionBandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.Extend
findCustomBand(BandedFulfillmentPricingOption, FulfillmentPricingRequest)to handle anyBandTypesnot inDefaultBandTypes.- Parameters:
option- The fulfillment option to use to calculate pricing for therequestrequest- The request for which to calculate shipping- Returns:
- the correct
FulfillmentOptionBandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.
-
findPriceBand
protected Optional<FulfillmentOptionBand> findPriceBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
Finds the correctprice-basedbandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.- Parameters:
option- The fulfillment option to use to calculate pricing for therequestrequest- The request for which to calculate shipping- Returns:
- the correct
price-basedbandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest
-
findWeightBand
protected Optional<FulfillmentOptionBand> findWeightBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
Finds the correctitem-weight-basedbandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.- Parameters:
option- The fulfillment option to use to calculate pricing for therequestrequest- The request for which to calculate shipping- Returns:
- the correct
item-weight-basedbandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest
-
findCustomBand
protected Optional<FulfillmentOptionBand> findCustomBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
Extension point to handleBandTypesnot inDefaultBandTypes.- Parameters:
option- The fulfillment option to use to calculate pricing for therequestrequest- The request for which to calculate shipping- Returns:
- the correct
FulfillmentOptionBandfrom theBandedFulfillmentPricingOptionfor the givenFulfillmentPricingRequest.
-
getDefaultBandedFulfillmentPricingOption
protected BandedFulfillmentPricingOption getDefaultBandedFulfillmentPricingOption()
Builds aBandedFulfillmentPricingOptionwith fields initialized to typical values.- Returns:
- a
BandedFulfillmentPricingOptionwith fields initialized to typical values.
-
buildItemToPriceMap
protected Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem,javax.money.MonetaryAmount> buildItemToPriceMap(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull FulfillmentOptionBand band)
Builds a map ofFulfillmentPricingItemsto the calculated prices.- Parameters:
request- The request for which to calculate shippingoption- The fulfillment option to use to calculate pricing for therequestband- The band fromoptionappropriate for the items being priced- Returns:
- a map of
FulfillmentPricingItemsto the calculated prices.
-
buildFulfillmentOptionPricedResponse
protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse buildFulfillmentOptionPricedResponse(@NonNull @NonNull javax.money.MonetaryAmount price, @NonNull @NonNull Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem,javax.money.MonetaryAmount> itemToPriceMap, @NonNull @NonNull BandedFulfillmentPricingOption fulfillmentOption, boolean isEstimate)Builds aFulfillmentOptionPricedResponsewith the given inputs.- Parameters:
price- The value to set forFulfillmentOptionPricedResponse.getFulfillmentPriceCalculated().itemToPriceMap- Map ofFulfillmentPricingItemsto their fulfillment pricesfulfillmentOption- TheFulfillmentOptionthat forms the basis of the responseisEstimate- Whether this is for estimating the fulfillment pricing- Returns:
- a
FulfillmentOptionPricedResponsefor the given inputs.
-
calculateFulfillmentGroupPriceBeforeAdjustments
protected javax.money.MonetaryAmount calculateFulfillmentGroupPriceBeforeAdjustments(@NonNull @NonNull FulfillmentOptionBand band, javax.money.CurrencyUnit expectedCurrency)
-
getMonetaryAmount
protected javax.money.MonetaryAmount getMonetaryAmount(javax.money.CurrencyUnit expectedCurrency, @Nullable Set<com.broadleafcommerce.shipping.domain.FulfillmentPriceAmount> fulfillmentPriceAmounts)Find the corresponding price for the expected currency, otherwise return zero.- Parameters:
expectedCurrency- The expected currency to find a price forfulfillmentPriceAmounts- The list of prices to search against- Returns:
- the corresponding price for the expected currency, otherwise return zero
-
calculatePriceForItem
@Deprecated protected javax.money.MonetaryAmount calculatePriceForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull FulfillmentOptionBand band, @NonNull @NonNull javax.money.CurrencyUnit currency)
Deprecated.Calculates the price for a fulfillment item. By default this means the price for a single unit rather than all like units, i.e.,FulfillmentPricingItem.getUnitPrice()is used notFulfillmentPricingItem.getSubtotal().- Parameters:
item- TheFulfillmentPriceInfoitem to be pricedoption- The applicableBandedFulfillmentPricingOptionfor theitemband- The applicable band from theoptionfor theitem- Returns:
- the price for a fulfillment item.
-
calculatePriceForItems
protected javax.money.MonetaryAmount calculatePriceForItems(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull FulfillmentOptionBand band, @NonNull @NonNull javax.money.CurrencyUnit currency)Calculates the price for a fulfillment items. By default this means the price for all units, i.e.,FulfillmentPricingItem.getMerchandiseTotalAmount().- Parameters:
item- TheFulfillmentPriceInfoitem to be pricedoption- The applicableBandedFulfillmentPricingOptionfor theitemband- The applicable band from theoptionfor theitem- Returns:
- the price for a fulfillment items.
-
calculateFixedPriceForItem
protected javax.money.MonetaryAmount calculateFixedPriceForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull FulfillmentOptionBand band, @NonNull @NonNull javax.money.CurrencyUnit currency)
-
calculatePercentageRateForItem
@Deprecated protected javax.money.MonetaryAmount calculatePercentageRateForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull FulfillmentOptionBand band, @NonNull @NonNull javax.money.CurrencyUnit currency)
Deprecated.
-
calculatePercentageRateForItems
protected javax.money.MonetaryAmount calculatePercentageRateForItems(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull FulfillmentOptionBand band, @NonNull @NonNull javax.money.CurrencyUnit currency)
-
preRequest
protected void preRequest(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getBandedProps
protected BandedFulfillmentPricingProperties getBandedProps()
-
getBandedFulfillmentPricingConfig
protected BandedFulfillmentPricingConfig getBandedFulfillmentPricingConfig()
-
getWeightCalculationService
protected WeightCalculationService getWeightCalculationService()
-
-