2014-01-24 99 views
0

默認情況下,我已經閱讀了有關通過opencart中的描述和子類別進行搜索的各種條目,但我有一個獨特的問題。 我有兩個頭文件,因爲我的網站有兩個標頭 ...一個用於主頁,另一個用於其他頁面。Opencart 1.5.4按說明搜索

首頁: https://garrysun.com/

其他網頁: https://garrysun.com/ayurveda-products/categories

當我主頁上搜索我得到正確的結果(搜索單詞「心臟」),但是當我搜索任何其他頁面不返回搜索說明或子類別

主頁搜索結果:https://garrysun.com/index.php?route=product/search&filter_description=true&filter_sub_category=true&filter_name=heart

其他頁面的搜索結果: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> 

回答

1

試圖找出什麼是錯在你的幾分鐘(失敗)代碼後,我跑了網絡調試,發現沒有什麼是錯的代碼,你只是調用2個不同的Javascript fil es(!):

在您的主頁上,您使用的是位於https://garrysun.com/catalog/view/javascript/common.js的common.js。

在您的分類頁面上,您使用的是位於https://garrysun.com/catalog/view/javascript/add2cart-go2cart/common.js的common.js。

第二屆一個不包括您的修改,看起來像這樣:

$('.button-search').bind('click', function() { 
     url = $('base').attr('href') + 'index.php?route=product/search'; 

     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'; 

      var filter_name = $('input[name=\'filter_name\']').attr('value'); 

      if (filter_name) { 
       url += '&filter_name=' + encodeURIComponent(filter_name); 
      } 

      location = url; 
     } 
    }); 

Vuala。

希望這會有所幫助!

+0

謝謝,謝謝,謝謝!我試圖弄清楚自己的頭腦。很棒! – MattM

+0

很高興能幫到你! :) 祝你好運! – Yani