我试图在标题auto suggest中显示基于类别的search结果,
form.mini.phtml
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<select id="select-category" title="Select your category" name="cat">
<option value="0" selected>Select category</option>
<?php
foreach ($categoryCollection as $category) { ?>
<option value="<?php echo $category->getId(); ?>"><?php echo $category->getName(); ?></option>
<?php } ?>
</select>
<div class="input-box">
<label for="search"><?php echo $this->__('Search:') ?></label>
<input id="search" type="search" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="input-text required-entry" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" placeholder="<?php echo $this->__('Search entire store here...') ?>" />
<button type="submit" title="<?php echo $this->__('Search') ?>" class="button search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>
</div>
<div id="search_autocomplete" class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', '');
searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
//]]>
</script>
</form>

在此表单中,当我输入输入框时,ajax请求传递如下
http://127.0.0.1/site/catalogsearch/ajax/suggest/?q=bla但所选的cat值不包括在此url中,如何将Cat="bla"包含在ajax/suggest url中
http://127.0.0.1/site/catalogsearch/ajax/suggest/?q=bla&cat=bla
谢谢!
发布于 2015-09-28 13:40:55
如果您已经在任何类别页面上实现了此搜索功能,则可以从以下位置获取要在控制器中筛选的类别id:
Mage::registry('current_category')->getId();如果希望仍然编辑除类别页之外的其他页面的ajax调用,可以在以下内容中编辑该调用:
magento/js/varien/js.js (调试initAutocomplete函数)
https://stackoverflow.com/questions/32824119
复制相似问题