Class RequiredOptionInfoProductConsolidationContributor
java.lang.Object
com.broadleafcommerce.catalog.service.product.consolidation.RequiredOptionInfoProductConsolidationContributor
- All Implemented Interfaces:
ProductConsolidationContributor
public class RequiredOptionInfoProductConsolidationContributor
extends Object
implements ProductConsolidationContributor
Performs logic to handle
ProductOptions with required ItemChoices. In particular this checks if all the required item choices are available for
purchase, whether all bundle items are available, and hydrates
ConsolidatedProductRequiredOptionInfo for Merchandising Products.
The logic in this consolidator is such that it will make the fewest number of queries possible to
read all the related products and variants the must be hydrated. It reads all of the relations by
their IDs that are production-level or within a sandbox that matches one of the
Consolidated Products being consolidated. It does not currently
generate new overrides but only hydrates the existing ones.
Supersedes ItemChoiceAvailabilityConsolidationContributor.
- Since:
- Catalog Service 2.1.5, Release Train 2.1.5
- Author:
- Nathan Moore (nathandmoore)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRequiredOptionInfoProductConsolidationContributor(ProductService<Product> productService, VariantService<Variant> variantService, com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser rsqlFilterParser, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected ConsolidatedProductRequiredOptionInfobuildRequiredOptionInfo(@NonNull ItemChoice itemChoice) Builds aConsolidatedProductRequiredOptionInfofrom theItemChoice.protected List<ConsolidatedProductRequiredOptionInfo>buildRequiredOptionsInfos(@NonNull ConsolidatedProduct product) Builds the list ofConsolidatedProductRequiredOptionInfosfor the givenConsolidatedProduct.protected <T extends ConsolidatedProduct>
voidcheckBundleProductsAvailable(@NonNull Collection<T> products) voidconsolidateProducts(@NonNull Set<String> productIds, @NonNull List<ConsolidatedProduct> products, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Consolidate products with their related domain and translations.contextCompositeKey(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) Creates a key that represents the key properties of aContextStatefor comparingConsolidated Productsand potentially relatedProductsandVariants.contextProductionCompositeKey(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) Creates a key that represents the key properties of aContextStatefor comparingConsolidated Productsand potentially relatedProductsandVariants.protected voiddetermineItemsInBundleAvailable(@NonNull ConsolidatedProduct consolidatedProduct) protected <T extends ConsolidatedProduct>
voiddetermineRequiredItemChoicesAvailable(@NonNull Collection<T> productsWithRequiredItemChoices) protected <T extends ConsolidatedProduct>
Set<Product>getAllProducts(@NonNull Collection<T> productsToHydrate, @NonNull Collection<String> variantParentIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theProductsto be hydrated onto theItemChoicesandIncludedProductsof theConsolidated Products.protected <T extends ConsolidatedProduct>
Set<Variant>getAllVariants(@NonNull Collection<T> productsToHydrate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected StringgetMostSpecificCatalogId(@NonNull com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) Returns the most specific catalog id for the givenContextState.protected cz.jirutka.rsql.parser.ast.NodegetNotArchivedAndSandboxFilters(@NonNull Collection<String> sandboxContextIds) Creates the filters for the not archived entities and with the specified sandboxes.protected cz.jirutka.rsql.parser.ast.NodeCreates the filters for the not archived entities.protected ProductService<Product>protected <T extends ConsolidatedProduct>
List<T>getProductsWithRequiredItems(@NonNull Collection<T> products) protected com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParserprotected cz.jirutka.rsql.parser.ast.NodeCreates the filters for the entities with null sandbox.protected com.broadleafcommerce.common.extension.TypeFactoryprotected VariantService<Variant>protected <T extends ConsolidatedProduct>
voidhydrateBundleAndMerchandisingProductOptions(@NonNull Collection<T> productsToHydrate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected <P extends Product,V extends Variant, C extends RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey>
voidhydrateBundleIncludedProducts(@NonNull ConsolidatedProduct cp, @NonNull Map<C, Map<String, V>> variantsByIdByContext, @NonNull Map<C, Map<String, P>> productsByIdByContext) protected <P extends Product,V extends Variant, C extends RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey>
voidhydrateMerchandisingProductOptions(@NonNull ConsolidatedProduct cp, @NonNull Map<C, Map<String, V>> variantsByIdByContext, @NonNull Map<C, Map<String, P>> productsByIdByContext) protected voidhydrateParentProductInfoOnVariant(@NonNull Variant variant, @NonNull Product parent) protected <T extends ConsolidatedProduct>
voidhydrateRequiredOptionInfo(@NonNull Collection<T> productsToHydrate) Hydrates theConsolidatedProductRequiredOptionInfosfor theConsolidated Products.protected booleanisSpecificProductAvailable(@NonNull ProductOption productOption) If 1 product is available in a bundle, even if that bundle has a minimum quantity of greater than 1, we assume it is available.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.catalog.service.product.consolidation.ProductConsolidationContributor
shouldConsolidate
-
Field Details
-
FILTER_BY_SANDBOX
- See Also:
-
FILTER_NOT_ARCHIVED
- See Also:
-
FILTER_BY_SANDBOX_IS_NULL
- See Also:
-
typeFactory
protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory
-
-
Constructor Details
-
RequiredOptionInfoProductConsolidationContributor
public RequiredOptionInfoProductConsolidationContributor(ProductService<Product> productService, VariantService<Variant> variantService, com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser rsqlFilterParser, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
consolidateProducts
public void consolidateProducts(@NonNull @NonNull Set<String> productIds, @NonNull @NonNull List<ConsolidatedProduct> products, @Nullable com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:ProductConsolidationContributorConsolidate products with their related domain and translations. This includes both hydratingProductfields and combining external references likeCategoryProduct. Any catalog or sandbox overrides made to external references for non-overridden products will generate new placeholder products to store those overrides.- Specified by:
consolidateProductsin interfaceProductConsolidationContributor- Parameters:
productIds- the IDs of the products to consolidateproducts- the product in all explicit context statesinheritanceLines- the catalog inheritance lines top-down from all of the productscontext- context information surrounding sandboxing/multitenant state
-
hydrateBundleAndMerchandisingProductOptions
protected <T extends ConsolidatedProduct> void hydrateBundleAndMerchandisingProductOptions(@NonNull @NonNull Collection<T> productsToHydrate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates theIncludedProductsandItemChoicesof theConsolidated Products. TheproductsToHydrateshould beMerchandising ProductsorBundle Products.- Type Parameters:
T- The type ofConsolidatedProduct- Parameters:
productsToHydrate- TheConsolidated Productsto hydratecontextInfo- Additional sandbox and multitenant context information
-
hydrateRequiredOptionInfo
protected <T extends ConsolidatedProduct> void hydrateRequiredOptionInfo(@NonNull @NonNull Collection<T> productsToHydrate) Hydrates theConsolidatedProductRequiredOptionInfosfor theConsolidated Products. TheproductsToHydrateshould beMerchandising Products.- Type Parameters:
T- The type ofConsolidatedProduct- Parameters:
productsToHydrate- TheConsolidated Productsto hydrate
-
getAllVariants
protected <T extends ConsolidatedProduct> Set<Variant> getAllVariants(@NonNull @NonNull Collection<T> productsToHydrate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theVariantsto be hydrated onto theItemChoicesof theConsolidated Products. TheproductsToHydrateshould beMerchandising ProductsorBundle Products.- Type Parameters:
T- The type ofConsolidatedProduct- Parameters:
productsToHydrate- TheConsolidated Productsto hydratecontextInfo- Additional sandbox and multitenant context information- Returns:
- The
Variantsto be used for hydration.
-
getAllProducts
protected <T extends ConsolidatedProduct> Set<Product> getAllProducts(@NonNull @NonNull Collection<T> productsToHydrate, @NonNull @NonNull Collection<String> variantParentIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theProductsto be hydrated onto theItemChoicesandIncludedProductsof theConsolidated Products. TheproductsToHydrateshould beMerchandising ProductsorBundle Products.This should be called after the variants are hydrated onto the same targets since Variants reference products as well.
- Type Parameters:
T- The type ofConsolidatedProduct- Parameters:
productsToHydrate- TheConsolidated Productsto hydratevariantParentIds- IDs of additionalProductsto read that are the parents ofVariantsthat are also being hydrated. These are needed because variants inherit some information from their products.contextInfo- Additional sandbox and multitenant context information- Returns:
- The
Productsto be used for hydration.
-
hydrateBundleIncludedProducts
protected <P extends Product,V extends Variant, void hydrateBundleIncludedProductsC extends RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey> (@NonNull @NonNull ConsolidatedProduct cp, @NonNull @NonNull Map<C, Map<String, V>> variantsByIdByContext, @NonNull @NonNull Map<C, Map<String, P>> productsByIdByContext) -
getMostSpecificCatalogId
protected String getMostSpecificCatalogId(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) Returns the most specific catalog id for the givenContextState. This is used to help generate thecontextCompositeKey(ContextState).- Parameters:
context- TheContextStateto get the catalog id for- Returns:
- The most specific catalog id for the given
ContextState
-
hydrateMerchandisingProductOptions
protected <P extends Product,V extends Variant, void hydrateMerchandisingProductOptionsC extends RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey> (@NonNull @NonNull ConsolidatedProduct cp, @NonNull @NonNull Map<C, Map<String, V>> variantsByIdByContext, @NonNull @NonNull Map<C, Map<String, P>> productsByIdByContext) -
contextCompositeKey
protected RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey contextCompositeKey(@Nullable com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) Creates a key that represents the key properties of aContextStatefor comparingConsolidated Productsand potentially relatedProductsandVariants.- Parameters:
context- TheContextStateto create the key for- Returns:
- The key that represents the key properties of the
ContextState
-
contextProductionCompositeKey
protected RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey contextProductionCompositeKey(@Nullable com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) Creates a key that represents the key properties of aContextStatefor comparingConsolidated Productsand potentially relatedProductsandVariants. This version will always use the production-level values.- Parameters:
context- TheContextStateto create the key for- Returns:
- The key that represents the key properties of the
ContextState
-
hydrateParentProductInfoOnVariant
-
checkBundleProductsAvailable
protected <T extends ConsolidatedProduct> void checkBundleProductsAvailable(@NonNull @NonNull Collection<T> products) -
determineItemsInBundleAvailable
protected void determineItemsInBundleAvailable(@NonNull @NonNull ConsolidatedProduct consolidatedProduct) -
getProductsWithRequiredItems
protected <T extends ConsolidatedProduct> List<T> getProductsWithRequiredItems(@NonNull @NonNull Collection<T> products) -
determineRequiredItemChoicesAvailable
protected <T extends ConsolidatedProduct> void determineRequiredItemChoicesAvailable(@NonNull @NonNull Collection<T> productsWithRequiredItemChoices) -
buildRequiredOptionsInfos
protected List<ConsolidatedProductRequiredOptionInfo> buildRequiredOptionsInfos(@NonNull @NonNull ConsolidatedProduct product) Builds the list ofConsolidatedProductRequiredOptionInfosfor the givenConsolidatedProduct. By default, this only applies tomerchandising productswhere the price of the product is determined by the item choices.- Parameters:
product- theConsolidatedProductto build the infos for- Returns:
- the list of
ConsolidatedProductRequiredOptionInfos. - Since:
- Catalog Service 2.1.5, Release Train 2.1.5
-
buildRequiredOptionInfo
protected ConsolidatedProductRequiredOptionInfo buildRequiredOptionInfo(@NonNull @NonNull ItemChoice itemChoice) Builds aConsolidatedProductRequiredOptionInfofrom theItemChoice.- Parameters:
itemChoice- theItemChoiceto build the info from- Returns:
- the
ConsolidatedProductRequiredOptionInfobuilt from theItemChoice - Since:
- Catalog Service 2.1.5, Release Train 2.1.5
-
isSpecificProductAvailable
If 1 product is available in a bundle, even if that bundle has a minimum quantity of greater than 1, we assume it is available. That's because, even if there's a minimum quantity of 2 and only 1 product is available, we can say that the customer could purchase 2 of the 1 available product.- Parameters:
productOption-- Returns:
- true if at least one specific item choice is available, else false.
-
getNotArchivedAndSandboxFilters
protected cz.jirutka.rsql.parser.ast.Node getNotArchivedAndSandboxFilters(@NonNull @NonNull Collection<String> sandboxContextIds) Creates the filters for the not archived entities and with the specified sandboxes.- Parameters:
sandboxContextIds- the context ids of the sandboxes to filter by- Returns:
- filters for the not archived entities and with the specified sandboxes.
-
getNotArchivedFilter
protected cz.jirutka.rsql.parser.ast.Node getNotArchivedFilter()Creates the filters for the not archived entities.- Returns:
- filters for the not archived entities
-
getSandboxIsNullFilter
protected cz.jirutka.rsql.parser.ast.Node getSandboxIsNullFilter()Creates the filters for the entities with null sandbox.- Returns:
- the filters for the entities with null sandbox
-
getProductService
-
getVariantService
-
getRsqlFilterParser
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.rsql.RSQLFilterParser getRsqlFilterParser() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-