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 of FulfillmentPricingProvider for implementations that require banded (or tiered) shipping configuration for its fulfillment options based on minimum price or weight. For fixed shipping, see FixedFulfillmentPricingProvider. Alternatively, a FulfillmentPricingProvider integrated with a 3rd party, such as ShipEngine, is preferred.

By default, BandedFulfillmentPricingProperties.getShipTables(ContextInfo) is used to retrieve the properties based on a given ContextInfo. If not found, BandedFulfillmentPricingConfig provided by BandedFulfillmentPricingProperties.getConfigPath() is used instead, which 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:
  • Constructor Details

    • BandedFulfillmentPricingProvider

      public BandedFulfillmentPricingProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, BandedFulfillmentPricingProperties bandedProps, WeightCalculationService weightCalculationService)
  • Method Details

    • init

      @PostConstruct public void init()
      Reads in the configuration file defined by BandedFulfillmentPricingProperties.getConfigPath() and initializes bandedFulfillmentPricingConfig to the result.
      Throws:
      UncheckedIOException - Thrown when there is an error while reading the configuration file or converting its contents into a BandedFulfillmentPricingConfig.
    • calculateCostForFulfillmentGroup

      public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FulfillmentPricingProvider
      Calculate shipping for a request that includes a specified fulfillment option.
      Specified by:
      calculateCostForFulfillmentGroup in interface FulfillmentPricingProvider
      Parameters:
      fulfillmentPricingRequest - The request for which to calculate shipping.
      contextInfo - context information around sandbox and multitenant state
      Returns:
      Response object with calculated shipping cost for the provided request.
    • canCalculateCostForOption

      public boolean canCalculateCostForOption(@NonNull @NonNull String fulfillmentOptionName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FulfillmentPricingProvider
      Whether this provider has knowledge of the provided option and thus can provide cost information for it.
      Specified by:
      canCalculateCostForOption in interface FulfillmentPricingProvider
      Parameters:
      fulfillmentOptionName - The option to consider whether this provider can calculate cost information.
      contextInfo - context information around sandbox and multitenant state
      Returns:
      Whether this provider has knowledge of the provided option and thus can provide cost information for it.
    • canProvidePricedFulfillmentOptions

      public boolean canProvidePricedFulfillmentOptions(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FulfillmentPricingProvider
      Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"
      Specified by:
      canProvidePricedFulfillmentOptions in interface FulfillmentPricingProvider
      Parameters:
      fulfillmentPricingRequest - The request used to identify relevant fulfillment options
      contextInfo - context information around sandbox and multitenant state
      Returns:
      Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"
    • estimateCostForFulfillmentGroup

      public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse estimateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FulfillmentPricingProvider
      Estimate shipping for a request that includes a specified fulfillment option.
      Specified by:
      estimateCostForFulfillmentGroup in interface FulfillmentPricingProvider
      Parameters:
      request - The request for which to estimate shipping.
      contextInfo - context information around sandbox and multitenant state
      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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: FulfillmentPricingProvider
      Retrieve all possible priced fulfillment options for the provided request. Intended to be used to display options to the customer for selection.
      Specified by:
      providePricedFulfillmentOptions in interface FulfillmentPricingProvider
      Parameters:
      request - The request for which to calculate shipping and return options.
      contextInfo - context information around sandbox and multitenant state
      Returns:
      All possible priced fulfillment options for the provided request.
    • getShipTables

      protected List<BandedFulfillmentPricingOption> getShipTables(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Gets a list of BandedFulfillmentPricingOptions based on the given ContextInfo.

      If BandedFulfillmentPricingOptions cannot be found, bandedFulfillmentPricingConfig would be used as a fallback.

      Parameters:
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a list of BandedFulfillmentPricingOptions based on the given ContextInfo
    • calculateCostForFulfillmentGroupInternal

      @Deprecated(since="1.1.0", forRemoval=true) protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroupInternal(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, boolean isEstimate)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • calculateCostForFulfillmentGroupInternal

      protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroupInternal(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, boolean isEstimate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • findBand

      protected final Optional<FulfillmentOptionBand> findBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
      Finds the correct FulfillmentOptionBand from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest.

      Extend findCustomBand(BandedFulfillmentPricingOption, FulfillmentPricingRequest) to handle any BandTypes not in DefaultBandTypes.

      Parameters:
      option - The fulfillment option to use to calculate pricing for the request
      request - The request for which to calculate shipping
      Returns:
      the correct FulfillmentOptionBand from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest.
    • findPriceBand

      protected Optional<FulfillmentOptionBand> findPriceBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
      Finds the correct price-based band from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest.
      Parameters:
      option - The fulfillment option to use to calculate pricing for the request
      request - The request for which to calculate shipping
      Returns:
      the correct price-based band from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest
    • findWeightBand

      protected Optional<FulfillmentOptionBand> findWeightBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
      Finds the correct item-weight-based band from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest.
      Parameters:
      option - The fulfillment option to use to calculate pricing for the request
      request - The request for which to calculate shipping
      Returns:
      the correctitem-weight-based band from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest
    • findCustomBand

      protected Optional<FulfillmentOptionBand> findCustomBand(@NonNull @NonNull BandedFulfillmentPricingOption option, @NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
      Extension point to handle BandTypes not in DefaultBandTypes.
      Parameters:
      option - The fulfillment option to use to calculate pricing for the request
      request - The request for which to calculate shipping
      Returns:
      the correct FulfillmentOptionBand from the BandedFulfillmentPricingOption for the given FulfillmentPricingRequest.
    • getDefaultBandedFulfillmentPricingOption

      protected BandedFulfillmentPricingOption getDefaultBandedFulfillmentPricingOption()
      Builds a BandedFulfillmentPricingOption with fields initialized to typical values.
      Returns:
      a BandedFulfillmentPricingOption with 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 of FulfillmentPricingItems to the calculated prices.
      Parameters:
      request - The request for which to calculate shipping
      option - The fulfillment option to use to calculate pricing for the request
      band - The band from option appropriate for the items being priced
      Returns:
      a map of FulfillmentPricingItems to 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 a FulfillmentOptionPricedResponse with the given inputs.
      Parameters:
      price - The value to set for FulfillmentOptionPricedResponse.getFulfillmentPriceCalculated().
      itemToPriceMap - Map of FulfillmentPricingItems to their fulfillment prices
      fulfillmentOption - The FulfillmentOption that forms the basis of the response
      isEstimate - Whether this is for estimating the fulfillment pricing
      Returns:
      a FulfillmentOptionPricedResponse for 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 for
      fulfillmentPriceAmounts - 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)
      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 not FulfillmentPricingItem.getSubtotal().
      Parameters:
      item - The FulfillmentPriceInfo item to be priced
      option - The applicable BandedFulfillmentPricingOption for the item
      band - The applicable band from the option for the item
      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 - The FulfillmentPriceInfo item to be priced
      option - The applicable BandedFulfillmentPricingOption for the item
      band - The applicable band from the option for the item
      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

      @Deprecated protected BandedFulfillmentPricingConfig getBandedFulfillmentPricingConfig()
    • getWeightCalculationService

      protected WeightCalculationService getWeightCalculationService()