Class AbstractProductRetriever


  • public abstract class AbstractProductRetriever
    extends AbstractRetriever
    Abstract implementation of product retriever that loads product data using GraphQL.
    • 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.
      • product

        protected com.adobe.cq.commerce.magento.graphql.ProductInterface product
        Product instance. Is only available after populate() was called.
      • mediaBaseUrl

        @Deprecated
        protected String mediaBaseUrl
        Deprecated.
        Media base url from the Magento store info. Is only available after populate() was called.
      • identifier

        protected String identifier
        Identifier of the product that should be fetched. Which kind of identifier is used is specified in productIdentifierType
    • Constructor Detail

    • Method Detail

      • fetchProduct

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

        @Deprecated
        public String fetchMediaBaseUrl()
        Deprecated.
        Executes the GraphQL query and returns the media base url from the store info. For subsequent calls of this method, a cached url is returned.
        Returns:
        Media base url
      • setIdentifier

        @Deprecated
        public void setIdentifier​(String identifier)
        Set the 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. Setting the identifier, removes any cached data.
        Parameters:
        identifier - Product identifier
      • setIdentifier

        public void setIdentifier​(UrlProvider.ProductIdentifierType productIdentifierType,
                                  String identifier)
        Set the identifier and the identifier type of the product that should be fetched. Setting the identifier, removes any cached data.
        Parameters:
        productIdentifierType - The product identifier type.
        identifier - The 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​(String identifier)
        Generate a complete product GraphQL query with a filter for the given product identifier.
        Parameters:
        identifier - Product identifier, 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