Class ExternalPricingProvider
- All Implemented Interfaces:
PricingProvider
- Author:
- Nathan Moore (nathandmoore)
-
Constructor Summary
ConstructorsConstructorDescriptionExternalPricingProvider(org.springframework.web.reactive.function.client.WebClient catalogBrowseWebClient, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, List<ProductPriceableTargetsBuilder> productPriceableTargetsBuilders, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddUserTargets(com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Deprecated, for removal: This API element is subject to removal in a future version.protected voidaddUserTargets(com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Add customer and customer segment user targets toPriceContext.getUserTargets().protected voidattachPriceInfoOnOtherEntity(@NonNull Object entity, @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) protected voidattachPriceInfosOnOtherEntity(@NonNull Object entity, @NonNull Collection<? extends com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Extension point to use to handle attaching pricing info onto a non-default type of priceable entity.protected ProductattachPricingToProduct(@NonNull Product product, @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Deprecated.UseattachPricingToProduct(Product, Map, SimplePage, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency.protected ProductattachPricingToProduct(@NonNull Product product, @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Handles attaching thePriceInfosreturned by the pricing service onto theProductand its related entities.attachPricingToProducts(@NonNull Collection<P> products, @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Deprecated.UseattachPricingToProducts(Collection, Map, SimplePage, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency.attachPricingToProducts(@NonNull Collection<P> products, @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Handles attaching thePriceInfosreturned by the pricing service onto theProductsand their related entities.protected voidbequeathItemChoicePricingToSpecificChoices(ItemChoice itemChoice) If anItemChoicehas aPriceInfo, then it needs to be inherited by all of itsSpecificItemChoicesunless they have an explicit override.protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<T>checkForPriceInfoForVariantFromPriceList(List<T> candidatePriceInfos, Variant variant) protected final voiddoAttachPricing(@NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Deprecated.UsedoAttachPricing(Map, SimplePage, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency.protected final voiddoAttachPricing(@NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
List<T>filterPriceInfosForCurrency(List<T> priceInfos, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
voidfixStandardPriceIfNeeded(T variantPriceInfo, List<T> candidatePriceInfos) protected org.springframework.web.reactive.function.client.WebClientprotected List<com.broadleafcommerce.pricing.client.domain.UserTargetRef>getCustomerSegmentTargetRefs(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.pricing.client.domain.UserTargetRef>protected com.broadleafcommerce.common.extension.intercommunication.ExternalClientprotected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<T>getPriceInfoForPriceableEntity(Priceable entity, List<T> candidatePriceInfos) Deprecated.UsegetPriceInfoForPriceableEntity(Priceable, List, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency.protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<T>getPriceInfoForPriceableEntity(Priceable entity, List<T> candidatePriceInfos, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Picks the appropriatePriceInfofor thePriceable entity.protected List<ProductPriceableTargetsBuilder>protected ExternalPricingProviderPropertiesprotected com.broadleafcommerce.common.extension.TypeFactorygetUrl()protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<T>hasPriceInfoFromPriceList(List<T> candidatePriceInfos) protected booleanisBasePrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) protected booleanisBaseSalePrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) protected booleanisDirectVariantPrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo, Variant variant) protected booleanisTargetingVariantSku(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo, Variant variant) protected SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo>makeRequest(@NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles making the actual request to the pricing service.priceProduct(@NonNull Product product, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates pricing info for the providedProductand its related priceable entities:Variant,IncludedProduct,SpecificItemChoice.priceProducts(@NonNull Collection<P> products, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates pricing info for the providedProductsand their related priceable entities:Variant,IncludedProduct,SpecificItemChoice.List<com.broadleafcommerce.pricing.client.domain.PriceInfo>priceTargets(@NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates pricing info for the provided targetsMapvoidsetExternalClient(com.broadleafcommerce.common.extension.intercommunication.ExternalClient externalClient) voidsetPriceInfosUri(String priceInfosUri) voidsetProperties(ExternalPricingProviderProperties properties) voidsetServiceClient(String serviceClient) voidprotected booleanvariantHasPrice(Variant variant) Methods inherited from class com.broadleafcommerce.catalogbrowse.service.provider.external.AbstractExternalProvider
getAuthenticationUtils, getExternalProviderProperties, getHeaders, getHeaders, getMapper, isCallerWhitelistedService, setAuthenticationUtils, setExternalProviderProperties
-
Constructor Details
-
ExternalPricingProvider
public ExternalPricingProvider(@Qualifier("catalogBrowseWebClient") org.springframework.web.reactive.function.client.WebClient catalogBrowseWebClient, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, List<ProductPriceableTargetsBuilder> productPriceableTargetsBuilders, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
-
-
Method Details
-
priceProduct
public Product priceProduct(@NonNull @NonNull Product product, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates pricing info for the providedProductand its related priceable entities:Variant,IncludedProduct,SpecificItemChoice.This implementation will mutate the given
productif price infos are returned.- Specified by:
priceProductin interfacePricingProvider- Parameters:
product- The product to pricepriceContext-PriceContextfrom the original request containing general pricing infopriceInfoContext-PriceInfoContextfrom the original request containing info specific for gettingPriceInfossuch as prefetchedPriceLists.contextInfo-ContextInfofrom the original request containing tenant info- Returns:
- The product with pricing attached.
-
priceTargets
public List<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceTargets(@NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PricingProviderPopulates pricing info for the provided targetsMap- Specified by:
priceTargetsin interfacePricingProvider- Parameters:
targetsMap- The targets to pricepriceContext-PriceContextfrom the original request containing general pricing infopriceInfoContext-PriceInfoContextfrom the original request containing info specific for gettingPriceInfossuch as prefetchedPriceLists.contextInfo-ContextInfofrom the original request containing tenant info- Returns:
- The price infos for the targets
-
priceProducts
public <P extends Product> List<P> priceProducts(@NonNull @NonNull Collection<P> products, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates pricing info for the providedProductsand their related priceable entities:Variant,IncludedProduct,SpecificItemChoice.This implementation will mutate the given
productsif price infos are returned.- Specified by:
priceProductsin interfacePricingProvider- Parameters:
products- The products to pricepriceContext-PriceContextfrom the original request containing general pricing infopriceInfoContext-PriceInfoContextfrom the original request containing info specific for gettingPriceInfossuch as prefetchedPriceLists.contextInfo-ContextInfofrom the original request containing tenant info- Returns:
- The products with pricing attached.
-
makeRequest
protected SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> makeRequest(@NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles making the actual request to the pricing service.- Parameters:
targetsMap- A map of entities to thePriceableTargetsbased upon thempriceContext-PriceContextfrom the original request containing general pricing infopriceInfoContext-PriceInfoContextfrom the original request containing info specific for gettingPriceInfossuch as prefetchedPriceLists.contextInfo-ContextInfofrom the original request containing tenant info- Returns:
- The response from the pricing service
-
addUserTargets
@Deprecated(forRemoval=true) protected void addUserTargets(@Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Deprecated, for removal: This API element is subject to removal in a future version. -
addUserTargets
protected void addUserTargets(@Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Add customer and customer segment user targets toPriceContext.getUserTargets(). Uses the current authentication token to determine principal and details.- Parameters:
priceContext- The priceContext to add user targets tocontextInfo- Additional tenant and sandbox info
-
getCustomerTargetRefs
-
getCustomerSegmentTargetRefs
protected List<com.broadleafcommerce.pricing.client.domain.UserTargetRef> getCustomerSegmentTargetRefs(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
attachPricingToProduct
@Deprecated(since="1.8.2") protected Product attachPricingToProduct(@NonNull @NonNull Product product, @NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Deprecated.UseattachPricingToProduct(Product, Map, SimplePage, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency. -
attachPricingToProduct
protected Product attachPricingToProduct(@NonNull @NonNull Product product, @NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Handles attaching thePriceInfosreturned by the pricing service onto theProductand its related entities. For convenience, all of them should already be present as the keys oftargetsMap.By default, the
productis merely passed through since all the price infos are attached to their respective owners via references intargetsMap. However,productis provided if implementors want to use a non-mutating method of attaching the price infos.- Parameters:
product-Productonto which to attach pricing infotargetsMap- A map of entities to thePriceableTargetsbased upon thempriceInfos-PriceInfosreturned from the pricing service- Returns:
- The product with price infos attached
-
attachPricingToProducts
@Deprecated(since="1.8.2") protected <P extends Product> List<P> attachPricingToProducts(@NonNull @NonNull Collection<P> products, @NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Deprecated.UseattachPricingToProducts(Collection, Map, SimplePage, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency. -
attachPricingToProducts
protected <P extends Product> List<P> attachPricingToProducts(@NonNull @NonNull Collection<P> products, @NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Handles attaching thePriceInfosreturned by the pricing service onto theProductsand their related entities. For convenience, all of them should already be present as the keys oftargetsMap.By default, the
productsis merely passed through since all the price infos are attached to their respective owners via references intargetsMap. However,productsis provided if implementors want to use a non-mutating method of attaching the price infos.- Parameters:
products-Productsonto which to attach pricing infotargetsMap- A map of entities to thePriceableTargetsbased upon thempriceInfos-PriceInfosreturned from the pricing service- Returns:
- The product with price infos attached
-
doAttachPricing
@Deprecated(since="1.8.2") protected final void doAttachPricing(@NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Deprecated.UsedoAttachPricing(Map, SimplePage, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency. -
doAttachPricing
protected final void doAttachPricing(@NonNull @NonNull Map<Object, Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) -
getPriceInfoForPriceableEntity
@Deprecated(since="1.8.2") protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<T> getPriceInfoForPriceableEntity(Priceable entity, List<T> candidatePriceInfos) Deprecated.UsegetPriceInfoForPriceableEntity(Priceable, List, PriceContext)Passing thePriceContextsupports proper filtering ofPriceInforesults that are in the proper currency. -
getPriceInfoForPriceableEntity
protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<T> getPriceInfoForPriceableEntity(Priceable entity, List<T> candidatePriceInfos, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Picks the appropriatePriceInfofor thePriceable entity. The candidates are all the infos that matched thePriceableTargetscreated for the entity in the pricing request.Multiple targets will be created for a single
Product, one targetingProduct.getSku()and one targetingProduct.getPricingKey(). In this case, whichever has the lower price will be selected.When a
Variantdoes not have adefaultorsaleprice, multiple targets will be created, one targetingVariant.getSku()and one targetingProduct.getPricingKey(). In this case, if there is a SKU-targeted price that is not a base price, such as price data from a price list, it will always be selected. Otherwise, it will use the price targetingProduct.getPricingKey(), so that the product's best price based onProduct.getPricingKey()would be used for theVariant.However, if a
Variantdoes have adefaultorsaleprice, then only one target will be created, based onVariant.getSku(). This way, theVariant's own pricing will always be used and never be affected by product's pricing.In some cases, multiple targets will be created for a single entity such as for
SpecificItemChoice, which may have pricing targeting it specifically, or, instead, its underlyingProductorVariant.Default is to just choose the first match except in the case of
IncludedProductandSpecificItemChoicewhere we check for an info targeting them directly. ForIncludedProductsif not present, then we choose the first candidate. ForSpecificItemChoice, we check that it hasn't already inherited its parentItemChoice's pricing, which should be retained; otherwise, we choose the first candidate.- Parameters:
entity- Entity for which to determine the appropriatecandidatePriceInfosto attach.candidatePriceInfos- ThePriceInfosmatching the targets made for theentity.priceContext- ThePriceContextwith the requested currency.- Returns:
- The chosen
PriceInfo.
-
filterPriceInfosForCurrency
-
fixStandardPriceIfNeeded
protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo> void fixStandardPriceIfNeeded(T variantPriceInfo, List<T> candidatePriceInfos) -
variantHasPrice
-
checkForPriceInfoForVariantFromPriceList
-
hasPriceInfoFromPriceList
-
bequeathItemChoicePricingToSpecificChoices
If anItemChoicehas aPriceInfo, then it needs to be inherited by all of itsSpecificItemChoicesunless they have an explicit override.- Parameters:
itemChoice- TheItemChoicewhose specific choices need to inherit pricing from.
-
isDirectVariantPrice
protected boolean isDirectVariantPrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo, Variant variant) -
isBasePrice
protected boolean isBasePrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) -
isBaseSalePrice
protected boolean isBaseSalePrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) -
isTargetingVariantSku
protected boolean isTargetingVariantSku(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo, Variant variant) -
attachPriceInfosOnOtherEntity
protected void attachPriceInfosOnOtherEntity(@NonNull @NonNull Object entity, @NonNull @NonNull Collection<? extends com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos) Extension point to use to handle attaching pricing info onto a non-default type of priceable entity. Default entities areProduct,Variant,IncludedProduct,ItemChoice, andSpecificItemChoice.- Parameters:
entity- Entity to attachpriceInfoontopriceInfos-PriceInfosthat match thePriceableTarget(s)created for theentity
-
attachPriceInfoOnOtherEntity
@Deprecated protected void attachPriceInfoOnOtherEntity(@NonNull @NonNull Object entity, @NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) -
getServiceClient
-
getPriceInfosUri
-
getUrl
-
setPriceInfosUri
-
setServiceClient
-
setUrl
-
getCatalogBrowseWebClient
protected org.springframework.web.reactive.function.client.WebClient getCatalogBrowseWebClient() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getProductPriceableTargetsBuilders
-
getProperties
-
setProperties
-
getExternalClient
protected com.broadleafcommerce.common.extension.intercommunication.ExternalClient getExternalClient() -
setExternalClient
@Autowired @Qualifier("browsePricingExternalClient") public void setExternalClient(com.broadleafcommerce.common.extension.intercommunication.ExternalClient externalClient)
-
addUserTargets(PriceContext, ContextInfo)