Page 1 of 1

how to get the number of total products found on product search results?

Posted: Tue Sep 25, 2018 4:34 am
by chongshengdz
how to get the number of total products found on product search results?
for example: Showing 1 to 15 of 22 (2 Pages)
get the number 22

Re: how to get the number of total products found on product search results?

Posted: Tue Sep 25, 2018 5:28 am
by straightlight
In OC v3.1.0.0, the system/library/pagination.php file will be abolished as it will be handled by a controller file instead. However, here's a tweak since the new version is still alpha:

Find:

Code: Select all

public $total = 0;
add below:

Code: Select all

public $end = 0;
Then, find:

Code: Select all

for ($i = $start; $i <= $end; $i++) {
add above:

Code: Select all

if (isset($end)) {
				$this->end = $end;
			}
Then, from your controller, you could use:

Code: Select all

$data['pagination_end'] = $pagination->end;
Finally, in your TWIG file, you could use:

Code: Select all

{% if pagination_end %}
{{ pagination_end }}
{% endif %}
This should resolved the issue.

Re: how to get the number of total products found on product search results?

Posted: Wed Sep 26, 2018 1:45 am
by chongshengdz
thanks for your reply.
but it only shows the number of total pages.
i need to get the number of total products.
can you help again?

Re: how to get the number of total products found on product search results?

Posted: Wed Sep 26, 2018 1:56 am
by chongshengdz
i change from

Code: Select all

$data['pagination_end'] = $pagination->end;
to

Code: Select all

$data['pagination_end'] = $pagination->total;
and it works perfect, many thanks for your help @straightlight

and there is no need to change php code in system/library/pagination.php
in template, just add {{ pagination_end }} anywhere if you like.