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)
  • Field Details

    • FILTER_BY_SANDBOX

      protected static final String FILTER_BY_SANDBOX
      See Also:
    • FILTER_NOT_ARCHIVED

      protected static final String FILTER_NOT_ARCHIVED
      See Also:
    • FILTER_BY_SANDBOX_IS_NULL

      protected static final String 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: ProductConsolidationContributor
      Consolidate products with their related domain and translations. This includes both hydrating Product fields and combining external references like CategoryProduct. Any catalog or sandbox overrides made to external references for non-overridden products will generate new placeholder products to store those overrides.
      Specified by:
      consolidateProducts in interface ProductConsolidationContributor
      Parameters:
      productIds - the IDs of the products to consolidate
      products - the product in all explicit context states
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - 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 the IncludedProducts and ItemChoices of the Consolidated Products. The productsToHydrate should be Merchandising Products or Bundle Products.
      Type Parameters:
      T - The type of ConsolidatedProduct
      Parameters:
      productsToHydrate - The Consolidated Products to hydrate
      contextInfo - Additional sandbox and multitenant context information
    • hydrateRequiredOptionInfo

      protected <T extends ConsolidatedProduct> void hydrateRequiredOptionInfo(@NonNull @NonNull Collection<T> productsToHydrate)
      Hydrates the ConsolidatedProductRequiredOptionInfos for the Consolidated Products. The productsToHydrate should be Merchandising Products.
      Type Parameters:
      T - The type of ConsolidatedProduct
      Parameters:
      productsToHydrate - The Consolidated Products to hydrate
    • getAllVariants

      protected <T extends ConsolidatedProduct> Set<Variant> getAllVariants(@NonNull @NonNull Collection<T> productsToHydrate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Returns the Variants to be hydrated onto the ItemChoices of the Consolidated Products. The productsToHydrate should be Merchandising Products or Bundle Products.
      Type Parameters:
      T - The type of ConsolidatedProduct
      Parameters:
      productsToHydrate - The Consolidated Products to hydrate
      contextInfo - Additional sandbox and multitenant context information
      Returns:
      The Variants to 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 the Products to be hydrated onto the ItemChoices and IncludedProducts of the Consolidated Products. The productsToHydrate should be Merchandising Products or Bundle 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 of ConsolidatedProduct
      Parameters:
      productsToHydrate - The Consolidated Products to hydrate
      variantParentIds - IDs of additional Products to read that are the parents of Variants that are also being hydrated. These are needed because variants inherit some information from their products.
      contextInfo - Additional sandbox and multitenant context information
      Returns:
      The Products to be used for hydration.
    • hydrateBundleIncludedProducts

      protected <P extends Product, V extends Variant, C extends RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey> void hydrateBundleIncludedProducts(@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 given ContextState. This is used to help generate the contextCompositeKey(ContextState).
      Parameters:
      context - The ContextState to get the catalog id for
      Returns:
      The most specific catalog id for the given ContextState
    • hydrateMerchandisingProductOptions

      protected <P extends Product, V extends Variant, C extends RequiredOptionInfoProductConsolidationContributor.ContextCompositeKey> void hydrateMerchandisingProductOptions(@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 a ContextState for comparing Consolidated Products and potentially related Products and Variants.
      Parameters:
      context - The ContextState to 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 a ContextState for comparing Consolidated Products and potentially related Products and Variants. This version will always use the production-level values.
      Parameters:
      context - The ContextState to create the key for
      Returns:
      The key that represents the key properties of the ContextState
    • hydrateParentProductInfoOnVariant

      protected void hydrateParentProductInfoOnVariant(@NonNull @NonNull Variant variant, @NonNull @NonNull Product parent)
    • 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 of ConsolidatedProductRequiredOptionInfos for the given ConsolidatedProduct. By default, this only applies to merchandising products where the price of the product is determined by the item choices.
      Parameters:
      product - the ConsolidatedProduct to 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)
      Parameters:
      itemChoice - the ItemChoice to build the info from
      Returns:
      the ConsolidatedProductRequiredOptionInfo built from the ItemChoice
      Since:
      Catalog Service 2.1.5, Release Train 2.1.5
    • isSpecificProductAvailable

      protected boolean isSpecificProductAvailable(@NonNull @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. 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

      protected ProductService<Product> getProductService()
    • getVariantService

      protected VariantService<Variant> getVariantService()
    • getRsqlFilterParser

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

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