Class VirtualFulfillmentPricingProvider

java.lang.Object
com.broadleafcommerce.shipping.service.integrations.virtual.VirtualFulfillmentPricingProvider
All Implemented Interfaces:
FulfillmentPricingProvider

public class VirtualFulfillmentPricingProvider extends Object implements FulfillmentPricingProvider
  • Constructor Details

    • VirtualFulfillmentPricingProvider

      public VirtualFulfillmentPricingProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, VirtualFulfillmentPricingProperties virtualShipProps)
  • Method Details

    • init

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

      public List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse> providePricedFulfillmentOptions(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.
    • canProvidePricedFulfillmentOptions

      public boolean canProvidePricedFulfillmentOptions(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"
    • calculateCostForFulfillmentGroup

      public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroup(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @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:
      request - 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(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.
    • estimateCostForFulfillmentGroup

      public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse estimateCostForFulfillmentGroup(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.
    • getFulfillmentOptions

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

      If VirtualFulfillmentPricingOptions cannot be found, virtualFulfillmentPricingConfig would be used as a fallback.

      Parameters:
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a list of VirtualFulfillmentPricingOptions 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)
      Calculates the shipping costs of the fulfillment items based on the fulfillment option on the request. Handles the shared logic of calculateCostForFulfillmentGroup(FulfillmentPricingRequest, ContextInfo) and estimateCostForFulfillmentGroup(FulfillmentPricingRequest, ContextInfo).
      Parameters:
      request - The request for which to calculate shipping
      isEstimate - Whether or not the shipping should be estimated
      contextInfo - Context information around sandbox and multitenant state
      Returns:
      fulfillment price information for request based on the fulfillment option.
    • buildItemToPriceMap

      protected Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem,javax.money.MonetaryAmount> buildItemToPriceMap(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @NonNull @NonNull VirtualFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency)
      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
      Returns:
      a map of FulfillmentPricingItems to the calculated prices.
    • calculatePriceForItem

      @Deprecated protected javax.money.MonetaryAmount calculatePriceForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull VirtualFulfillmentPricingOption option, @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 VirtualFulfillmentPricingOption 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 VirtualFulfillmentPricingOption option, @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 VirtualFulfillmentPricingOption 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 VirtualFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency)
      Calculates the fixed price for the fulfillment item, i.e. the price per item plus any flat rates for this item.
      Parameters:
      item - The FulfillmentPriceInfo item to be priced
      option - The applicable VirtualFulfillmentPricingOption for the item
      Returns:
      the fixed price for a fulfillment item.
    • calculatePercentageBasedPriceForItem

      @Deprecated protected javax.money.MonetaryAmount calculatePercentageBasedPriceForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull VirtualFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency)
      Calculates the fulfillment price based on the percentage rate per item.
      Parameters:
      item - The FulfillmentPriceInfo item to be priced
      option - The applicable VirtualFulfillmentPricingOption for the item
      Returns:
      the percentage rate price for a fulfillment item.
    • calculatePercentageBasedPriceForItems

      protected javax.money.MonetaryAmount calculatePercentageBasedPriceForItems(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull VirtualFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency)
    • calculateFulfillmentGroupPriceBeforeAdjustments

      protected javax.money.MonetaryAmount calculateFulfillmentGroupPriceBeforeAdjustments(@NonNull @NonNull VirtualFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency)
      Calculates the fixed fulfillment price per fulfillment group.
      Parameters:
      option - The applicable VirtualFulfillmentPricingOption for the fulfillment group
      Returns:
      the fixed fulfillment price per fulfillment group
    • 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
    • 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 VirtualFulfillmentPricingOption 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.
    • getDefaultVirtualFulfillmentPricingOption

      protected VirtualFulfillmentPricingOption getDefaultVirtualFulfillmentPricingOption(@NonNull @NonNull javax.money.CurrencyUnit currency)
      Builds a VirtualFulfillmentPricingOption with fields initialized to typical values.
      Returns:
      a VirtualFulfillmentPricingOption with fields initialized to typical values.
    • resolveCurrency

      protected javax.money.CurrencyUnit resolveCurrency(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request)
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getVirtualShipProps

      protected VirtualFulfillmentPricingProperties getVirtualShipProps()
    • getVirtualFulfillmentPricingConfig

      @Deprecated protected VirtualFulfillmentPricingConfig getVirtualFulfillmentPricingConfig()