Select ca-6ren">
gpt4 book ai didi

javascript - 如何在标题搜索 Magento 中显示带有类别过滤器的产品

转载 作者:行者123 更新时间:2023-11-28 06:52:37 24 4
gpt4 key购买 nike

我正在尝试在标题搜索中显示基于类别的自动建议结果,

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>

enter image description here

在这个表单中,当我在输入框中输入 ajax 请求时,就像这样传递

http://127.0.0.1/site/catalogsearch/ajax/suggest/?q=bla

但选定的 cat 值不包含在此网址中,如何在 ajax/suggest 网址中包含 Cat="bla",如

http://127.0.0.1/site/catalogsearch/ajax/suggest/?q=bla&cat=bla

谢谢!

最佳答案

如果您在任何类别页面上实现了此搜索功能,您可以从以下位置获取类别 ID 以在 Controller 中进行过滤:

Mage::registry('current_category')->getId();

如果您仍希望编辑除类别页面之外的页面的ajax调用,您可以在以下位置编辑:

magento/js/varien/js.js(调试 initAutocomplete 函数)

关于javascript - 如何在标题搜索 Magento 中显示带有类别过滤器的产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32824119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com