Page 1 of 1

Moved search function, now broke - SOLVED.

Posted: Thu Oct 20, 2011 10:50 pm
by Tallowman
Hi all.

Have a done a few themes myself, but in this new one, thought I'd get fancy. I have put in a jquery slider div on the left side of the screen that contains the currency changer and the search box. You know the type, little tab, you click on it and a div slides out nicely from the side of the screen with loads of goodies on it.

Only problem is, the search function has stopped working. Currency is fine.

Pressing enter after entering a search term and nothing happens. Click on the search icon and it tries to take me here:

undefinedindex.php?route=product/search&filter_name=hello

After searching the forums for a while, it does seem that there are a few problems with moving the search function. I tried a module that allows me to put the search function anywhere, but i can't put it in my custom slide-in div.

I would have thought that it might be an issue with the javascript not finding the element prorperly? But then I don't see any errors in my console.

Bit baffled. Any help appreciated. I'm on opencart 1.5.1.3

Cheers.

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 1:26 am
by JAY6390
Chances are whatever is undefined is set in the header controller, and you're using it outside of the header template. is that the case?

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 4:41 am
by Tallowman
Unfortunately not, still in the header template, but outside the header div. I put the slide-in div straight after the body tag, before the header.

Worryingly though, when I put the Search chunk of code back where it was, it's still not working. So I removed the js that's been added, and still not working.

Gah. How does the search function work? Trying to get to the bottom of it, but can't see where it sources in the link... Will have a good look at the header controller though. Good place to start again!

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 4:44 am
by JAY6390
Generally the search is just a call to the product/search route, and the query is passed along to the page. Do you have a link to the site?

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 4:03 pm
by Tallowman
That's what I don't get about it breaking - I imagine that the search route is called by some js somewhere as it's not in the html, but without being familiar with the opencart js structure, there's a lot to look through!

Lin k to site - 'fraid not, it's on my xampp set up. I think I'm going to back it out and then put back in slowly, see where it breaks. If still don't get anywhere then will put live I reckon, see if anyone can make anything of it :-\

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 4:25 pm
by Tallowman
Nearly Solved...

I forgot to echo out the base href, so that explains why it was going to the wrong place. Now it doesn't work after pressing return, only when I click on the icon. No great shakes, sure I'll figure it out.

cheers,
Tallowman

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 4:30 pm
by uksitebuilder
look in catalog/view/javascript/common.js

you should have the following or similar

Code: Select all

	$('#header input[name=\'filter_name\']').keydown(function(e) {
		if (e.keyCode == 13) {
			url = 'index.php?route=product/search';
			 
			var filter_name = $('input[name=\'filter_name\']').attr('value')
			
			if (filter_name) {
				url += '&filter_name=' + encodeURIComponent(filter_name);
			}
			
			var myString = filter_name.replace(/^\s+|\s+$/g, '');
			if (myString.length > 1) {
				location = url;
			}
		}
	});	
If you have moved the search to a different div, try changing #header to the id of your div where it now resides.

Re: Moved search function, now broke.

Posted: Fri Oct 21, 2011 4:46 pm
by Tallowman
Was just coming back to say I'd found the js! Cheers UKSB, that's exactly what I've done and it works perfectly now.

:)

Re: Moved search function, now broke - SOLVED.

Posted: Wed Mar 14, 2012 8:26 am
by eleven28
@uksitebuilder

You mean after all that, all I needed to do was change one little word in the common.js file!? <weak smile>

Ah well, it works now. Thanks.