My goal is to achieve the following modification in the Magento catalog search.
When I search for a product and only one product is returned in the result collection, I want to display to product view page instead of the product list page.
Can you give me an advice how and where I should start searching to do this modification?
At the moment I'm really lost in this whole lot of code.
Using Magento 1.9.0.1
Best Answer
You need to create a new extension that checks, before rendering the quick search (or advanced search) page if the product collection contains exactly one product.
For this let's create a new extension called
StackExchange_CatalogSearch
.You will need to following files:
app/etc/modules/StackExchange_CatalogSearch.xml
- the declaration fileapp/code/local/StackExchange/CatalogSearch/etc/config.xml
- the configuration file:app/code/local/StackExchange/CatalogSearch/Model/Observer.php
- the observer that does all the work.Clear the cache, disable compilation if enabled and give it a go.
Note: This extension redirects to the product page when the search (and advanced search) page should return only on product, even if this happens after the search or after applying a layered navigation filter.