Magento - 自动完成建议搜索不起作用
我在 Magento v1.4.2.0 中加入了一个新主题,并完成了所有必要的更改,但仅遵循真正的 Magento 方式来覆盖 Magento 模块和主题。方法。
我唯一的问题是前端的自动完成建议搜索功能根本不起作用。 AJAX 正在运行,因为我可以查看“Firebug
”中的调用(状态显示为“200 OK”),但搜索结果下拉列表没有出现。
更多信息:
- 检查表单的方法并将其设置为“
get
”。 - “
form.mini.phtml
”中文本字段的名称是“q
”。 - 检查了两个日志文件(
exception.log
和system.log
),但此处未打印任何有关自动完成搜索的内容。 - 检查最小查询长度的设置(从“系统 > 配置 > 目录 > 目录搜索 > 最小查询长度”)并将其设置为“
1
” 。 - 尽可能精确地将所有 HTML 合并到“
form.mini.phtml
”页面中,并包含所有必需的 JS 文件,其中没有任何错误。因此,Firebug
报告blank
/NULL
AJAX 响应,没有任何错误。
编辑:-
我还遇到另一个问题。假设我有 4 个产品,每个产品都以名称“测试”开头。另外,我们假设这 4 个产品的名称为“测试 1”、“测试 2”、“测试 3”、“ >测试 4”。
现在,如果我在路由器“catalogsearch/index
”中使用查询“Test”进行简单搜索,则结果显示有 4 个产品可用,这是正确的。但是,如果我使用查询“测试 1”进行搜索,则不会显示任何结果,这非常奇怪。
我还使用“jQuery
”,没有冲突条件。然而,还有6个“jQuery
”插件,它们都没有完美遵循无冲突条件。这是因为其中一些插件中的代码非常庞大,&我不可能改变每一个 &每个“$
”符号都指向“jQuery
”,使其不冲突兼容。有人也可以针对此类问题提出建议吗?它是否会以任何方式影响自动建议搜索?
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.
Some more info:
- Checked the method of the form and it is set as "
get
". - Name of the text field in the "
form.mini.phtml
" is "q
". - Checked both the Log Files (
exception.log
&system.log
), but nothing is printed here regarding auto complete search. - Checked the settings of Minimal Query Length (from "System > Configuration > Catalog > Catalog Search > Minimal Query Length") and it is set to "
1
". - Incorporated all the HTML in the "
form.mini.phtml
" page as precisely as possible, along with including all the required JS files without any errors in them. As a result, theFirebug
is reporting theblank
/NULL
AJAX responses, without any errors.
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来好像服务器响应 AJAX 调用的方式存在问题,而不是表单或 JavaScript 存在问题。我建议您需要调试几个关键区域。
理想情况下,您可以在连接到 IDE(Netbeans、Eclipse 等)的 Apache 上使用 Xdebug 进行调试。我个人的偏好/设置是 Netbeans,但其他的也可以正常工作。如果无法使用实时调试,则可以通过代码块插入 print_r/echo 语句并以这种方式跟踪调用。
form.mini.phtml 上的 javascript 应将请求发送到
Mage_CatalogSearch_AjaxController
和suggestAction
。在此方法中第一个if
语句的两侧设置断点/跟踪消息。如果未命中断点/跟踪,请尝试通过在浏览器地址栏中输入
http://hostname/catalogsearch/ajax/suggest?q=query
来手动触发该操作。如果这不起作用,则说明目录搜索模块的配置出现问题,可能与
部分有关。使用 Alan Storm 的 Configviewer 或 CommerceBug 模块进行调试。AjaxController
创建一个执行实际查询的Mage_CatalogSearch_Block_Autocomplete
实例。在$suggestData = $this->getSuggestData();
之前设置断点/跟踪,以检查块是否正在实例化。在该行之后,块调用它自己的
getSuggestData()
方法。继续跟踪代码,看看哪里出错了。块调用此方法来检索与
q
参数匹配的值,特别是将该参数插入 SQL 查询的setQueryFilter()
方法标准。再次跟踪这里以找到错误。当您在 IDE 中使用实时调试时,您会发现这个问题(以及大多数 Magento 问题)变得多么容易,我怎么强调都不为过。阅读
确保您的服务器处于开发者模式以输出尽可能多的内容尽可能的错误。
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 thesuggestAction
. Set breakpoints/trace messages either side of the firstif
statement in this method.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.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.The
AjaxController
creates an instance ofMage_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.After that line, the block calls it's own
getSuggestData()
method. Continue to trace through the code to see where the error occurs.The Block calls this method to retrieve the values that match the
q
param, in particular thesetQueryFilter()
method which inserts the param into the SQL query criteria. Again, trace through here to find the error.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.
请检查一次,您搜索某个词后,您知道该产品是否存在。如果无法显示,请按 Enter 键,您将进入结果视图。测试后,您现在是否可以在建议搜索中找到该文章。
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.
如果您查看工作网站的源代码(view-source:http://demo.magentocommerce.com/),您应该会发现搜索表单如下所示:
重要的部分似乎是一个名为
search_autocomplete 并将其 ID 传递给
searchForm.initAutocomplete()
。另请确保您的新主题包含prototype.js
和js/varien/
中的文件,并且没有任何其他 Javascript 错误。If you view the source of a working site (view-source:http://demo.magentocommerce.com/) you should find the search form looks like this:
The important part seems to be an element called
search_autocomplete
and it's ID is passed tosearchForm.initAutocomplete()
. Also make sure your new theme includesprototype.js
and the files fromjs/varien/
and doesn't have any other Javascript errors.我有同样的问题...看起来搜索中存在错误或与德国市场的某些扩展名发生冲突...
检查输入以下内容后会得到什么:http://www.studio-ausruestung.de/catalogsearch/ajax/suggest/?q=% 当然是你的网站名称。
通常你必须得到所有结果......
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 ...