【问题标题】:Opencart 1.5.4 Search by DescriptionOpencart 1.5.4 按描述搜索
【发布时间】:2014-01-24 18:43:37
【问题描述】:

默认情况下,我已阅读有关在 opencart 中按描述和子类别搜索的各种条目,但我有一个独特的问题。 我有两个头文件,因为我的网站有 2 个头...一个用于主页,一个用于其他页面。

主页: https://garrysun.com/

其他页面: https://garrysun.com/ayurveda-products/categories

当我在主页上搜索时,我得到了正确的结果(搜索单词“heart”)但是当我搜索任何其他页面不返回对描述或子类别的搜索

首页搜索结果: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= $(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>

【问题讨论】:

    标签: search opencart


    【解决方案1】:

    在试图找出你的代码有什么问题几分钟后(不成功),我运行了一次网络调试,发现你的代码没有任何问题,你只是调用了 2 个不同的 Javascript 文件(!):

    在您的主页上,您使用的是位于 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;
            }
        });
    

    瓦拉。

    希望这会有所帮助!

    【讨论】:

    • 谢谢谢谢谢谢!我一直在打自己的脑袋,试图弄清楚这一点。效果很好!
    • 很高兴我能帮上忙! :) 祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-08
    • 2018-08-11
    • 1970-01-01
    • 2016-09-29
    • 2015-12-19
    相关资源
    最近更新 更多