Jump to content

[Solved] Search by ref and return exact product


Recommended Posts

Hey guys,


I am trying change the product search box, so that when a customer searches using the unique product reference, ONLY that product will show up. At the moment, the product that is being searched for, plus other similar products show up.


For example, if a customer searches for NE 1001, 50 products show, with products that have similar references (eg SGI 1001 and NE 1002) also being shown. I want it to show ONLY the product with the reference that is being searched for. At the very least, I want the product with the correct reference being shown first.


I am running Prestashop version


Thank you everyone for your help! :)

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

Hi Dusty.

You need to create a system from scratch, as the basic search form will always look for keywords using LIKE.


Now, I suggest you create a new module. In the hooking function, wehen the 'submit_reference' name is passed, select from the database a product with the same identical reference. You might want to use Search::sanitize to be sure it's clean. Notice it wil absolutely need to be identical to your reference, to use '=' instead of LIKE.


If there is a match, use $Link->getProductLink('$id_product....) to get the link, and the header(Location:....) to redirect the user, or Tools::redirect()



Link to comment
Share on other sites

Hey Fabio,

Thanks so much for your reply. I actually found a way to do what i wanted. I edited the search.php class and before the results array was returned I added in some code to check each entry in the array, to see whether the reference was the one I was looking for. If such a reference was found, I only returned that array entry and nothing else. If not, the whole array was returned as usual.


I hope this helps anyone else who has this problem, I will make sure to mark this post as solved now.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 10 years later...

I have made that. Just edit the file classes/Search.php and change the line:

if (!$psFuzzySearch || $fuzzyLoop++ > $fuzzyMaxLoop || !($sql_param_search = static::findClosestWeightestWord($context, $word))) {


if (!$psFuzzySearch || $fuzzyLoop++ > $fuzzyMaxLoop) {

That's it! You will only find the product with the exact referente.

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...