<?php
$this->load->view("top_application");
//$mediaRes = $media_res;
//$overall_rating_product = product_overall_rating($res['products_id'], 'product');
//echo 'abc';
//exit;
//trace($this->input->get_post());
$QryStringArr = array();  // To store all Query Variables so to move to other view;
$QryStringArr = array_unique($QryStringArr);
if (isset($this->meta_info['entity_id']) && $this->meta_info['entity_id'] != '') {
  $QryStringArr['category_id'] = $this->meta_info['entity_id'];
}
if ($this->input->get_post('size') != '') {
  $QryStringArr['size'] = implode(',', $this->input->get_post('size'));
}
if ($this->input->get_post('categoryId') != '') {
  $QryStringArr['categoryId'] = implode(',', $this->input->get_post('categoryId'));
}
if ($this->input->get_post('price') != '') {
  $QryStringArr['price'] = $this->input->get_post('price');
}
if ($this->input->get_post('color') != '') {
  $QryStringArr['color'] = implode(',', $this->input->get_post('color'));
}
if ($this->input->get_post('keyword') != '') {
  $QryStringArr['keyword'] = $this->input->get_post('keyword');
}
if ($this->input->get_post('product_for') != '') {
  $QryStringArr['product_for'] = $this->input->get_post('product_for');
}
if ($this->input->get_post('sort') != '') {
  $QryStringArr['sort'] = $this->input->get_post('sort');
}
?>
<div class="breadcrumb">
  <div class="container">
    <div class="breadcrumb-inner">
      <ul class="list-inline list-unstyled">
        <li><a href="<?php echo site_url(); ?>">Home</a></li>
        <li class='active'><?php echo $heading_title; ?></li>
      </ul>
    </div>
    <!-- /.breadcrumb-inner -->
  </div>
  <!-- /.container -->
</div>
<!-- /.breadcrumb -->
<div class="body-content outer-top-xs">
  <div class='container'>
    <div class='row'>
      <div class='col-md-3 sidebar'>
        <!-- ================================== TOP NAVIGATION ================================== -->
        <!-- /.side-menu -->
        <!-- ================================== TOP NAVIGATION : END ================================== -->
        <div class="sidebar-module-container">
          <div class="sidebar-filter">
            <!-- ============================================== SIDEBAR CATEGORY ============================================== -->
            <div class="sidebar-widget wow fadeInUp">
              <h3 class="section-title">Category</h3>
              <div class="sidebar-widget-body">
                <div class="accordion">
                  <?php
                  $resGro = $this->db->query("SELECT * FROM wps_categories WHERE status = '1' AND parent_id = '0'")->result_array();

                  foreach ($resGro as $sideval) {

                    //trace($val);
                    ?>
                    <div class="accordion-group">
                      <div class="accordion-heading"> <a href="<?php echo site_url($sideval['friendly_url']); ?>" title="<?php echo $sideval['category_name']; ?>"> <?php echo $sideval['category_name']; ?> </a> </div>
                    </div>
                    <?php
                  }
                  ?>
                  <!-- /.accordion-group -->

                  <!--div class="accordion-group">
                    <div class="accordion-heading"> <a href="#collapseFour" data-toggle="collapse" class="accordion-toggle collapsed">Furniture </a> </div>
                    
                    <div class="accordion-body collapse" id="collapseFour" style="height: 0px;">
                      <div class="accordion-inner">
                        <ul>
                          <li><strong>Furniture</strong></li>
                          <li><a href="#">Bed</a></li>
                          <li><a href="#">Couch</a></li>
                          <li><a href="#">Dining Room Table</a></li>
                          <li><a href="#">Center table</a></li>
                          <li><a href="#">Cabinets</a></li>
                          <li><a href="#">Television stand</a></li>
                          <li><a href="#">Other Home Articles</a></li>
                          <li><strong>Office Furniture</strong></li>
                          <li><a href="#">Office desk</a></li>
                          <li><a href="#">Office chair</a></li>
                          <li><a href="#">Other Office Supplies</a></li>
                          <li><strong>Children Furniture</strong></li>
                          <li><a href="#">Full Set Of Bed</a></li>
                          <li><a href="#">Study Table Wardrobe</a></li>
                          <li><a href="#">Chair</a></li>
                          <li><a href="#">Side Benches</a></li>
                          <li><a href="#">Beautiful Bunk Beds</a></li>
                          <li><a href="#">Colourful Book Shelves</a></li>
                          <li><a href="#">Study Table</a></li>
                        </ul>
                      </div>
                      
                    </div>
                    
                  </div-->

                  <!-- /.accordion-group -->
                </div>
                <!-- /.accordion -->
              </div>
              <!-- /.sidebar-widget-body -->
            </div>
            <!-- /.sidebar-widget -->
            <!-- ============================================== SIDEBAR CATEGORY : END ============================================== -->
            <!-- ============================================== PRICE SILDER============================================== -->
            <?php
            if ($this->input->get_post('price')) {
              $pr = explode(',', $this->input->get_post('price'));
              $minp = $pr[0];
              $maxp = $pr[1];
            } else {
              $minp = 50;
              $maxp = 10000;
            }
            ?>
            <form id="searchForm" action="" method="POST">
              <div class="sidebar-widget wow fadeInUp">
                <div class="widget-header">
                  <h4 class="widget-title">Price Slider</h4>
                </div>
                <div class="sidebar-widget-body m-t-10">
                  <div class="price-range-holder"> <span class="min-max" <?php echo $minp; ?>> <span class="pull-left">MZN <?php echo $minp; ?></span> <span class="pull-right" <?php echo $maxp; ?>>MZN <?php echo $maxp; ?></span> </span>
                    
                    <input type="text" name="price" class="price-slider" value="<?php echo $this->input->get_post('price'); ?>" >
                  </div>
                  <!-- /.price-range-holder -->
                  <!--  <a href="#" class="lnk btn btn-primary">Show Now</a>--> </div>
                <!-- /.sidebar-widget-body -->
              </div>
            </form>
            <?php
            if (is_array($testimonial) && !empty($testimonial)) {
              ?>
              <div class="sidebar-widget  wow fadeInUp outer-top-vs ">
                <div id="advertisement" class="advertisement">
                  <!-- /.item -->
                  <?php
                  foreach ($testimonial as $tk => $tVal) {
                    ?>
                    <div class="item">
                      <div class="avatar"><img src="<?php echo get_image('testimonial', $tVal['testimonial_image'], '110', '110', 'R'); ?>" alt="<?php echo $tVal['poster_name']; ?>" title="<?php echo $tVal['poster_name']; ?>"></div>
                      <div class="testimonials"><em>"</em> <?php echo $tVal['testimonial_description']; ?><em>"</em></div>
                      <div class="clients_author"><?php echo $tVal['poster_name']; ?>
                        <!--<span>Abc Company</span>-->
                      </div>
                      <!-- /.container-fluid -->
                    </div>
                    <?php
                  }
                  ?>
                  <!-- /.item end-->
                </div>
                <!-- /.owl-carousel -->
              </div>
              <?php
            }
            ?>
            <!-- ============================================== Testimonials: END ============================================== -->
            <div class="home-banner"> <img src="<?php echo theme_url(); ?>images/banners/offer-banner.jpg" alt="Image"> </div>
          </div>
          <!-- /.sidebar-filter -->
        </div>
        <div class="sidebar-widget newsletter wow fadeInUp outer-bottom-small outer-top-vs">
          <h3 class="section-title">Newsletters</h3>
          <div class="sidebar-widget-body outer-top-xs">
            <p>Sign Up for Our Newsletter!</p>
            <form action="" id="newsletter" method="post">
              <div class="form-group">
                <label class="sr-only" for="exampleInputEmail1">Email address</label>
                <input placeholder="Type Your Email ID" required class="form-control" id="emailid" autocomplete="off" type="email">
              </div>

              <button class="btn btn-primary">Subscribe</button>

            </form>
          </div>
          <!-- /.sidebar-widget-body -->
        </div>
        <!-- /.sidebar-module-container -->
      </div>
      <!-- /.sidebar -->
      <div class='col-md-9'>
        <!-- ========================================== SECTION � HERO ========================================= -->
        <div id="category" class="category-carousel hidden-xs">
          <div class="item">
            <div class="image"> <img src="<?php echo theme_url(); ?>images/banners/cat-banner-1.jpg" alt="" class="img-responsive"> </div>
            <div class="container-fluid">
              <div class="caption vertical-top text-left">
                <!-- <div class="big-text"> Big Sale </div>

                <div class="excerpt hidden-sm hidden-md"> Save up to 49% off </div>

                <div class="excerpt-normal hidden-sm hidden-md"> Lorem ipsum dolor sit amet, consectetur adipiscing elit </div>-->
              </div>
              <!-- /.caption -->
            </div>
            <!-- /.container-fluid -->
          </div>
        </div>
        <div class="clearfix filters-container m-t-10">
          <div class="row">
            <div class="col col-sm-6 col-md-2">
              <div class="filter-tabs">
                <ul id="filter-tabs" class="nav nav-tabs nav-tab-box nav-tab-fa-icon">
                  <li class="active"> <a data-toggle="tab" href="#grid-container"><i class="icon fa fa-th-large"></i>Grid</a> </li>
                  <li><a data-toggle="tab" href="#list-container"><i class="icon fa fa-th-list"></i>List</a></li>
                </ul>
              </div>
              <!-- /.filter-tabs -->
            </div>
            <!-- /.col -->
            <div class="col col-sm-12 col-md-6">
              <div class="col col-sm-3 col-md-6 no-padding">

                <div class="lbl-cnt" style="width:300px;"> <span class="lbl">Sort by</span>
                  <div class="fld inline" >
                    <div class="dropdown dropdown-small dropdown-med dropdown-white inline">

                      <!-- <ul role="menu" class="dropdown-menu">
                         <li role="presentation"><a href="#">position</a></li>
                         <li role="presentation"><a href="#">Price:Lowest first</a></li>
                         <li role="presentation"><a href="#">Price:HIghest first</a></li>
                         <li role="presentation"><a href="#">Product Name:A to Z</a></li>
                       </ul>-->
                      <form name="searchFilter" action="" method="post">

                        <select name="sort" class="dropdown dropdown-small dropdown-med dropdown-white inline" onchange="this.form.submit();" style="height:30px">

                          <option>---Sort By---</option>

                          <option value="1" <?php echo ($this->input->get_post('sort') == '1' || $this->input->get_post('sort_by') == '1') ? 'selected' : ''; ?>>Popular</option>

                          <option value="2" <?php echo ($this->input->get_post('sort') == '2' || $this->input->get_post('sort_by') == '2') ? 'selected' : ''; ?>>New Arrival</option>

                          <option value="3" <?php echo ($this->input->get_post('sort') == '3' || $this->input->get_post('sort_by') == '3') ? 'selected' : ''; ?>>Newest</option>

                          <option value="4" <?php echo ($this->input->get_post('sort') == '4' || $this->input->get_post('sort_by') == '4') ? 'selected' : ''; ?>>Price Low - High</option>

                          <option value="5" <?php echo ($this->input->get_post('sort') == '5' || $this->input->get_post('sort_by') == '5') ? 'selected' : ''; ?>>Price High - Low</option>

                        </select>
                      </form>
                    </div>
                  </div>
                  <!-- /.fld -->
                </div>
                <!-- /.lbl-cnt -->
              </div>

              <!-- /.col -->
            </div>

            <!-- /.col -->
          </div>
          <!-- /.row -->
        </div>
        <?php
        echo error_message();
        echo validation_message();
        if (is_array($res) && !empty($res)) {
          ?>
          <div class="search-result-container ">
            <div id="myTabContent" class="tab-content category-list">
              <div class="tab-pane active " id="grid-container">
                <div class="category-product">
                  <div class="row">
                    <?php
                    $ix = 1;
                    foreach ($res as $val) {
                      $link_url = base_url($val['friendly_url']);
                      $productStock = product_stock($val['products_id']);
                      $overall_rating_product = product_overall_rating($val['products_id'], 'product');
                      ?>
                      <div class="col-sm-6 col-md-4 wow fadeInUp">
                        <div class="products">
                          <div class="product">
                            <div class="product-image">
                              <div class="image"> <a href="<?php echo $link_url; ?>"><img  src="<?php echo get_image('product_images', $val['media'], '349', '349', 'AR'); ?>" alt="<?php echo $val['product_name']; ?>" title="<?php echo $val['product_name']; ?>"></a> </div>
                              <!-- /.image -->
                              <div class="tag new"><span>new</span></div>
                            </div>
                            <!-- /.product-image -->
                            <div class="product-info text-left">
                              <h3 class="name"><a href="<?php echo $link_url; ?>"><?php echo $val['product_name']; ?></a></h3>
                              <?php /* ?><a href="<?php echo $link_url; ?>"><div class="rating rateit-small"></div></a><?php */ ?>
                              <div class="rating "><?php echo rating_html($overall_rating_product, 5); ?></div>
                              <div class="description"></div>
                              <div class="product-price"> 
                                <?php
                                if ($val['product_discounted_price'] > 0) {
                                  ?>
                                  <span class="price"><?php echo display_price($val['product_discounted_price']); ?> </span> <span class="price-before-discount"><?php echo display_price($val['product_price']); ?></span>
                                  <?php
                                } else {
                                  ?>
                                  <span class="price"><?php echo display_price($val['product_price']); ?> </span>
                                  <?php
                                }
                                ?>
                              </div>
                              <!-- /.product-price -->
                            </div>
                            <!-- /.product-info -->
                            <div class="cart clearfix animate-effect">
                              <div class="action">
                                <ul class="list-unstyled">
                                  <li class="add-cart-button btn-group"> <a href="<?php echo $link_url; ?>">
                                      <button data-toggle="tooltip" class="btn btn-primary icon" type="button" title="Add Cart"> <i class="fa fa-shopping-cart"></i> </button>
                                      <button class="btn btn-primary cart-btn" type="button">Add to cart</button>
                                  </li>
                                  </a>
                                  <li class="lnk wishlist"> <a data-toggle="tooltip" class="add-to-cart" href="<?php echo site_url('cart/add_to_wishlist/' . $val['products_id']); ?>" title="Wishlist"> <i class="icon fa fa-heart"></i> </a> </li>
                                  <!--<li class="lnk"> <a data-toggle="tooltip" class="add-to-cart" href="" title="Compare"> <i class="fa fa-signal" aria-hidden="true"></i> </a> </li>-->
                                </ul>
                              </div>
                              <!-- /.action -->
                            </div>
                            <!-- /.cart -->
                          </div>
                          <!-- /.product -->
                        </div>
                        <!-- /.products -->
                      </div>
                      <?php
                    }
                    ?>
                    <!-- /.item -->
                  </div>
                  <!-- /.row -->
                </div>
                <!-- /.category-product -->
              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane "  id="list-container">
                <div class="category-product">
                  <?php
                  $ix = 1;
                  foreach ($res as $val) {
                    $link_url = base_url($val['friendly_url']);
                    $productStock = product_stock($val['products_id']);
                    ?>
                    <div class="category-product-inner wow fadeInUp">
                      <div class="products">
                        <div class="product-list product">
                          <div class="row product-list-row">
                            <div class="col col-sm-4 col-lg-4">
                              <div class="product-image">
                                <div class="image"> <img src="<?php echo get_image('product_images', $val['media'], '249', '249', 'R'); ?>" alt="<?php echo $val['product_name']; ?>" title="<?php echo $val['product_name']; ?>"> </div>
                              </div>
                              <!-- /.product-image -->
                            </div>
                            <!-- /.col -->
                            <div class="col col-sm-8 col-lg-8">
                              <div class="product-info">
                                <h3 class="name"><a href="<?php echo $link_url; ?>"><?php echo $val['product_name']; ?></a></h3>
                                <div class="rating rateit-small"></div>
                                <div class="product-price"> <<?php
                                  if ($val['product_discounted_price'] > 0) {
                                    ?>
                                    <span class="price"><?php echo display_price($val['product_discounted_price']); ?> </span> <span class="price-before-discount"><?php echo display_price($val['product_price']); ?></span>
                                    <?php
                                  } else {
                                    ?>
                                    <span class="price"><?php echo display_price($val['product_price']); ?> </span>
                                    <?php
                                  }
                                  ?> </div>
                                <!-- /.product-price -->
                                <div class="description m-t-10"><?php echo char_limiter($val['products_description'], 300); ?>.</div>
                                <div class="cart clearfix animate-effect">
                                  <div class="action">
                                    <ul class="list-unstyled">
                                      <li class="add-cart-button btn-group">
                                        <button class="btn btn-primary icon" data-toggle="dropdown" type="button"> <i class="fa fa-shopping-cart"></i> </button>
                                        <div class="btn btn-primary cart-btn"><a style="color: #fff;"  href="<?php echo $link_url; ?>">Add to cart</a></div>
                                      </li>
                                      <li class="lnk wishlist"> <a class="add-to-cart" href="<?php echo site_url('cart/add_to_wishlist/' . $val['products_id']); ?>" title="Wishlist"> <i class="icon fa fa-heart"></i> </a> </li>
                                      <!--<li class="lnk"> <a class="add-to-cart" href="detail.html" title="Compare"> <i class="fa fa-signal"></i> </a> </li>-->
                                    </ul>
                                  </div>
                                  <!-- /.action -->
                                </div>
                                <!-- /.cart -->
                              </div>
                              <!-- /.product-info -->
                            </div>
                            <!-- /.col -->
                          </div>
                          <!-- /.product-list-row -->
                          <div class="tag new"><span>new</span></div>
                        </div>
                        <!-- /.product-list -->
                      </div>
                      <!-- /.products -->
                    </div>
                    <?php
                  }
                  ?>
                  <!-- /.category-product-inner -->
                </div>
                <!-- /.category-product -->
              </div>
              <!-- /.tab-pane #list-container -->
            </div>
            <!-- /.tab-content -->

          </div>
          <?php
        } else {
          ?>
          <h1 class="page-heading">
            <span class="page-heading-title"><?php echo $heading_title; ?></span>
          </h1>
          <div class="alert alert-danger" role="alert" style="margin-top: 10px !important;">
            <strong>Oh snap!</strong> No product(s) found.
          </div>
          <?php
        }
        ?>
        <!-- /.search-result-container -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
    <!-- ============================================== BRANDS CAROUSEL ============================================== -->
    <?php getBrand(); ?>
    <!-- /.logo-slider -->
    <!-- ============================================== BRANDS CAROUSEL : END ============================================== -->
  </div>
  <!-- /.container -->
</div>
<!-- /.body-content -->
<script type="text/javascript">
  var page = 1;
  var triggeredPaging = 0;
  $(window).scroll(function () {
    $('#loadingdiv').hide();

    var scrollTop = $(window).scrollTop();

    var scrollBottom = (scrollTop + $(window).height());

    var containerTop = $('#prodListingContainer').offset().top;

    var containerHeight = $('#prodListingContainer').height();

    var containerBottom = Math.floor(containerTop + containerHeight);

    var scrollBuffer = 0;

    if ((containerBottom - scrollBuffer) <= scrollBottom) {

      page = $('.listpager').length;

      var queryString = '?stOffSet=' + page;

<?php
if (count($QryStringArr)) {

  foreach ($QryStringArr as $qrykey => $qryval) {
    ?>

          queryString += "&<?php echo $qrykey; ?>=<?php echo $qryval; ?>";

    <?php
  }
}
?>

      var actual_count = <?php echo $total_rows; ?>;



      if (!triggeredPaging && page < actual_count) {

        triggeredPaging = 1;

        $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>products/ajax_load_product_view" + queryString,
          error: function (res) {

            //alert('Error');

            triggeredPaging = 0;

            $('#loadingdiv').hide();

            //console.log(arguments);

          },
          beforeSend: function (jqXHR, settings) {

            $('#loadingdiv').show();



          },
          success: function (res) {

            $('#loadingdiv').hide();

            $("#prodListingContainer").append(res);

            triggeredPaging = 0;

            //console.log(res);

            $('.listpager').fadeTo(1000, 0.5, function () {

              $(this).fadeTo(1000, 1.0);

            });

          }

        });

      }

    }

  });

</script>
<?php $this->load->view("bottom_application"); ?>
