Page 1 of 1

Search function fails to return results [SOLVED]

Posted: Thu Feb 08, 2018 12:31 am
by chris.dempsey
Environment
  • OC 2.3.0.2
  • VQmod 2.6.2
  • PHP 5.6.3.3
  • Default Template
I am convinced the Search function worked previously but it now returns no results when searching product names either for exact or partial match. This occurs whether the search term entered in the search bar on header or on search page. Same behaviour if search submitted by mouse click or enter button.

UPDATE: the site originally ran on OC 1.5 and, if I remember correctly, was updated to 2.3.0.2 using the regular install process.

Example searches are
  • Cutting Knife (exact product name)
  • Brush (partial product name)
Stuff I've tried to resolve
  • There are no search related extensions installed and I have uninstalled all other extensions and OCmod and VQmod modifications
  • I've tried all flavours of PHP available on the server from 5.4 through to 7.0
  • No errors are logged either by PHP. OCmod or VQmod
  • I can't find anything to help in Google and Forum searches or in GitHub issues
  • One thread I found suggested database user permissions. My user has the full set of Structure and Data access permissions
  • I cleared /system/storage/cache and /vqmod/cache manually after each adjustment to settings
  • Replaced all the core files with the originals from the install process in case any were accidentally changed
Can anyone suggest what might be causing the issue?

Staging site is available at http://oc2.allscotltd.co.uk

Thanks,

Chris

EDIT: post updated with site url and more development history

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 2:19 am
by simonpieman
Does the page switch to the results page. but empty?or does it not change?

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 2:33 am
by chris.dempsey
Posts to results page /index.php?route=product/search&search=Brush

Displays default no results message:

Products meeting the search criteria
There is no product that matches the search criteria.

Any ideas?

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 2:36 am
by chris.dempsey
Should also mention site is on staging server with password protection.

Could make public if it would help.

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 6:40 pm
by paulfeakins
This should serve as an example of how to request help on the forum, lots of info, great description and a list of what you've already tried!

And yes I think providing a link would help ...

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 6:53 pm
by chris.dempsey
Staging site is available at http://oc2.allscotltd.co.uk

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 7:03 pm
by chris.dempsey
Original post updated with a few more details.

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 7:06 pm
by paulfeakins
If you trace the execution path through the controller that's responsible for search, what do you find? Is it getting to the right function? Is it performing the query? Is any data being returned? Is that data being passed to the view?

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 7:19 pm
by chris.dempsey
Will attempt to do this, not sure of the process though. Usually I can work backwards from the error log but all I got right now is silence.

Side note, another thing I tried yesterday was replacing all the core files with the originals from the 2.3.0.2 install process in case any were accidentally changed. Obviously no joy.

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 7:26 pm
by paulfeakins
Ok so you can see from the URL:
index.php?route=product/search&search=colour

We're on the front-end so we're looking in /catalog/
Everything goes through a controller so we're looking in /catalog/controller/
The route is product/search so we're looking in /catalog/controller/product for a file called search.php
There is not a third part of the route, so we're looking at the default method which is always "index()"

Now start tracing things in here by dumping out variables to see where it's getting to and with what data.

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 8:04 pm
by chris.dempsey
Sorry, when you said trace I thought you meant in an IDE or Xdebug.

Dumping $search returns empty so $this->request->get['search'] is not seeing the &search parameter in the query string...

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 8:15 pm
by paulfeakins
Nothing fancy here, just good old fashioned stepping through the code by hand ;)

So it looks like that's your problem, for some reason the URL variables aren't getting in to OpenCart's request variable.

What happens if you dump $_GET["search"] ?

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 8:27 pm
by chris.dempsey
echo $_GET['search']; returns
Undefined index: search

echo print_r($_GET); returns

Array
(
[route] => product/search
)
1

URL definitely has search parameter in query string: /index.php?route=product/search&search=brush

Re: Search function fails to return results

Posted: Thu Feb 08, 2018 9:14 pm
by chris.dempsey
<Punches self in face repeatedly>

It was a badly written rewrite rule in the web server config file.

Thanks Paul

Re: Search function fails to return results [SOLVED]

Posted: Thu Feb 08, 2018 9:48 pm
by paulfeakins
Ah ha, good find, happy to help :)