V
V
Valery Vitalievich2020-08-04 17:59:25
opencart
Valery Vitalievich, 2020-08-04 17:59:25

How to implement search for opencart 3.0?

I'm redoing the default theme of opencarat 3, but I'm stuck with the search, it doesn't work for some reason. I
tend to the script, tell me how to fix it so that it works, I return everything to the default data.

<div id="search" class="col-8 col-md-8 col-lg-5 col-xl-7">
                      <div class="search-input">
                        <input type="text" name="search" value="{{ search }}" placeholder="{{ text_search }}" class="no-round-input no-border" />
                      </div>
                    </div>
                    <div class="col-4 col-md-4 col-lg-3 col-xl-2">
                      <button type="button" class="no-round-btn">{{ text_search }}</button>
                    </div>


and script

$('#search input[name=\'search\']').parent().find('button').on('click', function() {
    var url = $('base').attr('href') + 'index.php?route=product/search';

    var value = $('header #search input[name=\'search\']').val();

    if (value) {
      url += '&search=' + encodeURIComponent(value);
    }

    location = url;
  });

  $('#search input[name=\'search\']').on('keydown', function(e) {
    if (e.keyCode == 13) {
      $('#search input[name=\'search\']').parent().find('button').trigger('click');
    }
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Har8iunian, 2020-08-06
@valera_91

There was a similar question

$('.button-search').bind('click', function() {
    url = $('base').attr('href') + 'index.php?route=product/search';
    var search = $('input[name=\'search\']').attr('value');
    if (search) {
      url += '&search=' + encodeURIComponent(search);
    }
    location = url;
  });
$('#header input[name=\'search\']').bind('keydown', function(e) {
    if (e.keyCode == 13) {
      url = $('base').attr('href') + 'index.php?route=product/search';
      var search = $('input[name=\'search\']').attr('value');
      if (search) {
        url += '&search=' + encodeURIComponent(search);
      }
      location = url;
    }
  });

Author of the solution Alexey

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question