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 Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionItemChoiceHierarchyProductContextContributor
(CategoryProductService<CategoryProduct> categoryProductService, ProductService<Product> productService, VariantService<Variant> variantService, CategoryService<Category> categoryService, CatalogServiceProperties properties, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addItemChoiceCategoryProducts
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<String>> categoryIdMap, 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.protected void
addItemChoiceRelatedOptionTemplates
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<String>> optionTemplateIdMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for the item choice optionTemplates and adds them to the productDetailsContext's related optionTemplates.protected void
addItemChoiceRelatedProducts
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<String>> productIdsMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for the item choice products and adds them to the productDetailsContext's related products.protected void
addItemChoiceRelatedVariants
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<String>> variantIdsProductMap, Map<String, Set<String>> productIdsMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for the item choice variants and adds them to the productDetailsContext's related variants.buildCategoryIdMap
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> productMap, boolean firstIteration) Builds a mapping of item choice category IDs for the associated productDetailsContext.buildOptionTemplateIdMap
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> productMap, boolean firstIteration) Builds a mapping of option template IDs for the associated productDetailsContext.protected Set<ProductDetails>
buildProductDetailsMap
(ProductDetailsContext productDetailsContext, Product product) Filters through the category and product options to collect the next set ofProductDetails
.buildProductIdMap
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> productMap, boolean firstIteration) Builds a mapping of item choice product IDs for the associated productDetailsContext.buildVariantIdMap
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> productMap, boolean firstIteration) Builds a mapping of item choice variant IDs for the associated productDetailsContext.<T extends ProductDetailsContext>
Collection<T>contribute
(Collection<T> productDetailsContexts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Contributes to the suppliedProductDetailsContext
.filterCategoryIdsToQuery
(ProductDetailsContext productDetailsContext, Product product) Filters the category IDs to the ones not currently in the specific category choices.filterCategoryProductIdsToQuery
(Collection<? extends ProductDetailsContext> productDetailsContexts, Collection<? extends CategoryProduct> categoryProducts) Filters the category product IDs to the ones not currently in the related products.filterOptionTemplateIdsToQuery
(ProductDetailsContext productDetailsContext, Product product) Filters the option template IDs to the ones not currently in the related option templates.filterProductIdsToQuery
(ProductDetailsContext productDetailsContext, Product product) Filters the product IDs to the ones not currently in the related products.filterVariantIdsToQuery
(ProductDetailsContext productDetailsContext, Product product) Filters the variant IDs to the ones not currently in the related products.protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
protected OptionTemplateService<OptionTemplate>
int
getOrder()
protected ProductService<Product>
protected CatalogServiceProperties
protected com.broadleafcommerce.common.extension.TypeFactory
protected VariantService<Variant>
protected Collection<? extends ProductDetailsContext>
populateProductItemChoices
(Collection<? extends ProductDetailsContext> productDetailsContexts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Loops through the productDetailsContexts to populate product options item choices up to the maximum depth.protected Map<String,
Set<ProductDetails>> populateProductItemChoices
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> productDetailsMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Responsible for population of item choice categories, products, and variants of depths greater than one.protected Map<String,
Set<ProductDetails>> retrieveNextLevelProducts
(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> previosProductDetailMap, boolean firstIteration) Retrieves the map ofProductDetails
to recursively build out the item choice hierarchy structure.void
setOptionTemplateService
(OptionTemplateService<OptionTemplate> optionTemplateService)
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDER- See Also:
-
-
Constructor Details
-
ItemChoiceHierarchyProductContextContributor
public ItemChoiceHierarchyProductContextContributor(CategoryProductService<CategoryProduct> categoryProductService, ProductService<Product> productService, VariantService<Variant> variantService, CategoryService<Category> categoryService, CatalogServiceProperties properties, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceorg.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 suppliedProductDetailsContext
. This should not mutate the inputted context, but return a new one with the new contributions.- Specified by:
contribute
in interfaceProductDetailsContextContributor
- Parameters:
productDetailsContexts
- The contexts to which to contributecontextInfo
- 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 contributecontextInfo
- 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 contributeproductDetailsMap
- The product details to fetch the item choices fromcontextInfo
- 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 ofProductDetails
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 ofProductDetails
.- Parameters:
productDetailsContext
- The context to which to contributeproduct
- The product to fetch the next level products from- Returns:
- The set of configurable products from this product's item choices.
-
getProductIdsFromOptionChoices
-
buildOptionTemplateIdMap
protected Map<String,Set<String>> buildOptionTemplateIdMap(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<ProductDetails>> productMap, boolean firstIteration) Builds a mapping of option template IDs for the associated productDetailsContext.- Parameters:
productDetailsContexts
- The contexts to which to contributeproductMap
- Set of products keyed to the product details contextfirstIteration
- Whether this is the first iteration- Returns:
- The set of item choice option template IDs mapped to the productDetailsContext.
-
filterOptionTemplateIdsToQuery
protected Set<String> filterOptionTemplateIdsToQuery(ProductDetailsContext productDetailsContext, Product product) Filters the option template IDs to the ones not currently in the related option templates.- Parameters:
productDetailsContext
- The context to which to contributeproduct
- The product to fetch the option template IDs from- Returns:
- The option template IDs for this productDetailsContext not found in the related option templates.
-
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 contributeproductMap
- Set of products keyed to the product details contextfirstIteration
- 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 contributeproduct
- 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 contributeproductMap
- Set of products keyed to the product details contextfirstIteration
- 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 contributeproduct
- 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 contributeproductMap
- Set of products keyed to the product details contextfirstIteration
- 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 contributeproduct
- 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 contributecategoryProducts
- 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.
-
addItemChoiceRelatedOptionTemplates
protected void addItemChoiceRelatedOptionTemplates(Collection<? extends ProductDetailsContext> productDetailsContexts, Map<String, Set<String>> optionTemplateIdMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for the item choice optionTemplates and adds them to the productDetailsContext's related optionTemplates.- Parameters:
productDetailsContexts
- The contexts to which to contributeoptionTemplateIdMap
- Map of a product id to the option templates it referencescontextInfo
- Context information surrounding sandboxing/multitenant state
-
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 contributevariantIdsProductMap
- Set of variant IDs keyed to the product details contextproductIdsMap
- Set of product IDs keyed to the product details contextcontextInfo
- 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 contributeproductIdsMap
- Set of product IDs keyed to the product details contextcontextInfo
- 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 contributecategoryIdMap
- Set of category IDs keyed to the product details contextcontextInfo
- Context information surrounding sandboxing/multitenant state
-
getOptionTemplateService
-
setOptionTemplateService
@Autowired public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) -
getCategoryProductService
-
getProductService
-
getVariantService
-
getCategoryService
-
getProperties
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-