Close

January 9, 2015

Magento Google Custom Search Integration

We have a lot of experience setting up Google Custom Search engines for both CE and EE versions of Magento. Before making the jump to outright purchasing the Google CSE (Custom Search Engine), we recommend installing the free/ad-supported version on a site to see how relevant the results are with the site. Below is a brief, step-by-step overview to setting it up.

1.) Setup your custom Google Search Engine at Google and copy the code they provide.

2.) Create a new PHTML file google_search.phtml and add it in your frontend theme folder:
ie: app\design\frontend\themename\template\page\google_search.phtml

Add your search code from google directly to it.
Be sure to add a catch to grab the search query submitted.

3.) Create CMS page called Google Search Results.
URL Key: search-results
4.) Add content:

{{block type="core/template" template="page/google_search.phtml"}}

5.) Modify your skin templates to use Google’s search instead of Magento search (most likely in header.phtml or catalogsearch/form.mini.phtml)

            	<form action="/search-results/" method="get">
                <div>
                	<input type="text" class="search_field" name='q' onclick='this.value=""' />
                    <input name="" type="button" class="search_button" value="" onclick='this.form.submit()' />
                </div>
                </form>

6.) You should be able to enter a query in your search box and have it retrieve Google Search results. Using the Google CSE Admin tool, you can change how the search results look and have the results automatically carry over into your Magento search.