title: Opencart 3: how to add search method in the Ajax live search module?
body: <p>By the default Ajax live search module can search by product name and SKU. I want to make it so that the search also takes place by manufacturer. I was able to add a manufacturer to the controller so that it appears in the search results, but it does not search for this criterion.</p>
  <p>I've looked at the controller and Java Script code in the template, but I don't see a place anywhere that would be responsible for the search parameters. Maybe someone came across and knows where to look?</p>
  <p>This is <strong>catalog/controller file</strong>:</p>
  <pre><code>&lt;?php
  class ControllerExtensionModuleLiveSearch extends Controller {
      public function index() {
          $json = array();
          if (isset($this-&gt;request-&gt;get['filter_name'])) {
              $search = $this-&gt;request-&gt;get['filter_name'];
          } else {
              $search = '';
          }
          if (isset($this-&gt;request-&gt;get['cat_id'])) {
              $cat_id = (int)$this-&gt;request-&gt;get['cat_id'];
          } else {
              $cat_id = 0;
          }
  
          $tag           = $search;
          $description   = '';
          $category_id   = $cat_id;
          $sub_category  = '';
          $sort          = 'p.sort_order';
          $order         = 'ASC';
          $page          = 1;
          $limit         = $this-&gt;config-&gt;get('module_live_search_limit');
          $search_result = 0;
          $error         = false;
          if( version_compare(VERSION, '3.0.0.0', '&gt;=') ){
              $currency_code = $this-&gt;session-&gt;data['currency'];
          }
          else{
              $error = true;
              $json[] = array(
                  'product_id' =&gt; 0,
                  'image'      =&gt; null,
                  'name'       =&gt; 'Version Error: '.VERSION,
                  'extra_info' =&gt; null,
                  'price'      =&gt; 0,
                  'special'    =&gt; 0,
                  'url'        =&gt; '#'
              );
          }
  
          if(!$error){
              if (isset($this-&gt;request-&gt;get['filter_name'])) {
                  $this-&gt;load-&gt;model('catalog/product');
                  $this-&gt;load-&gt;model('tool/image');
                  $filter_data = array(
                      'filter_name'         =&gt; $search,
                      'filter_tag'          =&gt; $tag,
                      'filter_description'  =&gt; $description,
                      'filter_category_id'  =&gt; $category_id,
                      'filter_sub_category' =&gt; $sub_category,
                      'sort'                =&gt; $sort,
                      'order'               =&gt; $order,
                      'start'               =&gt; ($page - 1) * $limit,
                      'limit'               =&gt; $limit
                  );
                  $results = $this-&gt;model_catalog_product-&gt;getProducts($filter_data);
                  $search_result = $this-&gt;model_catalog_product-&gt;getTotalProducts($filter_data);
                  $image_width        = $this-&gt;config-&gt;get('module_live_search_image_width') ? $this-&gt;config-&gt;get('module_live_search_image_width') : 0;
                  $image_height       = $this-&gt;config-&gt;get('module_live_search_image_height') ? $this-&gt;config-&gt;get('module_live_search_image_height') : 0;
                  $title_length       = $this-&gt;config-&gt;get('module_live_search_title_length');
                  $description_length = $this-&gt;config-&gt;get('module_live_search_description_length');
  
                  foreach ($results as $result) {
                      if ($result['image']) {
                          $image = $this-&gt;model_tool_image-&gt;resize($result['image'], $image_width, $image_height);
                      } else {
                          $image = $this-&gt;model_tool_image-&gt;resize('placeholder.png', $image_width, $image_height);
                      }
  
                      if (($this-&gt;config-&gt;get('config_customer_price') &amp;&amp; $this-&gt;customer-&gt;isLogged()) || !$this-&gt;config-&gt;get('config_customer_price')) {
                          $price = $this-&gt;currency-&gt;format($this-&gt;tax-&gt;calculate($result['price'], $result['tax_class_id'], $this-&gt;config-&gt;get('config_tax')), $currency_code);
                      } else {
                          $price = false;
                      }
  
                      if ((float)$result['special']) {
                          $special = $this-&gt;currency-&gt;format($this-&gt;tax-&gt;calculate($result['special'], $result['tax_class_id'], $this-&gt;config-&gt;get('config_tax')), $currency_code);
                      } else {
                          $special = false;
                      }
  
                      if ($this-&gt;config-&gt;get('config_tax')) {
                          $tax = $this-&gt;currency-&gt;format((float)$result['special'] ? $result['special'] : $result['price'], $currency_code);
                      } else {
                          $tax = false;
                      }
  
                      if ($this-&gt;config-&gt;get('config_review_status')) {
                          $rating = (int)$result['rating'];
                      } else {
                          $rating = false;
                      }
                      $json['total'] = (int)$search_result;
                      $json['products'][] = array(
                          'product_id'  =&gt; $result['product_id'],
                          'image'       =&gt; $image,
                          'name' =&gt; utf8_substr(strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), 0, $title_length) . '..',
                          'extra_info' =&gt; utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $description_length) . '..',
                          'price'       =&gt; $price,
                          'special'     =&gt; $special,
                          'url'        =&gt; $this-&gt;url-&gt;link('product/product', 'product_id=' . $result['product_id'])
                      );
                  }
              }
          }
          $this-&gt;response-&gt;addHeader('Content-Type: application/json');
          $this-&gt;response-&gt;setOutput(json_encode($json));
      }
  }
  
  </code></pre>
  <p>This is <strong>JS code in the template</strong>:</p>
  <pre><code>                var live_search = {
                      selector: '#search input[name=\'search\']',
                      text_no_matches: '{{ text_empty }}',
                      height: '50px'
                  }
  
                  $(document).ready(function() {
                      var html = '';
                      html += '&lt;div class=&quot;live-search&quot;&gt;';
                      html += '   &lt;ul&gt;';
                      html += '   &lt;/ul&gt;';
                      html += '&lt;div class=&quot;result-text&quot;&gt;&lt;/div&gt;';
                      html += '&lt;/div&gt;';
  
                      //$(live_search.selector).parent().closest('div').after(html);
                      $(live_search.selector).after(html);
  
                      $(live_search.selector).autocomplete({
                          'source': function(request, response) {
                              var filter_name = $(live_search.selector).val();
                              var cat_id = 0;
                              var module_live_search_min_length = '{{ module_live_search_min_length|abs }}';
                              if (filter_name.length &lt; module_live_search_min_length) {
                                  $('.live-search').css('display','none');
                              }
                              else{
                                  var html = '';
                                  html += '&lt;li style=&quot;text-align: center;height:10px;&quot;&gt;';
                                  html += '&lt;img class=&quot;loading&quot; src=&quot;catalog/view/theme/default/image/loading.gif&quot; /&gt;';
                                  html += '&lt;/li&gt;';
                                  $('.live-search ul').html(html);
                                  $('.live-search').css('display','block');
  
                                  $.ajax({
                                      url: 'index.php?route=extension/module/live_search&amp;filter_name=' +  encodeURIComponent(filter_name),
                                      dataType: 'json',
                                      success: function(result) {
                                          var products = result.products;
                                          $('.live-search ul li').remove();
                                          $('.result-text').html('');
                                          if (!$.isEmptyObject(products)) {
                                              var show_image = {{ module_live_search_show_image|abs }};
                                              var show_price = {{ module_live_search_show_price|abs }};
                                              var show_description = {{ module_live_search_show_description|abs }};
                                              $('.result-text').html('&lt;a href=&quot;{{ module_live_search_href }}'+filter_name+'&quot; class=&quot;view-all-results&quot;&gt;{{ text_view_all_results|e }} ('+result.total+')&lt;/a&gt;');
  
                                              $.each(products, function(index,product) {
                                                  var html = '';
  
                                                  html += '&lt;li&gt;';
                                                  html += '&lt;a href=&quot;' + product.url + '&quot; title=&quot;' + product.name + '&quot;&gt;';
                                                  if(product.image &amp;&amp; show_image){
                                                      html += '   &lt;div class=&quot;product-image&quot;&gt;&lt;img alt=&quot;' + product.name + '&quot; src=&quot;' + product.image + '&quot;&gt;&lt;/div&gt;';
                                                  }
                                                  html += '   &lt;div class=&quot;product-name&quot;&gt;' + product.name ;
                                                  if(show_description){
                                                      html += '&lt;p&gt;' + product.extra_info + '&lt;/p&gt;';
                                                  }
                                                  html += '&lt;/div&gt;';
                                                  if(show_price){
                                                      if (product.special) {
                                                          html += '&lt;div class=&quot;product-price&quot;&gt;&lt;span class=&quot;price&quot;&gt;' + product.special + '&lt;/span&gt;&lt;/div&gt;';
                                                      } else {
                                                          html += '   &lt;div class=&quot;product-price&quot;&gt;&lt;span class=&quot;price&quot;&gt;' + product.price + '&lt;/span&gt;&lt;/div&gt;';
                                                      }
                                                  }
                                                  html += '&lt;span style=&quot;clear:both&quot;&gt;&lt;/span&gt;';
                                                  html += '&lt;/a&gt;';
                                                  html += '&lt;/li&gt;';
                                                  $('.live-search ul').append(html);
                                              });
                                          } else {
                                              var html = '';
                                              html += '&lt;li style=&quot;text-align: center;height:10px;&quot;&gt;';
                                              html += live_search.text_no_matches;
                                              html += '&lt;/li&gt;';
  
                                              $('.live-search ul').html(html);
                                          }
                                          $('.live-search').css('display','block');
                                          return false;
                                      }
                                  });
                              }
                          },
                          'select': function(product) {
                              $(live_search.selector).val(product.name);
                          }
                      });
  
                      $(document).bind( &quot;mouseup touchend&quot;, function(e){
                        var container = $('.live-search');
                        if (!container.is(e.target) &amp;&amp; container.has(e.target).length === 0)
                        {
                          container.hide();
                        }
                      });
                  });
  
  </code></pre>
  <p>Also module has admin/controller file. But I think that he is not responsible for the search criteria. Any ideas where I can edit the search criteria?</p>