Magento - Autocomplete Suggest Search Not Working

Magento - Autocomplete Suggest Search Not Working



I have incorporated a new theme in Magento v1.4.2.0, and have completed all the necessary changes, but only following true Magento way of overriding the Magento modules & methods.



My only problem is that the auto complete suggest search functionality in the front-end is not working at all. The AJAX is running as I can view the calls in "Firebug" (with the status showing as "200 OK"), but the search result dropdown isn’t coming.


Firebug



Some more info:


get


form.mini.phtml


q


exception.log


system.log


1


form.mini.phtml


Firebug


blank


NULL



Edit:-

I am also getting another problem. Say I have 4 products, each starting with a name "Test". Also let's assume that the name of these 4 Products are "Test 1", "Test 2", "Test 3", "Test 4".

Now if I do a simple search with query "Test", in the router "catalogsearch/index", then result is showing that there are 4 Products available, which is correct. But if I do a search with query as "Test 1", then no results are showing, which is very much weird.


catalogsearch/index



Also I am using "jQuery", with no conflict condition. However, there are also 6 plugins of "jQuery", all of which are not following the no conflict condition perfectly. This is because the code in some of those plugins are huge, & it is impossible for me to change each & every "$" sign to "jQuery", making it no conflict compatible. Can anybody suggest for this sort of problem too? And whether it is affecting the Auto Suggest Search in any way?


jQuery


jQuery


$


jQuery





So nobody has any solution?
– Knowledge Craving
Feb 21 '11 at 7:07





Have you tried switching to a default theme temporarily to help determine its your template files or not? As for the other problem, it sounds like your product indexes need to be rebuilt, you can also try and disable the flat tables to see if it helps.
– B00MER
Feb 23 '11 at 17:19





@B00mer - I have tried switching to default theme but in vain. There also it's not working. Indexes have been rebuilt many a times, so it's not the fault of product indexes. Lastly, it will be fatal for the project to let go of the use of flat tables, since the client himself demanded that option. :(
– Knowledge Craving
Feb 24 '11 at 6:09





try to wrap your jQuery plugins code with function call and define $ as local scope. Just create a closure and execute it over the plugin code: function ($) ..Plugin code goes here.. (jQuery);
– Ivan Chepurnyi
Feb 24 '11 at 11:24



function ($) ..Plugin code goes here.. (jQuery);




4 Answers
4



It sounds as though there is an issue with the way that the server is responding to the AJAX calls rather than a problem with the form or the javascript. I would suggest that you need to debug a couple of key areas.



Ideally, you would debug this with Xdebug on your Apache hooked into your IDE (Netbeans, Eclipse, other). My personal preference/setup is Netbeans, but others will work fine. If you can't use live debugging, you can insert print_r/echo statements through the code blocks and trace the call that way.



The javascript on form.mini.phtml should be sending the request to Mage_CatalogSearch_AjaxController and the suggestAction. Set breakpoints/trace messages either side of the first if statement in this method.


Mage_CatalogSearch_AjaxController


suggestAction


if



If the breakpoint/trace doesn't get hit, try manually hitting the action by putting http://hostname/catalogsearch/ajax/suggest?q=query in your browser address bar.


http://hostname/catalogsearch/ajax/suggest?q=query



If that doesn't work, there's something broken with the config of the catalogsearch module, probably to do with the <frontname><routers> section. Use Alan Storm's Configviewer or CommerceBug modules to debug that.


<frontname><routers>



The AjaxController creates an instance of Mage_CatalogSearch_Block_Autocomplete which does the actual query. Set a breakpoint/trace just before $suggestData = $this->getSuggestData(); to check that the Block is getting instantiated.


AjaxController


Mage_CatalogSearch_Block_Autocomplete


$suggestData = $this->getSuggestData();



After that line, the block calls it's own getSuggestData() method. Continue to trace through the code to see where the error occurs.


getSuggestData()



The Block calls this method to retrieve the values that match the q param, in particular the setQueryFilter() method which inserts the param into the SQL query criteria. Again, trace through here to find the error.


q


setQueryFilter()



I can't emphasize enough how much easier you will find this (and most Magento issues) when you're using live debugging in your IDE. Have a read of my answer here if you want tips on this process.



Make sure that you have the server in Developer Mode to output as many errors as possible.





First of all, many thanks for such a detailed highlight. But before reading any more of this comment, please read my edited question. Now I have been checking the code, and all it seems is okay, except that I am lost at "Mage_CatalogSearch_Model_Query::getSuggestCollection()". Also I have worked & manipulated some attributes (some system attributes have been edited to just user-defined ones directly from the database, and have been made out of attribute set), due to client requirements. But how does it affect the auto suggest feature is my major concern. Can you please highlight?
– Knowledge Craving
Feb 23 '11 at 9:15


Mage_CatalogSearch_Model_Query::getSuggestCollection()





If you have a separate question re how Search works, please raise a new question and we'll deal with that. What do you mean you are getting lost at that point, you can't find the file to insert the trace messages? What is working so far?
– Jonathan Day
Feb 24 '11 at 4:28



If you view the source of a working site (view-source:http://demo.magentocommerce.com/) you should find the search form looks like this:


<div class="form-search">
<label for="search">Search:</label>
<input id="search" type="text" name="q" value="" class="input-text" />
<button type="submit" title="Search" class="button"><span><span>Search</span></span></button>
<div id="search_autocomplete" class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', 'Search entire store here...');
searchForm.initAutocomplete('http://demo.magentocommerce.com/catalogsearch/ajax/suggest/', 'search_autocomplete');
//]]>
</script>
</div>



The important part seems to be an element called search_autocomplete and it's ID is passed to searchForm.initAutocomplete(). Also make sure your new theme includes prototype.js and the files from js/varien/ and doesn't have any other Javascript errors.


search_autocomplete


searchForm.initAutocomplete()


prototype.js


js/varien/





All the above has already been done correctly, otherwise the Firebug would not have worked fetching the NULL / blank AJAX responses. :( Question edited, as per your answer.
– Knowledge Craving
Feb 19 '11 at 14:07



Firebug


NULL


blank





can you post the URL that Firebug shows that the AJAX request is being submitted to?
– Jonathan Day
Feb 22 '11 at 10:13



Please check one time, that you search after a word, you know, that the product is existing. If it cannot be shown then, press enter and you will be send to result view. After that test, if you can find the article now in suggest search.





This is a really good point, auto suggest results only come from a cache of prior searches - if you are testing a new store you will only get empty AJAX responses until you actually commit the search, then next time you type that phrase you'll start to get a return value.
– benz001
Oct 14 '14 at 3:49



I have the same problem ... it looks like there is a bug in the search or a conflict with some extension mabye the German Markets one ....



Check what you get if you enter this: http://www.studio-ausruestung.de/catalogsearch/ajax/suggest/?q=% with your sitename of course.



Normaly you have to get all results ...





blank page as ajax response, help please.
– ReNiSh A R
Nov 30 '15 at 16:27






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế