Advanced search in Magento and how to use it in your own way

Advanced search in Magento and how to use it in your own way

Magento’s default catalog search can be a powerful tool. It’s versatility is something every customer can appreciate.

One of the coolest features of the built-in advanced search is the ability to search by attributes assigned to a product. But what if your client’s plans for search are a bit different, and advanced search is too cluttered for his or her needs?

Let’s say your client wants his customers to be able to search by brand or SKU, with all other fields removed from the search, and wishes for custom URL for each one of those search types.

The solution

Attached in this article is a little “module” that enables you to use your custom URL for advanced search.

This means that instead of
http://your-store.com/catalogsearch/advanced/ you could use
http://your-store.com/search/ for advanced search.

Not only that, but you can specify a single attribute you want to search by!

You could even use this to implement search by brand or SKU. In any case, the search form action URL is e.g. http://your-store.com/search/results/for/?sku=1, which can be useful and very SEO-friendly.

Keep in mind, though, that this is a custom developed module, without admin options, so everything you want to do with this search module has to be done by code.

Walkthrough

I’ll walk you through a few basic modifications to this module.

Changing the URL of your advanced search

  • in app\code\community\Inchoo\Search\etc\config.xml replace ‘search‘ with your desired url
<frontName>search</frontName>

Replacing SKU (default in this module) with another attribute

  • in app\design\frontend\base\default\template\inchoo\search\form.phtml change the condition (‘sku‘) to attribute of your desire. Note that the attribute must be set as visible and searchable in Admin->Catalog->Attributes->Manage attributes
<?php if($_code == 'sku'):>
  • open app\code\community\Inchoo\Search\Block\Results.php and change attribute ‘sku‘ to the attribute of your desire
$title = $this->__("Search results for: '%s'", $this->getRequest()->getQuery('sku'));

And you are done! Now you have somewhat more custom url, and only one custom field displayed on your advanced search.

Download zipped source or view this module on GitHub.

Note: This is a revamp of the article originally written in November 2008.

You made it all the way down here so you must have enjoyed this post! You may also like:

Add Pagination to Custom Collection in Magento Dario Trbovic
Dario Trbovic

Add Pagination to Custom Collection in Magento

Optimize Elasticsearch autocomplete URL for Google Analytics Matej Djakovic
Matej Djakovic

Optimize Elasticsearch autocomplete URL for Google Analytics

3 things you should do today with your Magento store to improve your sales Toni Anicic
Toni Anicic

3 things you should do today with your Magento store to improve your sales

Tell us about your project

Drop us a line. We'd love to know more about your project.