Class FixedFulfillmentPricingProvider
java.lang.Object
com.broadleafcommerce.shipping.service.integrations.fixed.FixedFulfillmentPricingProvider
- All Implemented Interfaces:
FulfillmentPricingProvider
Simple implementation of
FulfillmentPricingProvider for implementations that require
fixed shipping configuration for it's fulfillment options. For banded or tiered shipping, see
BandedFulfillmentPricingProvider. Alternatively, a FulfillmentPricingProvider
integrated with a 3rd party, such as ShipEngine, is preferred.
By default, FixedFulfillmentPricingProperties.getShipTables(ContextInfo) is used to
retrieve the properties based on a given ContextInfo. If not found,
FixedFulfillmentPricingConfig provided by
FixedFulfillmentPricingProperties.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 Summary
ConstructorsConstructorDescriptionFixedFulfillmentPricingProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, FixedFulfillmentPricingProperties fixedShipProps) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsebuildFulfillmentOptionPricedResponse(@NonNull javax.money.MonetaryAmount price, @NonNull Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem, javax.money.MonetaryAmount> itemToPriceMap, @NonNull FixedFulfillmentPricingOption 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 FixedFulfillmentPricingOption option) Builds a map ofFulfillmentPricingItemsto the calculated prices.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsecalculateCostForFulfillmentGroup(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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) Deprecated, for removal: This API element is subject to removal in a future version.protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsecalculateCostForFulfillmentGroupInternal(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, boolean isEstimate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected javax.money.MonetaryAmountcalculateFixedPriceForItem(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FixedFulfillmentPricingOption option, @NonNull javax.money.CurrencyUnit currency) protected javax.money.MonetaryAmountcalculateFulfillmentGroupPriceBeforeAdjustments(@NonNull FixedFulfillmentPricingOption option, javax.money.CurrencyUnit expectedCurrency) protected javax.money.MonetaryAmountcalculatePercentageRateForItem(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FixedFulfillmentPricingOption option, @NonNull javax.money.CurrencyUnit currency) Deprecated.protected javax.money.MonetaryAmountcalculatePercentageRateForItems(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FixedFulfillmentPricingOption option, @NonNull javax.money.CurrencyUnit currency) protected javax.money.MonetaryAmountcalculatePriceForItem(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FixedFulfillmentPricingOption option, @NonNull javax.money.CurrencyUnit currency) Deprecated.protected javax.money.MonetaryAmountcalculatePriceForItems(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull FixedFulfillmentPricingOption option, @NonNull javax.money.CurrencyUnit currency) Calculates the price for a fulfillment items.booleancanCalculateCostForOption(@NonNull String fulfillmentOptionName, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Whether this provider has knowledge of the provided option and thus can provide cost information for it.booleancanProvidePricedFulfillmentOptions(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponseestimateCostForFulfillmentGroup(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Estimate shipping for a request that includes a specified fulfillment option.protected FixedFulfillmentPricingOptiongetDefaultFixedFulfillmentPricingOption(javax.money.CurrencyUnit expectedCurrency) Builds aFixedFulfillmentPricingOptionwith fields initialized to typical values.protected FixedFulfillmentPricingConfigDeprecated.since 1.1.0, in favor ofFixedFulfillmentPricingProperties.getShipTables(ContextInfo)protected FixedFulfillmentPricingPropertiesprotected 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.ObjectMapperprotected List<FixedFulfillmentPricingOption>getShipTables(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets a list ofFixedFulfillmentPricingOptionsbased on the givenContextInfo.protected com.broadleafcommerce.common.extension.TypeFactoryvoidinit()Reads in the configuration file defined byFixedFulfillmentPricingProperties.getConfigPath()and initializesfixedFulfillmentPricingConfigto the result.protected voidpreRequest(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse>providePricedFulfillmentOptions(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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, waitMethods inherited from interface com.broadleafcommerce.shipping.service.integrations.FulfillmentPricingProvider
calculateCostForFulfillmentGroup, canCalculateCostForOption, canProvidePricedFulfillmentOptions, estimateCostForFulfillmentGroup, getFulfillmentOptionPricingResponses, providePricedFulfillmentOptions
-
Constructor Details
-
FixedFulfillmentPricingProvider
public FixedFulfillmentPricingProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, FixedFulfillmentPricingProperties fixedShipProps)
-
-
Method Details
-
init
@PostConstruct public void init()Reads in the configuration file defined byFixedFulfillmentPricingProperties.getConfigPath()and initializesfixedFulfillmentPricingConfigto the result.- Throws:
UncheckedIOException- Thrown when there is an error while reading the configuration file or converting its contents into aFixedFulfillmentPricingConfig.
-
calculateCostForFulfillmentGroup
public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:FulfillmentPricingProviderCalculate shipping for a request that includes a specified fulfillment option.- Specified by:
calculateCostForFulfillmentGroupin interfaceFulfillmentPricingProvider- 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(@NonNull @NonNull String fulfillmentOptionName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.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(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.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: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.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:FulfillmentPricingProviderWhether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"- Specified by:
canProvidePricedFulfillmentOptionsin interfaceFulfillmentPricingProvider- Parameters:
fulfillmentPricingRequest- The request used to identify relevant fulfillment optionscontextInfo- context information around sandbox and multitenant state- Returns:
- Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"
-
getShipTables
protected List<FixedFulfillmentPricingOption> getShipTables(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets a list ofFixedFulfillmentPricingOptionsbased on the givenContextInfo.If
FixedFulfillmentPricingOptionscannot be found,fixedFulfillmentPricingConfigwould be used as a fallback.- Parameters:
contextInfo- context information around sandbox and multitenant state- Returns:
- a list of
FixedFulfillmentPricingOptionsbased on the givenContextInfo
-
buildItemToPriceMap
protected Map<com.broadleafcommerce.shipping.domain.FulfillmentPricingItem,javax.money.MonetaryAmount> buildItemToPriceMap(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest request, @NonNull @NonNull FixedFulfillmentPricingOption option) 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 therequest- Returns:
- a map of
FulfillmentPricingItemsto the calculated prices.
-
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.since 1.1.0, in favor ofcalculateCostForFulfillmentGroupInternal(FulfillmentPricingRequest, boolean, ContextInfo) -
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) -
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 FixedFulfillmentPricingOption 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 FixedFulfillmentPricingOption option, 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 FixedFulfillmentPricingOption option, @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 applicableFixedFulfillmentPricingOptionfor theitem- Returns:
- the price for a fulfillment item.
-
calculatePriceForItems
protected javax.money.MonetaryAmount calculatePriceForItems(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull FixedFulfillmentPricingOption 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- TheFulfillmentPriceInfoitem to be pricedoption- The applicableFixedFulfillmentPricingOptionfor theitem- Returns:
- the price for a fulfillment items.
-
calculateFixedPriceForItem
protected javax.money.MonetaryAmount calculateFixedPriceForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull FixedFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency) -
calculatePercentageRateForItem
@Deprecated protected javax.money.MonetaryAmount calculatePercentageRateForItem(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull FixedFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency) Deprecated. -
calculatePercentageRateForItems
protected javax.money.MonetaryAmount calculatePercentageRateForItems(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingItem item, @NonNull @NonNull FixedFulfillmentPricingOption option, @NonNull @NonNull javax.money.CurrencyUnit currency) -
getDefaultFixedFulfillmentPricingOption
protected FixedFulfillmentPricingOption getDefaultFixedFulfillmentPricingOption(javax.money.CurrencyUnit expectedCurrency) Builds aFixedFulfillmentPricingOptionwith fields initialized to typical values.- Returns:
- a
FixedFulfillmentPricingOptionwith fields initialized to typical values.
-
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() -
getFixedShipProps
-
getFixedFulfillmentPricingConfig
Deprecated.since 1.1.0, in favor ofFixedFulfillmentPricingProperties.getShipTables(ContextInfo)
-
calculateCostForFulfillmentGroupInternal(FulfillmentPricingRequest, boolean, ContextInfo)