Jump to content

show the total number of products in the search page title


Bendris

Recommended Posts

Hello,

i use Prestashop 1.7.6.5

Please i want to display the total number of products find in a search result.. in the title of the search page.. i try to modify the file "themes/mytheme/templates/catalog/listing/product-list.tpl" and i use the variable {$listing.products|count} .. but this variable give me the number of products in this page.. i want the total number of products..

 

then i try to use the variable {$pagination.total_items} that exists in the pagination.tpl file .. but is dont work on product-list.tpl file..

 

how i can do that please!?

 

Thanks

Edited by Bendris (see edit history)
Link to comment
Share on other sites

  • 2 years later...

To display the total number of products found in a search result on the search page, you can modify the SearchController.php file of Prestashop. Here are the steps:

1. Make a backup of the SearchController.php file located in the controllers/front folder of your Prestashop installation.

2. Open the SearchController.php file and find the initContent() method.

3. Inside the initContent() method, you'll find the code that sets up the search result data. You can add the total number of products found in the search result to the $params array that's passed to the template.

4. To get the total number of products found in the search result, you can use the following code:

$totalProducts = Product::searchTotalByName($query);

Where $query is the search query entered by the user.

5. Add $totalProducts to the $params array, like this:

$params['total_products'] = $totalProducts;

6. Save the modified SearchController.php file.

7. Open the themes/mytheme/templates/catalog/search.tpl file and find the <h1> tag where you want to display the total number of products found.

8. Add the following code inside the <h1> tag:

{if isset($total_products) && $total_products > 0}
    ({$total_products})
{/if}

This code checks if the $total_products variable is set and greater than zero, and displays it in parentheses.

9. Save the modified search.tpl file.

After these steps, the total number of products found in the search result will be displayed in the specified <h1> tag on the search page.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...