Skip to main content
Version: 1.0.0

ProductCountQuery

Description

Returns the number of products matching the specified criteria. This query is useful for pagination or when you need to know the total count of products without fetching the actual product data.

Endpoint

query productCount($handle: [QueryArgument], $yuiId: [QueryArgument], $price: [QueryArgument], $type: [String]) {
productCount(handle: $handle, yuiId: $yuiId, price: $price, type: $type)
}

Arguments

ArgumentTypeRequiredDescription
handle[QueryArgument]NoNarrows the query results based on the handle on the product.
yuiId[QueryArgument]NoNarrows the query results based on the YUI ID on the product.
price[QueryArgument]NoNarrows the query results based on the price on the product.
price_incl_tax[QueryArgument]NoNarrows the query results based on the price including tax on the product.
price_excl_tax[QueryArgument]NoNarrows the query results based on the price excluding tax on the product.
specialPrice[QueryArgument]NoNarrows the query results based on the special price on the product.
special_price_incl_tax[QueryArgument]NoNarrows the query results based on the special price including tax on the product.
special_price_excl_tax[QueryArgument]NoNarrows the query results based on the special price excluding tax on the product.
type[String]NoNarrows the query results based on the product type the products belong to per the product type's handles.

Common Element Arguments

In addition to the specific arguments above, this query also supports common element arguments:

ArgumentTypeRequiredDescription
id[QueryArgument]NoNarrows the query results based on the element's ID.
uid[String]NoNarrows the query results based on the element's UID.
status[String]NoNarrows the query results based on the element's status.
title[String]NoNarrows the query results based on the element's title.
slug[String]NoNarrows the query results based on the element's slug.
siteIdIntNoDetermines which site to fetch results from.

Return Values

The query returns an integer representing the total number of products that match the specified criteria.

Usage Example

query {
productCount(type: ["simple"], price: [">", 10])
}

Example Response

{
"data": {
"productCount": 42
}
}

Notes

  • The QueryArgument type allows for various comparison operators. For example, you can use price: [">", 10] to count products with a price greater than 10.
  • You can combine multiple arguments to narrow down the count further.
  • This query is particularly useful for implementing pagination in your frontend application.
  • Unlike the products query, this query does not support the limit and offset arguments, as it always returns the total count.
  • This query uses the same filtering arguments as the products query, so you can use the same filters to get a count of products that would be returned by a corresponding products query.