2

On the webshop that I'm working on, the user can find products by choosing filters (attributes like color/size/category) and/or entering a search query, the search results are then displayed on the search results page. However, when the search text is left empty, Magento redirects to the homepage instead of showing results, even if other filters are filled in.

In the admin, I have set the 'Minimal Query Length' to 0, but this doesn't make any difference.

I've created a workaround by setting the search param to '0' before submitting when left empty, which will make Magento display all the products anyway. But it's not a great solution because the string '0' appears everywhere on the page including in the popular search block in the admin page.

Is there an elegant way to solve this issue without having to override all kinds of core classes?

You can find a demo of the problem here, if you replace the 'q=watch' by 'q=' I want it to show all the products.

0

I've just overridden Magento\CatalogSearch\Controller\Result\Index with a copy of that file and removed the condition if ($queryText != '') { ... }, that seems to work. But if anyone has a better solution I like to hear it.

0

Store > Configuration > Catalog and choose Catalog. After that, expand the Catalog Search section and do the following:

Set Minimal Query Length to the minimum number of characters that can be submitted in a query. Maybe magento will let you set 0. Not 100% though.

Your solution is perfectly acceptable.

  • It does allow 0, but it will still reject empty search query. I assume there is no other way other than overriding the controller. – Arne Jun 17 at 18:20
  • @Arne you could create your custom controller, and forward to Result\Index only when queryText has some value. This is just an idea, it involves more work, but you wouldn't have to maintain a core controller. – vitoriodachef Jun 17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.