JaviMetal
JaviMetal

Reputation: 85

Prestashop - Retrieve searched products results to custom module

I need to retrieve the ($search['result']) from SearchController.php in my module when user has performed a prestashop search result.

My code is the next

public function hookActionSearch($params)
{
   $my_var = $this->context->smarty; //1st test
   $my_var = $this->context->controller; //2nd test
   $my_var = $params; //3rd test
   $var_dump($my_var); //in the three cases Couldn't see on the dump the $search var or $search_result in the smarty case
}

How can I retrieve this results in a var?

Upvotes: 1

Views: 536

Answers (1)

PrestaShopDeveloper
PrestaShopDeveloper

Reputation: 3118

There are only 2 parameters passed to that hook implementation:

  1. $params['query'] - which is the string customer search for
  2. $params['total'] - which is the total number of results

The search results are not being passed, so you can't get them that way.

To get them you will need to override the SearchController::initContent() and to add another hook, on which you must pass the result and implement in in your module.

Upvotes: 1

Related Questions