Class ExternalCatalogSearchProvider<T extends Product>

java.lang.Object
com.broadleafcommerce.catalogbrowse.service.provider.external.AbstractExternalProvider
com.broadleafcommerce.catalogbrowse.service.provider.external.search.ExternalCatalogSearchProvider<T>
All Implemented Interfaces:
CatalogSearchProvider<T>

public class ExternalCatalogSearchProvider<T extends Product> extends AbstractExternalProvider implements CatalogSearchProvider<T>
Author:
Nathan Moore (nathandmoore)
  • Field Details

  • Constructor Details

    • ExternalCatalogSearchProvider

      public ExternalCatalogSearchProvider(@Qualifier("catalogSearchWebClient") org.springframework.web.reactive.function.client.WebClient catalogSearchWebClient, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PricingProvider browsePricingProvider, CatalogProvider browseCatalogProvider)
  • Method Details

    • fetchCategoryWithDetailsAndSearchResponse

      public Category fetchCategoryWithDetailsAndSearchResponse(@NonNull @NonNull CategoryDetailsRequest request)
      Specified by:
      fetchCategoryWithDetailsAndSearchResponse in interface CatalogSearchProvider<T extends Product>
    • getSearchResultsForCategory

      public SearchResponse<T> getSearchResultsForCategory(@NonNull @NonNull CatalogEntityDetailsRequest detailsRequest, @NonNull @NonNull Category category)
      Description copied from interface: CatalogSearchProvider
      Performs a search for products belonging to the provided category.
      Specified by:
      getSearchResultsForCategory in interface CatalogSearchProvider<T extends Product>
      Parameters:
      detailsRequest - The original category request
      category - The resolved category
      Returns:
      The search results for the category.
    • getSearchResults

      public SearchResponse<T> getSearchResults(@NonNull @NonNull CatalogSearchRequest request)
      Description copied from interface: CatalogSearchProvider
      Performs a search for the provided request.
      Specified by:
      getSearchResults in interface CatalogSearchProvider<T extends Product>
      Parameters:
      request - All of the relevant information to be used to retrieve search results.
      Returns:
      The SearchResponse with results for the request.
    • getSuggestions

      public TypeAheadResponse getSuggestions(@NonNull @NonNull CatalogTypeAheadRequest request)
      Description copied from interface: CatalogSearchProvider
      Gets suggestions for a search typeahead component based on the request.
      Specified by:
      getSuggestions in interface CatalogSearchProvider<T extends Product>
      Parameters:
      request - All of the relevant information to be used to retrieve type-ahead suggestions.
      Returns:
      The TypeAheadResponse with the results for the request.
    • getFullyHydratedProducts

      protected List<T> getFullyHydratedProducts(@NonNull @NonNull CatalogSearchRequest request, @NonNull @NonNull List<T> content)
    • getHydratedProductSuggestionsPricing

      protected List<Map<String,Object>> getHydratedProductSuggestionsPricing(@NonNull @NonNull List<Map<String,Object>> suggestions, @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)
      Hydrates pricing on product type-ahead suggetsions.
      Parameters:
      suggestions - Suggestions to be hydrated
      priceContext - PriceContext from the original request containing general pricing info
      priceInfoContext - PriceInfoContext from the original request containing info specific for getting PriceInfos such as prefetched PriceLists.
      contextInfo - ContextInfo from the original request containing tenant and sandbox info
      Returns:
      Hydrated product suggestions
    • hydrateProductPricing

      protected void hydrateProductPricing(@NonNull @NonNull Collection<T> 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)
      Hydrates pricing onto the results of a search request.
      Parameters:
      products - The products from the SearchResponse to be hydrated
      priceContext - PriceContext from the original request containing general pricing info
      priceInfoContext - PriceInfoContext from the original request containing info specific for getting PriceInfos such as prefetched PriceLists.
      contextInfo - ContextInfo from the original request containing tenant and sandbox info
    • assignDefaultProductPriceInfos

      protected void assignDefaultProductPriceInfos(@NonNull @NonNull Collection<T> products, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Parses the ProductPricingPredicate returned from the search results to add price details used by the pricing service to compute display results including the cost, base price, sale price, and pricing key for the product. If available, the system will override the product prices to those of it's lowest priced variant.
      Parameters:
      products - Search results whose contents to ensure to have a PriceInfos instead of simple prices.
      priceContext -
      contextInfo -
    • overrideProductPriceDetailsWithSkuData

      protected void overrideProductPriceDetailsWithSkuData(Product product, ProductPricingPredicate predicate)
      By default, this method overrides the product prices for display in search with the values from the lowest priced sku. This could be changed to utilize the default sku instead.
      Parameters:
      product -
      predicate -
    • updateBestPrice

      protected void updateBestPrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo)
    • addPriceDetailsFromProductData

      protected void addPriceDetailsFromProductData(Product product, ProductPricingPredicate predicate)
      Add price details from product's data.

      For DefaultPriceableFieldType.BASE_PRICE and DefaultPriceableFieldType.SALE_PRICE, if ProductPricingPredicate.getDefaultSku() exists and the price is available, then that price is used, otherwise use the price from the ProductPricingPredicate.

      Since:
      1.8.8, 2.0.1
    • addPriceDetailFromProductData

      protected void addPriceDetailFromProductData(Product product, DefaultPriceableFieldType fieldType, javax.money.MonetaryAmount price)
    • addPriceDetail

      protected void addPriceDetail(Product product, DefaultPriceableFieldType fieldType, @Nullable javax.money.MonetaryAmount price, boolean replaceExisting)
    • updatePricingKeyFromPredicate

      protected void updatePricingKeyFromPredicate(ProductPricingPredicate predicate, Product product)
      Adds the pricing key from the predicate to the product if the product does not already have a pricing key value.
    • setProductPriceInfos

      @Deprecated(forRemoval=true, since="1.8.2") protected void setProductPriceInfos(@NonNull @NonNull Collection<T> products, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Ensures that all Products with simple prices have those replaced with a PriceInfo.
      Parameters:
      products - Search results whose contents to ensure to have a PriceInfos instead of simple prices.
    • hydrateProductAssets

      protected void hydrateProductAssets(@NonNull @NonNull Collection<T> products, @Nullable org.springframework.util.MultiValueMap<String,String> parameters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Makes an additional call to the CatalogProvider to hydrate Assets for the search results.

      This hydration is gated by isHydrateAssets().

      Parameters:
      products - The search results.
      parameters - Additional parameters to include the request like filters
      contextInfo - Additional sandbox and multitenant state.
    • hydrateProductTags

      protected void hydrateProductTags(@NonNull @NonNull Collection<T> products, @Nullable org.springframework.util.MultiValueMap<String,String> parameters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Makes an additional call to the CatalogProvider to hydrate ProductTags for the search results.
      Parameters:
      products - The search results.
      parameters - Additional parameters to include the request like filters
      contextInfo - Additional sandbox and multitenant state.
    • convertSuggestionsToProducts

      protected List<T> convertSuggestionsToProducts(@NonNull @NonNull List<Map<String,Object>> suggestions)
    • convertSuggestionsToMap

      protected List<Map<String,Object>> convertSuggestionsToMap(@NonNull @NonNull List<T> suggestions)
    • buildCustomerContextHeader

      protected String buildCustomerContextHeader(org.springframework.util.MultiValueMap<String,String> customerParams, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • createCustomerContext

      protected CustomerContext createCustomerContext(org.springframework.util.MultiValueMap<String,String> customerParams, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getCustomerContextParams

      protected org.springframework.util.MultiValueMap<String,String> getCustomerContextParams(@Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Builds a org.springframework.util.MultiValueMap<String,String> that includes params related to the currently authenticated user and any dynamic customer segments that should be passed along to the backing service.
      Parameters:
      priceContext - PriceContext header.
      contextInfo - Additional tenant and sandbox info along with dynamic customer segments.
      Returns:
      A org.springframework.util.MultiValueMap<String,String> that includes params related to the currently authenticated user and any dynamic customer segments that should be passed along to the backing service.
    • getAuthenticationParams

      protected org.springframework.util.MultiValueMap<String,String> getAuthenticationParams()
      Builds a org.springframework.util.MultiValueMap<String,String> that includes params related to the currently authenticated user that should be passed along to the backing service. This is needed because the authentication in that service will belong to the Cart Operations Client rather than the authenticated user.
      Returns:
      A org.springframework.util.MultiValueMap<String,String> that includes params related to the currently authenticated user that should be passed along to the backing service
    • parseProductPricingPredicate

      @Nullable protected ProductPricingPredicate parseProductPricingPredicate(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Attempts to fetch the ProductPricingPredicate from the search response, if it exists. This is used for hydrating prices.
      Parameters:
      product -
      contextInfo -
      Returns:
    • getUrl

      public String getUrl()
    • getSearchUri

      public String getSearchUri()
    • getSuggestUri

      public String getSuggestUri()
    • isHydrateAssets

      public boolean isHydrateAssets()
    • getServiceClient

      public String getServiceClient()
    • getCatalogSearchWebClient

      protected org.springframework.web.reactive.function.client.WebClient getCatalogSearchWebClient()
    • getTypeFactory

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

      protected PricingProvider getBrowsePricingProvider()
    • getCatalogProvider

      protected CatalogProvider getCatalogProvider()
    • getProperties

      protected ExternalCatalogSearchProviderProperties getProperties()
    • setProperties

      @Autowired public void setProperties(ExternalCatalogSearchProviderProperties properties)