【发布时间】:2014-01-24 18:43:37
【问题描述】:
默认情况下,我已阅读有关在 opencart 中按描述和子类别搜索的各种条目,但我有一个独特的问题。 我有两个头文件,因为我的网站有 2 个头...一个用于主页,一个用于其他页面。
其他页面: https://garrysun.com/ayurveda-products/categories
当我在主页上搜索时,我得到了正确的结果(搜索单词“heart”)但是当我搜索任何其他页面 它不返回对描述或子类别的搜索。
其他页面搜索结果:https://garrysun.com/index.php?route=product/search&filter_name=heart
如您所见,当我搜索其他页面时,没有添加额外的代码来搜索描述和子类别。
那么,为什么我添加的这个新代码适用于主页而不是其他任何页面?
为了使这个搜索功能正常工作,我将 common.js 文件更改为如下所示(在每个 "url= $(base..." 部分下方添加两行:
/* Search */
$('.button-search').bind('click', function() {
url = $('base').attr('href') + 'index.php?route=product/search';
url += '&filter_description=true'; // ADDED this to search descriptions
url += '&filter_sub_category=true'; // ADDED this to search sub-categories
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name) ;
}
location = url;
});
$('#header input[name=\'filter_name\']').bind('keydown', function(e) {
if (e.keyCode == 13) {
url = $('base').attr('href') + 'index.php?route=product/search';
url += '&filter_description=true'; // ADDED this to search descriptions
url += '&filter_sub_category=true'; // ADDED this to search sub-categories
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name) ;
}
location = url;
}
});
两个头文件使用相同的代码调用搜索功能:
<div id="search">
<div class="button-search"></div>
<?php if ($filter_name) { ?>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
<?php } else { ?>
<input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#000000';" />
<?php } ?>
</div>
</div>
【问题讨论】: