Class AbstractProductRetriever
- java.lang.Object
-
- com.adobe.cq.commerce.core.components.models.retriever.AbstractRetriever
-
- com.adobe.cq.commerce.core.components.models.retriever.AbstractProductRetriever
-
public abstract class AbstractProductRetriever extends AbstractRetriever
Abstract implementation of product retriever that loads product data using GraphQL.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
identifier
Identifier of the product that should be fetched.protected String
mediaBaseUrl
Deprecated.protected com.adobe.cq.commerce.magento.graphql.ProductInterface
product
Product instance.protected UrlProvider.ProductIdentifierType
productIdentifierType
The type of the product identifier.protected Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery>
productQueryHook
Lambda that extends the product query.protected Consumer<com.adobe.cq.commerce.magento.graphql.SimpleProductQuery>
variantQueryHook
Lambda that extends the product variant query.-
Fields inherited from class com.adobe.cq.commerce.core.components.models.retriever.AbstractRetriever
client, query
-
-
Constructor Summary
Constructors Constructor Description AbstractProductRetriever(MagentoGraphqlClient client)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated 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.String
fetchMediaBaseUrl()
Deprecated.com.adobe.cq.commerce.magento.graphql.ProductInterface
fetchProduct()
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(String identifier)
Generate a complete product GraphQL query with a filter for the given product identifier.protected void
populate()
Executes the query and parses the response.void
setIdentifier(UrlProvider.ProductIdentifierType productIdentifierType, String identifier)
Set the identifier and the identifier type of the product that should be fetched.void
setIdentifier(String identifier)
Deprecated.UsesetIdentifier(ProductIdentifierType, String)
instead.-
Methods inherited from class com.adobe.cq.commerce.core.components.models.retriever.AbstractRetriever
setQuery
-
-
-
-
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 inproductIdentifierType
-
productIdentifierType
protected UrlProvider.ProductIdentifierType productIdentifierType
The type of the product identifier.
-
-
Constructor Detail
-
AbstractProductRetriever
public AbstractProductRetriever(MagentoGraphqlClient client)
-
-
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)
Deprecated.UsesetIdentifier(ProductIdentifierType, String)
instead.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 classAbstractRetriever
- Returns:
- GraphqlResponse object
-
generatePriceQuery
protected com.adobe.cq.commerce.magento.graphql.ProductPriceQueryDefinition generatePriceQuery()
-
populate
protected void populate()
Description copied from class:AbstractRetriever
Executes the query and parses the response.- Specified by:
populate
in classAbstractRetriever
-
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
-
-