How to get total products for pagination

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kdim95
Advanced
Posts: 191
Joined: 26 Aug 2022, 12:17

How to get total products for pagination

Post by kdim95 » 29 Mar 2023, 14:21

Laravel framework version: 9.52.4
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux

Hello,

What is the proper way to get the total count of products for the catalog listing?

I need the total product count for pagination.

$cntl->search( $total ) inside Aimeos\Client\Html\Catalog\Lists sets the $total to a maximum of 10,000.

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: How to get total products for pagination

Post by aimeos » 30 Mar 2023, 08:00

This is done for good reasons because counting records in a database is an expensive task if they exceed 10k rows. Therefore, Aimeos (and e.g. ElasticSearch too) limits the maximum number of counted records to 10k. That's no problem because no user will usually visit more than the first 3-10 pages and use the filter instead to limit the products to the ones he is looking for.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 191
Joined: 26 Aug 2022, 12:17

Re: How to get total products for pagination

Post by kdim95 » 30 Mar 2023, 10:38

For the ElasticSearch index, does this code get the total number of products in every category?

$aggregate = $cntl->aggregate('index.catalog.id');

inside Aimeos\Client\Html\Catalog\Lists::data()

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: How to get total products for pagination

Post by aimeos » 31 Mar 2023, 07:05

Yes, that should be the case, up to 10k documents. If you have more, the numbers for some categories will be less than the real number or even zero.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply