{{ header }}
<div id="product-search">
   <div id="breadcrumb" class="section">
      <!-- container -->
      <div class="container">
        <!-- row -->
        <div class="row">
          <div class="col-md-12">
            <ul class="breadcrumb-tree">
            {% for breadcrumb in breadcrumbs %}
            <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
             {% endfor %}
            </ul>
          </div>
        </div>
      </div>
    </div>
    {% if content_top %}
    <div class="section">
      <div class="container">
          {{ content_top }}
      </div>
    </div>
     {% endif %}
     <div class="section">
      <div class="container">
        <div id="content">
          <h3>{{ heading_title }}</h3> 
          <label class="control-label" for="input-search">{{ entry_search }}</label>
          <div class="row">
            <div class="col-sm-4 form-group">
              <input type="text" name="search" value="{{ search }}" placeholder="{{ text_keyword }}" id="input-search" class="form-control" />
            </div>
            <div class="col-sm-3 form-group">
              <select name="category_id" class="form-control">
                <option value="0">{{ text_category }}</option>
                {% for category_1 in categories %}
                {% if category_1.category_id == category_id %}
                <option value="{{ category_1.category_id }}" selected="selected">{{ category_1.name }}</option>
                {% else %}
                <option value="{{ category_1.category_id }}">{{ category_1.name }}</option>
                {% endif %}
                {% for category_2 in category_1.children %}
                {% if category_2.category_id == category_id %}
                <option value="{{ category_2.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% else %}
                <option value="{{ category_2.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% endif %}
                {% for category_3 in category_2.children %}
                {% if category_3.category_id == category_id %}
                <option value="{{ category_3.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                {% else %}
                <option value="{{ category_3.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                {% endif %}
                {% endfor %}
                {% endfor %}
                {% endfor %}
              </select>
            </div>
            <div class="col-sm-3">
              <input type="button" value="{{ button_search }}" id="button-search" class="btn btn-primary" />
             </div>
          <div class="col-sm-12">
            <label class="checkbox-inline">
              {% if description %}
              <input type="checkbox" name="description" value="1" id="description" checked="checked" />
              {% else %}
              <input type="checkbox" name="description" value="1" id="description" />
              {% endif %}
              {{ entry_description }}</label>
              <label class="checkbox-inline">
                {% if sub_category %}
                <input type="checkbox" name="sub_category" value="1" checked="checked" />
                {% else %}
                <input type="checkbox" name="sub_category" value="1" />
                {% endif %}
                {{ text_sub_category }}</label>
        
          </div>
        </div>
         <hr>
      </div>
      </div>
    </div>
    <div class="section">
      <div class="container">
        <div class="row">
        {{ column_left }}
        {% if column_left and column_right %}
        {% set class = 'col-sm-6' %}
        {% elseif column_left or column_right %}
        {% set class = 'col-sm-9' %}
        {% else %}
        {% set class = 'col-sm-12' %}
        {% endif %}
        <div id="content" class="{{ class }}">
        {% if products %}
            <!-- store top filter -->
            <div class="store-filter clearfix">
              <div class="store-sort">
                <label>
                 {{ text_sort }}
                  <select id="input-sort" class="input-select" onchange="location = this.value;">
                    {% for sorts in sorts %}
                    {% if sorts.value == '%s-%s'|format(sort, order) %}
                    <option value="{{ sorts.href }}" selected="selected">{{ sorts.text }}</option>
                    {% else %}
                    <option value="{{ sorts.href }}">{{ sorts.text }}</option>
                    {% endif %}
                    {% endfor %}
                  </select>
                </label>

                <label>
                   {{ text_limit }}
                   <select id="input-limit" class="input-select" onchange="location = this.value;">
                    {% for limits in limits %}
                    {% if limits.value == limit %}
                    <option value="{{ limits.href }}" selected="selected">{{ limits.text }}</option>
                    {% else %}
                    <option value="{{ limits.href }}">{{ limits.text }}</option>
                    {% endif %}
                    {% endfor %}
                  </select>
                </label>
              </div>
               <div class="store-sort">
                <label>
                   <div class="form-group form-prd-cate"><a href="{{ compare }}" id="compare-total" class="btn btn-compare">{{ text_compare }}</a></div>
                </label>
               </div>
              <ul class="store-grid hidden-xs">
                <button type="button" id="grid-view" class="btn btn-view" data-toggle="tooltip" title="{{ button_grid }}"><i class="fa fa-th"></i></button>
                 <button type="button" id="list-view" class="btn btn-view" data-toggle="tooltip" title="{{ button_list }}"><i class="fa fa-th-list"></i></button>
                
              </ul>
            </div>
            <!-- /store top filter -->
            <!-- store products -->
            <div class="row">
              {% for product in products %}   
              <div class="product-layout product-list col-xs-12">
                 <div class="product">
                      <div class="product-img">
                        <img src="{{ product.thumb }}" alt="{{ product.name }}" class="img-responsive center-block" >
                        <div class="product-label">

				{# start owc_core_productpageenhanced_hooks_twig.xml #}
				{# HOOK_PRODUCTPAGEENHANCED_LIST_BEFORE_PRICE #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
				
                          {% if product.price %}
                          {% if product.special %}
                          <span class="sale">- {{ product.percent }}</span>
                          {% endif %}  
                          {% endif %}  
                            {{ product.top_selling }}
                        </div>
                      </div>
                      <div class="product-body">
                        <p class="product-category">{{ product.category_title}}</p>
                        <h3 class="product-name"><a href="{{ product.href }}">{{ product.name }}</a></h3>
                        <div class="product-desc">{{ product.description }}</div>

				{# start owc_core_productpageenhanced_hooks_twig.xml #}
				{# HOOK_PRODUCTPAGEENHANCED_LIST_BEFORE_PRICE #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
				
                          {% if product.price %}
                          {% if not product.special %}
                             <h4 class="product-price"> {{ product.price }}</h4>
                          {% else %}
                            <h4 class="product-price">{{ product.special }} <del class="product-old-price">{{ product.price }}</del></h4> {% endif %} 
                         {% endif %} 

                         {% if product.rating %}
                          <div class="product-rating">
                          {% for i in 1..5 %}
                            {% if product.rating < i %} <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span> {% else %} <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span> {% endif %}
                            {% endfor %}
                          </div>
                          {% else %} 
                            <div class="product-rating"></div>
                          {% endif %}

                        <div class="product-btns">
                          <button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>
                          <button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>
                           <a class="quick-view" data-toggle="tooltip" href="{{ product.href }}" title="View"><i class="fa fa-eye"></i></a>
                            <button class="add-to-cart-btn btn-cart-icon" onclick="cart.add('{{ product.product_id }}');"><i class="fa fa-shopping-basket"></i></button>
                        </div>
                      </div>
                      <div class="add-to-cart">
                        <button class="add-to-cart-btn" onclick="cart.add('{{ product.product_id }}');">{{ button_cart }}</button>
                      </div>
                    </div>
                </div>
                {% endfor %} 
            </div>
             <div class="row">
              <div class="section-pagination">
              <div class="col-sm-6 text-left">{{ pagination }}</div>
              <div class="col-sm-6 text-right">{{ results }}</div>
              </div>
            </div>
        {% endif %}
        {% if not categories and not products %}
          <p>{{ text_empty }}</p>
          <div class="buttons">
            <div class="pull-right"><a href="{{ continue }}" class="primary-btn">{{ button_continue }}</a></div>
          </div>
          {% endif %}
        </div>
        </div>
        {{ column_right }}
      </div>
    </div>
    {% if content_bottom %}
    <div class="section">
      <div class="container">
          {{ content_bottom }}
      </div>
    </div>
     {% endif %}
</div>
<script type="text/javascript"><!--
$('#button-search').bind('click', function() {
  url = 'index.php?route=product/search';

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

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

  var category_id = $('#content select[name=\'category_id\']').prop('value');

  if (category_id > 0) {
    url += '&category_id=' + encodeURIComponent(category_id);
  }

  var sub_category = $('#content input[name=\'sub_category\']:checked').prop('value');

  if (sub_category) {
    url += '&sub_category=true';
  }

  var filter_description = $('#content input[name=\'description\']:checked').prop('value');

  if (filter_description) {
    url += '&description=true';
  }

  location = url;
});

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

$('select[name=\'category_id\']').on('change', function() {
  if (this.value == '0') {
    $('input[name=\'sub_category\']').prop('disabled', true);
  } else {
    $('input[name=\'sub_category\']').prop('disabled', false);
  }
});

$('select[name=\'category_id\']').trigger('change');

var cart = {
  'add': function(product_id, quantity) {
    $.ajax({
      url: 'index.php?route=checkout/cart/add',
      type: 'post',
      data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
      dataType: 'json',
      beforeSend: function() {
        $('#cart > button').button('loading');
      },
      complete: function() {
        $('#cart > button').button('reset');
      },
      success: function(json) {
        $('.alert-dismissible, .text-danger').remove();

        if (json['redirect']) {
          location = json['redirect'];
        }

        if (json['success']) {
          $('#content').parent().before('<div class="container alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

          // Need to set timeout otherwise it wont update the total
          setTimeout(function () {
            $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-basket"></i> ' + json['total'] + '</span>');
          }, 100);

          $('html, body').animate({ scrollTop: 0 }, 'slow');

          $('#cart > ul').load('index.php?route=common/cart/info ul li');
        }
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
    });
  },
  'update': function(key, quantity) {
    $.ajax({
      url: 'index.php?route=checkout/cart/edit',
      type: 'post',
      data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
      dataType: 'json',
      beforeSend: function() {
        $('#cart > button').button('loading');
      },
      complete: function() {
        $('#cart > button').button('reset');
      },
      success: function(json) {
        // Need to set timeout otherwise it wont update the total
        setTimeout(function () {
          $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-basket"></i> ' + json['total'] + '</span>');
        }, 100);

        if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
          location = 'index.php?route=checkout/cart';
        } else {
          $('#cart > ul').load('index.php?route=common/cart/info ul li');
        }
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
    });
  },
  'remove': function(key) {
    $.ajax({
      url: 'index.php?route=checkout/cart/remove',
      type: 'post',
      data: 'key=' + key,
      dataType: 'json',
      beforeSend: function() {
        $('#cart > button').button('loading');
      },
      complete: function() {
        $('#cart > button').button('reset');
      },
      success: function(json) {
        // Need to set timeout otherwise it wont update the total
        setTimeout(function () {
          $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-basket"></i> ' + json['total'] + '</span>');
        }, 100);

        if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
          location = 'index.php?route=checkout/cart';
        } else {
          $('#cart > ul').load('index.php?route=common/cart/info ul li');
        }
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
    });
  }
}
var wishlist = {
  'add': function(product_id) {
    $.ajax({
      url: 'index.php?route=account/wishlist/add',
      type: 'post',
      data: 'product_id=' + product_id,
      dataType: 'json',
      success: function(json) {
        $('.alert-dismissible').remove();

        if (json['redirect']) {
          location = json['redirect'];
        }

        if (json['success']) {
          $('#content').parent().before('<div class="container alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
        }

        $('#wishlist-total span').html(json['total']);
        $('#wishlist-total').attr('title', json['total']);

        $('html, body').animate({ scrollTop: 0 }, 'slow');
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
    });
  },
  'remove': function() {

  }
}
var compare = {
  'add': function(product_id) {
    $.ajax({
      url: 'index.php?route=product/compare/add',
      type: 'post',
      data: 'product_id=' + product_id,
      dataType: 'json',
      success: function(json) {
        $('.alert-dismissible').remove();

        if (json['success']) {
          $('#content').parent().before('<div class="container alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

          $('#compare-total').html(json['total']);

          $('html, body').animate({ scrollTop: 0 }, 'slow');
        }
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
    });
  },
  'remove': function() {

  }
}
--></script>
{{ footer }} 
