2/15/2016 - 5:55 AM

How to create auto complete search in magento ?

How to create auto complete search in magento ?

// Use type ahead search for fast search results

// Put below mentioned library in your head section

<!--<script src=""></script>
<script src=""></script>-->    

// Use below mention code in you catalogsearch/ file

var gp = $.noConflict();
        name : 'username',
        remote: {
            url : ''

<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
    <div class="search-box">
        <label for="search"><?php echo $this->__('Categories:') ?></label>
        <input id="search" type="text" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="input-text serch" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" placeholder="Search entire store here" />
        <button type="submit" title="<?php echo $this->__('Search') ?>" class="button search-icon"><span><span><?php //echo $this->__('Search') ?></span></span></button>
        <div id="search_autocomplete" class="search-autocomplete"></div>
        <script type="text/javascript">
            var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Search entire store here...') ?>');
            searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
    <div class="myrspns"></div>
// You can create you module and put below code on your module controller's file

class Zap_LoginWorld_SearchController extends Mage_Core_Controller_Front_Action{

     public function indexAction(){
        $searchData = $_GET['query'];
	        require_once 'app/Mage.php';
	        $collection = Mage::getModel('catalog/product')->getCollection();
	        $collection->addAttributeToSelect(array('name', 'price'));
	        $collection->addAttributeToFilter('name', array('like' => '% '.$searchData.'%'));	        
			foreach ($collection as $product) { 
	        		$res[] = $product->getName();
		       echo json_encode($res);