Answer the question
In order to leave comments, you need to log in
How to implement search in Opencart?
Started learning Opencart. I'm making a template from scratch. I can't figure out how to search.
In the header.tpl, the place I needed indicated <?php echo search ?>
the output is:
<div id="search" class="input-group">
<input type="text" name="search" value="" placeholder="Поиск" class="form-control input-lg">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-lg"><i class="fa fa-search"></i></button>
</span>
</div>
Answer the question
In order to leave comments, you need to log in
You need to add a script:
$('.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;
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question