Class AbstractProductsRetriever

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected List<String> identifiers
      Identifier of the product that should be fetched.
      protected Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook
      Lambda that extends the product query.
      protected List<com.adobe.cq.commerce.magento.graphql.ProductInterface> products
      List of product instances.
      protected Consumer<com.adobe.cq.commerce.magento.graphql.SimpleProductQuery> variantQueryHook
      Lambda that extends the product variant query.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.adobe.cq.commerce.graphql.client.GraphqlResponse<com.adobe.cq.commerce.magento.graphql.Query,​com.adobe.cq.commerce.magento.graphql.gson.Error> executeQuery()
      Execute the GraphQL query with the GraphQL client.
      void extendProductQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook)
      Extend the product GraphQL query with a partial query provided by a lambda hook that sets additional fields.
      void extendVariantQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.SimpleProductQuery> variantQueryHook)
      Extend the product variant GraphQL query with a partial query provided by a lambda hook that sets additional fields.
      List<com.adobe.cq.commerce.magento.graphql.ProductInterface> fetchProducts()
      Executes the GraphQL query and returns a product.
      protected com.adobe.cq.commerce.magento.graphql.ProductPriceQueryDefinition generatePriceQuery()  
      protected abstract com.adobe.cq.commerce.magento.graphql.ProductInterfaceQueryDefinition generateProductQuery()
      Generates the partial ProductInterface query part of the GraphQL product query.
      protected String generateQuery​(List<String> identifiers)
      Generate a complete product GraphQL query with a filter for the given product identifiers.
      protected void populate()
      Executes the query and parses the response.
      void setIdentifiers​(List<String> identifiers)
      Set the identifiers of the products that should be fetched.
    • Field Detail

      • productQueryHook

        protected Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook
        Lambda that extends the product query.
      • variantQueryHook

        protected Consumer<com.adobe.cq.commerce.magento.graphql.SimpleProductQuery> variantQueryHook
        Lambda that extends the product variant query.
      • products

        protected List<com.adobe.cq.commerce.magento.graphql.ProductInterface> products
        List of product instances. Is only available after populate() was called.
      • identifiers

        protected List<String> identifiers
        Identifier of the product that should be fetched. Which kind of identifier is used (usually slug or SKU) is implementation specific and should be checked in subclass implementations.
    • Constructor Detail

    • Method Detail

      • fetchProducts

        public List<com.adobe.cq.commerce.magento.graphql.ProductInterface> fetchProducts()
        Executes the GraphQL query and returns a product. For subsequent calls of this method, a cached product is returned.
        Returns:
        Product
      • setIdentifiers

        public void setIdentifiers​(List<String> identifiers)
        Set the identifiers of the products that should be fetched. Which kind of identifier is used (usually slug or SKU) is implementation specific and should be checked in subclass implementations. Setting the identifier, removes any cached data.
        Parameters:
        identifiers - Product identifier
      • extendProductQueryWith

        public void extendProductQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook)
        Extend the product GraphQL query with a partial query provided by a lambda hook that sets additional fields. Example:
         
         productRetriever.extendProductQueryWith(p -> p
             .createdAt()
             .addCustomSimpleField("is_returnable"));
         
         
        Parameters:
        productQueryHook - Lambda that extends the product query
      • extendVariantQueryWith

        public void extendVariantQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.SimpleProductQuery> variantQueryHook)
        Extend the product variant GraphQL query with a partial query provided by a lambda hook that sets additional fields. Example:
         
         productRetriever.extendVariantQueryWith(s -> s
             .createdAt()
             .addCustomSimpleField("is_returnable"));
         
         
        Parameters:
        variantQueryHook - Lambda that extends the product variant query
      • generateQuery

        protected String generateQuery​(List<String> identifiers)
        Generate a complete product GraphQL query with a filter for the given product identifiers.
        Parameters:
        identifiers - Product identifiers, usually SKU or slug
        Returns:
        GraphQL query as string
      • executeQuery

        protected com.adobe.cq.commerce.graphql.client.GraphqlResponse<com.adobe.cq.commerce.magento.graphql.Query,​com.adobe.cq.commerce.magento.graphql.gson.Error> executeQuery()
        Execute the GraphQL query with the GraphQL client.
        Specified by:
        executeQuery in class AbstractRetriever
        Returns:
        GraphqlResponse object
      • generatePriceQuery

        protected com.adobe.cq.commerce.magento.graphql.ProductPriceQueryDefinition generatePriceQuery()
      • generateProductQuery

        protected abstract com.adobe.cq.commerce.magento.graphql.ProductInterfaceQueryDefinition generateProductQuery()
        Generates the partial ProductInterface query part of the GraphQL product query.
        Returns:
        ProductInterface query definition