当没有指定搜索词时,如何使 Magento 高级搜索显示所有产品?

发布于 2024-12-04 17:22:42 字数 217 浏览 0 评论 0原文

有人可以帮我解决这个问题吗?

我在 magento 上使用高级搜索,效果很好,但是当我单击“搜索”而不输入任何搜索词时,它会出现错误或注释:“请指定至少一个搜索词。”

我希望当我点击“搜索”而不输入任何搜索词时,它会显示我所有类别中的所有产品,这怎么可能?

先感谢您。 您的帮助:))

问候

非常感谢 我使用magento 1.5社区版本

Can anyone help me with this problem please?

I use advanced search on magento and it works well, but when I click on "Search" without entering any search terms it gives error or note: "Please specify at least one search term."

I'd like it to show All my products in all categories when I click on "search" without entering any search terms, how is it possible?

Thank you in advance.
Your Help is much appreciated : ))

Regards

P.S. I Use magento 1.5 community version

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春夜浅 2024-12-11 17:22:42

在系统下->配置->目录->目录搜索

将“最小查询长度”更改为 0,然后再次尝试搜索。

我想指出的是,通配符搜索可能非常繁重,具体取决于您搜索的属性数量以及产品数量。这也取决于 LIKE 与 FULLTEXT。

至于第二个问题,这可以处理上面admin中同一位置的分层导航。我会将“如果搜索结果小于则应用分层导航”的数量设置为等于主要可见性中的产品数量。默认情况下,类别是分层导航的一部分。

Under System -> Configuration -> Catalog -> Catalog Search

Change "Minimal Query Length" to 0 and attempt your search again.

I would like to note that wildcard searches can be very taxing depending on the number of attributes that you are searching on, as well the number of products. This can also depend on LIKE vs FULLTEXT.

As for the second question, this can deal with the Layered Navigation on the same place in admin above. I would set the number for "Apply Layered Navigation if Search Results are Less Than" equal to the number of products you have in your primary visibility. Categories are part of layered navigation by default.

┈┾☆殇 2024-12-11 17:22:42

这是一篇旧帖子,但由于我最近遇到了同样的问题,这就是我解决它的方法。拒绝您能够在没有任何参数的情况下进行搜索的代码位于文件中

app/code/core/Mage/CatalogSearch/Model/Advanced.php

第 208 行函数 addFilters() 中(Magento v1.8.1):

if ($allConditions) {
        $this->getProductCollection()->addFieldsToFilter($allConditions);
    } else if (!$hasConditions) {
        Mage::throwException(Mage::helper('catalogsearch')->__('Please specify at least one search term.'));
    }

因此我们要做的是摆脱抛出的异常。由于我们不想修改任何核心文件,因此我们重写此类并重载 addFilters() 函数以捕获异常,从而启用空的高级搜索。

在您的模块中创建文件

app/code/local/Yournamespace/Yourmodule/Models/Catalogsearch/Advanced.php


class Yournamespace_Yourmodel_Model_Catalogsearch_Advanced extends Mage_CatalogSearch_Model_Advanced {

/**
 * call original addFilters but catch Exception
 * so search WITHOUT search parameters is allowed.
 * 
 * @param array $values
 * @return \Yournamespace_Yourmodel_Model_Catalogsearch_Advanced
 */
public function addFilters($values) {

    try {
        return parent::addFilters($values);
    } catch (Mage_Core_Exception $ex) {

        return $this;
    }

}

}

并用新模型重写原始高级搜索模型:

app/code/local/Yournamespace/Yourmodule/etc/config.xml

...
<global>
    <models>
        <catalogsearch>
            <rewrite>
                <advanced>Yournamespace_Yourmodel_Model_Catalogsearch_Advanced</advanced>
            </rewrite>
        </catalogsearch>
    </models>
</global>
...

这应该可以解决问题。

This is an old post but since i ran into the same problem recently here's how i solved it. The code denying you to be able to search without any parameters lies within the file

app/code/core/Mage/CatalogSearch/Model/Advanced.php

in function addFilters() on line 208 (Magento v1.8.1):

if ($allConditions) {
        $this->getProductCollection()->addFieldsToFilter($allConditions);
    } else if (!$hasConditions) {
        Mage::throwException(Mage::helper('catalogsearch')->__('Please specify at least one search term.'));
    }

So what we want to do is get rid of the Exception beeing thrown. Since we want to never modify any core files we rewrite this class and overload the addFilters() function to catch the Exception, thus enabling an empty advanced search.

Within your module create the file

app/code/local/Yournamespace/Yourmodule/Models/Catalogsearch/Advanced.php


class Yournamespace_Yourmodel_Model_Catalogsearch_Advanced extends Mage_CatalogSearch_Model_Advanced {

/**
 * call original addFilters but catch Exception
 * so search WITHOUT search parameters is allowed.
 * 
 * @param array $values
 * @return \Yournamespace_Yourmodel_Model_Catalogsearch_Advanced
 */
public function addFilters($values) {

    try {
        return parent::addFilters($values);
    } catch (Mage_Core_Exception $ex) {

        return $this;
    }

}

}

and rewrite the original advanced search model with your new one:

app/code/local/Yournamespace/Yourmodule/etc/config.xml

...
<global>
    <models>
        <catalogsearch>
            <rewrite>
                <advanced>Yournamespace_Yourmodel_Model_Catalogsearch_Advanced</advanced>
            </rewrite>
        </catalogsearch>
    </models>
</global>
...

That should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文