Class RelatedProductsProductContextContributor

java.lang.Object
com.broadleafcommerce.catalog.service.product.commerce.context.contributor.RelatedProductsProductContextContributor
All Implemented Interfaces:
ProductDetailsContextContributor, org.springframework.core.Ordered

public class RelatedProductsProductContextContributor extends Object implements ProductDetailsContextContributor
Contributes all of the related products and categories' products to the ProductDetailsContext. This will look through all of the IncludedProducts and ItemChoices. By default, this will not look deeper than the first level of item choices: ItemChoices of a SpecificItemChoice's product will be ignored.

This should run after RelatedCategoriesProductContextContributor since we want to get all of the products for each of those categories at the same time as the rest of the related products.

Extend contributeOtherProductIds(java.util.Collection<? extends com.broadleafcommerce.catalog.domain.product.commerce.ProductDetailsContext>, com.broadleafcommerce.data.tracking.core.context.ContextInfo) to contribute other product IDs before fetching all of the related products.

Author:
Nathan Moore (nathandmoore)
  • Field Details

  • Constructor Details

    • RelatedProductsProductContextContributor

      public RelatedProductsProductContextContributor(CategoryProductService<CategoryProduct> categoryProductService, ProductService<Product> productService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser rsqlFilterParser)
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • contribute

      public <T extends ProductDetailsContext> Collection<T> contribute(Collection<T> productDetailsContexts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductDetailsContextContributor
      Contributes to the supplied ProductDetailsContext. This should not mutate the inputted context, but return a new one with the new contributions.
      Specified by:
      contribute in interface ProductDetailsContextContributor
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      A version of the supplied ProductDetailsContext with the new contributions.
    • getRelatedPromotionalProductIdsToContribute

      protected Map<String,Set<String>> getRelatedPromotionalProductIdsToContribute(@NonNull @NonNull Collection<? extends ProductDetailsContext> productDetailsContexts)
      Creates a map of resolved Product IDs to a collection of promotional product's related product IDs.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      Returns:
      A map of resolved Product IDs to a collection of promotional product's related product IDs.
    • getIncludedProductIdsToContribute

      protected Map<String,Set<String>> getIncludedProductIdsToContribute(@NonNull @NonNull List<Product> resolvedProducts)
      Gets the set of product IDs from related IncludedProducts.
      Parameters:
      resolvedProducts - The Products resolved for the ProductDetailsRequests.
      Returns:
      the set of product IDs from related IncludedProducts.
    • getSpecificChoiceProductsIdsToContribute

      protected Map<String,Set<String>> getSpecificChoiceProductsIdsToContribute(@NonNull @NonNull List<Product> resolvedProducts)
      Gets the set of product IDs from related SpecificItemChoice.
      Parameters:
      resolvedProducts - The Products resolved for the ProductDetailsRequests.
      Returns:
      the set of product IDs from related SpecificItemChoice.
    • getCategoryToProductMapToContribute

      protected Map<String,Map<String,Set<String>>> getCategoryToProductMapToContribute(@NonNull @NonNull Collection<? extends ProductDetailsContext> productDetailsContexts, @NonNull @NonNull List<Product> resolvedProducts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Collects the IDs of all the products related to the resolved products through related CategoryProducts. Returns a map of the product IDs to the IDs of their Categories.

      Note that only the product IDs are hydrated onto the CategoryProduct so there's no point in saving the entire product ref here.

      Parameters:
      productDetailsContexts - The contexts to which to contribute
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      a map of the product IDs to the IDs of their Categories.
    • contributeOtherProductIds

      protected Set<String> contributeOtherProductIds(@NonNull @NonNull Collection<? extends ProductDetailsContext> productDetailsContexts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Extension point for contributing other product IDs to the set.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      A set of product IDs related to the resolved product.
    • contributeRelatedProducts

      protected <T extends ProductDetailsContext> Collection<T> contributeRelatedProducts(@NonNull @NonNull Collection<T> productDetailsContexts, @NonNull @NonNull Set<String> productIds, @NonNull @NonNull Map<String,Set<String>> relatedProductsMap, @NonNull @NonNull Map<String,Map<String,Set<String>>> categoryProductsMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Fetches and contributes the related products to the ProductDetailsContext.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      productIds - Ids of the Products to fetch and contribute
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      A version of the supplied ProductDetailsContext with the new contributions.
    • contributeRelatedCategoryProducts

      protected <T extends ProductDetailsContext> Collection<T> contributeRelatedCategoryProducts(@NonNull @NonNull Collection<T> productDetailsContexts, @NonNull @NonNull Map<String,Map<String,Set<String>>> categoryProductsMap)
      Contributes the related category products to the ProductDetailsContext.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      categoryProductsMap - Map of category IDs to Product IDs for the CategoryProducts to contribute.
      Returns:
      A version of the supplied ProductDetailsContext with the new contributions.
    • contributeProductsOfRuleBasedCategories

      protected <T extends ProductDetailsContext> Collection<T> contributeProductsOfRuleBasedCategories(@NonNull @NonNull Collection<T> productDetailsContexts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Handles contributing the products related to related rule-based categories separately from other related products. This will evaluate each rule-based category's membership rule and contribute the related products discovered along with maintaining the mapping from the category to its related products.
      Type Parameters:
      T - The specific type of the ProductDetailsContexts in use
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      contextInfo - Additional sandbox and tenancy info
      Returns:
      A version of the supplied ProductDetailsContext with the new contributions.
    • getCategoryProductService

      protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getProductService

      protected ProductService<Product> getProductService()
    • getTypeFactory

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

      protected com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser getRsqlFilterParser()