Class ItemChoiceHierarchyProductContextContributor

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

public class ItemChoiceHierarchyProductContextContributor extends Object implements ProductDetailsContextContributor
Contributes all the related products, related variants, and specific choice categories for the item choice hierarchy.
Author:
Marie Standeven (marieStandeven)
  • Field Details

  • Constructor Details

  • 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.
    • populateProductItemChoices

      protected Collection<? extends ProductDetailsContext> populateProductItemChoices(Collection<? extends ProductDetailsContext> productDetailsContexts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Loops through the productDetailsContexts to populate product options item choices up to the maximum depth.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      contextInfo - Context information surrounding sandboxing/multitenant state
      Returns:
      the productDetailsContexts after contributing the item choice categories, products, and variants
    • populateProductItemChoices

      protected Map<String,Set<ProductDetails>> populateProductItemChoices(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<ProductDetails>> productDetailsMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Responsible for population of item choice categories, products, and variants of depths greater than one.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      productDetailsMap - The product details to fetch the item choices from
      contextInfo - Context information surrounding sandboxing/multitenant state
      Returns:
      The next level of products to populate the item choices for.
    • retrieveNextLevelProducts

      protected Map<String,Set<ProductDetails>> retrieveNextLevelProducts(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<ProductDetails>> previosProductDetailMap, boolean firstIteration)
      Retrieves the map of ProductDetails to recursively build out the item choice hierarchy structure.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      Returns:
      The next level of configurable products.
    • buildProductDetailsMap

      protected Set<ProductDetails> buildProductDetailsMap(ProductDetailsContext productDetailsContext, Product product)
      Filters through the category and product options to collect the next set of ProductDetails.
      Parameters:
      productDetailsContext - The context to which to contribute
      product - The product to fetch the next level products from
      Returns:
      The set of configurable products from this product's item choices.
    • buildCategoryIdMap

      protected Map<String,Set<String>> buildCategoryIdMap(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<ProductDetails>> productMap, boolean firstIteration)
      Builds a mapping of item choice category IDs for the associated productDetailsContext.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      productMap - Set of products keyed to the product details context
      firstIteration - Whether this is the first iteration
      Returns:
      The set of item choice category IDs mapped to the productDetailsContext.
    • filterCategoryIdsToQuery

      protected Set<String> filterCategoryIdsToQuery(ProductDetailsContext productDetailsContext, Product product)
      Filters the category IDs to the ones not currently in the specific category choices.
      Parameters:
      productDetailsContext - The context to which to contribute
      product - The product to fetch the category IDs from
      Returns:
      The category IDs for this productDetailsContext not found in the specific category choices.
    • buildProductIdMap

      protected Map<String,Set<String>> buildProductIdMap(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<ProductDetails>> productMap, boolean firstIteration)
      Builds a mapping of item choice product IDs for the associated productDetailsContext.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      productMap - Set of products keyed to the product details context
      firstIteration - Whether this is the first iteration
      Returns:
      The set of item choice product IDs mapped to the productDetailsContext.
    • filterProductIdsToQuery

      protected Set<String> filterProductIdsToQuery(ProductDetailsContext productDetailsContext, Product product)
      Filters the product IDs to the ones not currently in the related products.
      Parameters:
      productDetailsContext - The context to which to contribute
      product - The product to fetch the product IDs from
      Returns:
      The product IDs for this productDetailsContext not found in the related products.
    • buildVariantIdMap

      protected Map<String,Set<String>> buildVariantIdMap(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<ProductDetails>> productMap, boolean firstIteration)
      Builds a mapping of item choice variant IDs for the associated productDetailsContext.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      productMap - Set of products keyed to the product details context
      firstIteration - Whether this is the first iteration
      Returns:
      The set of item choice variant IDs mapped to the productDetailsContext.
    • filterVariantIdsToQuery

      protected Set<String> filterVariantIdsToQuery(ProductDetailsContext productDetailsContext, Product product)
      Filters the variant IDs to the ones not currently in the related products.
      Parameters:
      productDetailsContext - The context to which to contribute
      product - The product to fetch the variant IDs from
      Returns:
      The variant IDs for this productDetailsContext not found in the related variants.
    • filterCategoryProductIdsToQuery

      protected Map<String,Set<String>> filterCategoryProductIdsToQuery(Collection<? extends ProductDetailsContext> productDetailsContexts, Collection<? extends CategoryProduct> categoryProducts)
      Filters the category product IDs to the ones not currently in the related products.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      categoryProducts - Collection of category products to filter on
      Returns:
      The product IDs from the item choice category for this productDetailsContext not found in the related products.
    • addItemChoiceRelatedVariants

      protected void addItemChoiceRelatedVariants(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<String>> variantIdsProductMap, Map<String,Set<String>> productIdsMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Queries for the item choice variants and adds them to the productDetailsContext's related variants.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      variantIdsProductMap - Set of variant IDs keyed to the product details context
      productIdsMap - Set of product IDs keyed to the product details context
      contextInfo - Context information surrounding sandboxing/multitenant state
    • addItemChoiceRelatedProducts

      protected void addItemChoiceRelatedProducts(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<String>> productIdsMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Queries for the item choice products and adds them to the productDetailsContext's related products.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      productIdsMap - Set of product IDs keyed to the product details context
      contextInfo - Context information surrounding sandboxing/multitenant state
    • addItemChoiceCategoryProducts

      protected void addItemChoiceCategoryProducts(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String,Set<String>> categoryIdMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Queries for the item choice categories and category products, and adds them to the productDetailsContext's specific category choices and related products.
      Parameters:
      productDetailsContexts - The contexts to which to contribute
      categoryIdMap - Set of category IDs keyed to the product details context
      contextInfo - Context information surrounding sandboxing/multitenant state
    • getCategoryProductService

      protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getProductService

      protected ProductService<Product> getProductService()
    • getVariantService

      protected VariantService<Variant> getVariantService()
    • getCategoryService

      protected CategoryService<Category> getCategoryService()
    • getProperties

      protected CatalogServiceProperties getProperties()
    • getTypeFactory

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