I’ve been browesing several topics in this forum but I haven’t found any answer.
We are doing a React webapp which uses the Storefront API with GraphQL. On collection page we would like to list 10 products and display a pagination index, eg: “1, 2, 3 … last”
Unfortunately I havent found any way to get the total number of products per collection.
It’d be great to have a totalCount like this http://graphql.org/learn/pagination/#complete-connection-model but it isn’t implemented. How can I achieve the same thing?
4 Likes
Hafros
March 28, 2018, 8:39pm
2
There is no totalCount parameter in the SDK. Just use hasNextPage
That’s what we’re doing temprarely. Having a totalCount would be great, otherwise you have to do convoluted workaround to get that information.
Hafros
March 28, 2018, 10:01pm
4
I do not know what your visual solutions are for pagination. Show please, can we find a solution
That’s the one.
If there are more than 6 pages it becomes 1 2 3 … 7 8 9.
Without totalCount I can only use the NEXT button
I’m thinking of using Shopify Admin API to retrieve the total number with this https://help.shopify.com/api/reference/product#count
babyt
July 18, 2023, 11:27am
7
I know this is an old post, but you can use the filters to sum up the available + unavailable products to get the total count for the collection
query {
// collection query
products(
filters {
values {
id
label
count
}
}
)
}
4 Likes
Well thought. Thank you, you saved me!
1 Like