Jump to content

[Solved] Search by ref and return exact product


dusty_much
 Share

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 1.4.7.3

 

Thank you everyone for your help! :)

Edited by dusty_much (see edit history)

Share this post


Link to post
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()

 

Fabio

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

  • 1 month later...

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More