Class ExternalPricingProvider
- java.lang.Object
-
- com.broadleafcommerce.catalogbrowse.service.provider.external.AbstractExternalProvider
-
- com.broadleafcommerce.catalogbrowse.service.provider.external.pricing.ExternalPricingProvider
-
- All Implemented Interfaces:
PricingProvider
@ConfigurationProperties("broadleaf.catalogbrowse.pricingprovider") public class ExternalPricingProvider extends AbstractExternalProvider implements PricingProviderConnects to an external pricing service.- Author:
- Nathan Moore (nathandmoore)
-
-
Constructor Summary
Constructors Constructor Description ExternalPricingProvider(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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddUserTargets(com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)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)Handles attaching thePriceInfosreturned by the pricing service onto theProductand its related entities.protected <P extends Product>
List<P>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)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 voiddoAttachPricing(@NonNull Map<Object,Set<com.broadleafcommerce.pricing.client.domain.PriceableTarget>> targetsMap, @NonNull SimplePage<com.broadleafcommerce.pricing.client.domain.PriceInfo> priceInfos)protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsgetAuthenticationUtils()protected org.springframework.web.reactive.function.client.WebClientgetCatalogBrowseWebClient()protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo>
Optional<T>getPriceInfoForPriceableEntity(Priceable entity, List<T> candidatePriceInfos)Picks the appropriatePriceInfofor thePriceable entity.StringgetPriceInfosUri()The URI path for pricing items.protected List<ProductPriceableTargetsBuilder>getProductPriceableTargetsBuilders()StringgetServiceClient()The service client to use when interacting with pricing service.protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()StringgetUrl()The base url for an external cart service.protected booleanisBasePrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)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.ProductpriceProduct(@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.<P extends Product>
List<P>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.voidsetPriceInfosUri(String priceInfosUri)The URI path for pricing items.voidsetServiceClient(String serviceClient)The service client to use when interacting with pricing service.voidsetUrl(String url)The base url for an external cart service.-
Methods inherited from class com.broadleafcommerce.catalogbrowse.service.provider.external.AbstractExternalProvider
getHeaders, getMapper
-
-
-
-
Constructor Detail
-
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 Detail
-
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.
-
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
protected void addUserTargets(@Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)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 to
-
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)
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
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)
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
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)
-
getPriceInfoForPriceableEntity
protected <T extends com.broadleafcommerce.pricing.client.domain.PriceInfo> Optional<T> getPriceInfoForPriceableEntity(Priceable entity, List<T> candidatePriceInfos)
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.- Returns:
- The chosen
PriceInfo.
-
bequeathItemChoicePricingToSpecificChoices
protected void bequeathItemChoicePricingToSpecificChoices(ItemChoice itemChoice)
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.
-
isBasePrice
protected boolean isBasePrice(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)
-
getCatalogBrowseWebClient
protected org.springframework.web.reactive.function.client.WebClient getCatalogBrowseWebClient()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getProductPriceableTargetsBuilders
protected List<ProductPriceableTargetsBuilder> getProductPriceableTargetsBuilders()
-
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
-
getUrl
public String getUrl()
The base url for an external cart service.
-
setUrl
public void setUrl(String url)
The base url for an external cart service.
-
getPriceInfosUri
public String getPriceInfosUri()
The URI path for pricing items.
-
setPriceInfosUri
public void setPriceInfosUri(String priceInfosUri)
The URI path for pricing items.
-
getServiceClient
public String getServiceClient()
The service client to use when interacting with pricing service. Default is "catalogbrowseclient"
-
setServiceClient
public void setServiceClient(String serviceClient)
The service client to use when interacting with pricing service. Default is "catalogbrowseclient"
-
-