默認情況下,我已經閱讀了有關通過opencart中的描述和子類別進行搜索的各種條目,但我有一個獨特的問題。 我有兩個頭文件,因爲我的網站有兩個標頭 ...一個用於主頁,另一個用於其他頁面。Opencart 1.5.4按說明搜索
其他網頁: https://garrysun.com/ayurveda-products/categories
當我主頁上搜索我得到正確的結果(搜索單詞「心臟」),但是當我搜索任何其他頁面它不返回搜索說明或子類別。
其他頁面的搜索結果:https://garrysun.com/index.php?route=product/search&filter_name=heart
正如你可以看到,當我搜索其他頁面沒有被添加額外的代碼說明和子類別進行搜索。
那麼,爲什麼我添加的這個新代碼在主頁上並沒有任何其他頁面?
爲了使這個搜索功能工作,我已經改變了common.js文件看起來像這樣(添加低於每一種兩線「URL = $(基地......」部分:
/* 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>
謝謝,謝謝,謝謝!我試圖弄清楚自己的頭腦。很棒! – MattM
很高興能幫到你! :) 祝你好運! – Yani