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 Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionRelatedProductsProductContextContributor
(CategoryProductService<CategoryProduct> categoryProductService, ProductService<Product> productService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser rsqlFilterParser) -
Method Summary
Modifier and TypeMethodDescription<T extends ProductDetailsContext>
Collection<T>contribute
(Collection<T> productDetailsContexts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Contributes to the suppliedProductDetailsContext
.contributeOtherProductIds
(@NonNull Collection<? extends ProductDetailsContext> productDetailsContexts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point for contributing other product IDs to the set.protected <T extends ProductDetailsContext>
Collection<T>contributeProductsOfRuleBasedCategories
(@NonNull Collection<T> productDetailsContexts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles contributing the products related to related rule-basedcategories
separately from other related products.protected <T extends ProductDetailsContext>
Collection<T>contributeRelatedCategoryProducts
(@NonNull Collection<T> productDetailsContexts, @NonNull Map<String, Map<String, Set<String>>> categoryProductsMap) Contributes the related category products to theProductDetailsContext
.protected <T extends ProductDetailsContext>
Collection<T>contributeRelatedProducts
(@NonNull Collection<T> productDetailsContexts, @NonNull Set<String> productIds, @NonNull Map<String, Set<String>> relatedProductsMap, @NonNull Map<String, Map<String, Set<String>>> categoryProductsMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Fetches and contributes the related products to theProductDetailsContext
.protected CategoryProductService<CategoryProduct>
getCategoryToProductMapToContribute
(@NonNull Collection<? extends ProductDetailsContext> productDetailsContexts, @NonNull List<Product> resolvedProducts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Collects the IDs of all the products related to theresolved products
through related CategoryProducts.getIncludedProductIdsToContribute
(@NonNull List<Product> resolvedProducts) Gets the set of product IDs from relatedIncludedProducts
.int
getOrder()
protected ProductService<Product>
getRelatedPromotionalProductIdsToContribute
(@NonNull Collection<? extends ProductDetailsContext> productDetailsContexts) Creates a map of resolved Product IDs to a collection ofpromotional product's related product IDs
.protected com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser
getSpecificChoiceProductsIdsToContribute
(@NonNull List<Product> resolvedProducts) Gets the set of product IDs from relatedSpecificItemChoice
.protected com.broadleafcommerce.common.extension.TypeFactory
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDER- See Also:
-
-
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 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.
-
getRelatedPromotionalProductIdsToContribute
protected Map<String,Set<String>> getRelatedPromotionalProductIdsToContribute(@NonNull @NonNull Collection<? extends ProductDetailsContext> productDetailsContexts) Creates a map of resolved Product IDs to a collection ofpromotional 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 relatedIncludedProducts
.- Parameters:
resolvedProducts
- TheProducts
resolved for theProductDetailsRequests
.- 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 relatedSpecificItemChoice
.- Parameters:
resolvedProducts
- TheProducts
resolved for theProductDetailsRequests
.- Returns:
- the set of product IDs from related
SpecificItemChoice
.
-
getCategoryToProductMapToContribute
protected Map<String,Map<String, getCategoryToProductMapToContributeSet<String>>> (@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 theresolved 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 contributecontextInfo
- 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 contributecontextInfo
- 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 theProductDetailsContext
.- Parameters:
productDetailsContexts
- The contexts to which to contributeproductIds
- Ids of the Products to fetch and contributecontextInfo
- 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 theProductDetailsContext
.- Parameters:
productDetailsContexts
- The contexts to which to contributecategoryProductsMap
- 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-basedcategories
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 theProductDetailsContexts
in use- Parameters:
productDetailsContexts
- The contexts to which to contributecontextInfo
- Additional sandbox and tenancy info- Returns:
- A version of the supplied
ProductDetailsContext
with the new contributions.
-
getCategoryProductService
-
getProductService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getRsqlFilterParser
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser getRsqlFilterParser()
-