/** * generates the brand's filer list * * @return void * @author Ankit Balyan - sf.ankit@gmail.com **/ function get_brandFilterList($array, $child = FALSE, $category = FALSE) { $str = ''; if (count($array)) { $str .= '<div class="panel panel-default">'; static $topBrandId = ''; if ($category) { $str .= '' . PHP_EOL; } elseif ($child) { $str .= '<div id="' . $topBrandId . '" class="panel-collapse collapse">'; $str .= '<div class="panel-body">'; $str .= '<ul>'; } else { $str .= ''; } foreach ($array as $item) { //$active = $CI->uri->segment(1) == $item['slug'] ?TRUE : FALSE; $active = null; if (isset($item['children']) && count($item['children'])) { $topBrandId = "topBrandId_" . $item['brand_id']; $str .= '<div class="panel-heading">' . PHP_EOL; $str .= '<h4 class="panel-title">' . PHP_EOL; $str .= '<a data-toggle="collapse" data-parent="#brandFilterAcorrdian" href="#' . $topBrandId . '">' . PHP_EOL; $str .= '<span class="badge pull-right"><i class="fa fa-plus"></i></span>' . PHP_EOL; $str .= $item['brand_name'] . '</a>' . PHP_EOL; $str .= '</h4>' . PHP_EOL; $str .= '</div>' . PHP_EOL; $str .= get_brandFilterList($item['children'], TRUE); } else { $str .= '<li><input type="checkbox" name="selecteBrandBox[]" id="brand_id_' . $item['brand_id'] . '" class="large" value="' . $item['brand_id'] . '"> <a href="">' . $item['brand_name'] . '</a></li>'; } } if ($category) { $str .= '' . PHP_EOL; } elseif ($child) { $str .= '</ul>'; $str .= '</div>'; $str .= '</div>'; } else { $str .= '' . PHP_EOL; } $str .= '</div>' . PHP_EOL; } return $str; }
/** * Outputs the HTML for this widget. * * @param array An array of standard parameters for widgets in this theme * @param array An array of settings for this widget instance * @return void Echoes it's output * @author Ankit Balyan - sf.ankit@gmail.com **/ function widget($args, $instance) { extract($args, EXTR_SKIP); extract($instance, EXTR_SKIP); $category_filter_title = apply_filters('widget_title', $category_filter_title); if (empty($category_filter_title)) { $category_filter_title = "Category"; } $brand_filter_title = apply_filters('widget_title', $brand_filter_title); if (empty($brand_filter_title)) { $brand_filter_title = "Brand"; } $before_title = "<h2>"; $after_title = "</h2>"; echo $before_widget; // // Widget display logic goes here // ?> <form action="" method="POST" name="productFilterForm" id="productFilterForm"> <?php $brands = get_nested(); ?> <?php if (count($brands)) { echo $before_title; echo $brand_filter_title; // Can set this with a widget option, or omit altogether echo $after_title; echo $brandlistView = get_brandFilterList($brands); ?> <?php $categories = getCategories(); if (count($categories)) { echo $before_title; echo $category_filter_title; // Can set this with a widget option, or omit altogether echo $after_title; ?> <div class="panel-group category-products" id="categoryFilterAccordian"><!--category-productsr--> <?php foreach ($categories as $category) { ?> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <input type="checkbox" name="selectCategoryBox[]" id="category_id_<?php echo $category->category_id; ?> " value="<?php echo $category->category_id; ?> " class="large" > <a data-toggle="collapse" data-parent="#accordian" href="#sportswear" onclick ="submitFilter()"><?php echo $category->category_name; ?> </a> </h4> </div> </div> <?php } ?> </div> <?php } ?> <?php } ?> <div class="price-range"><!--price-range--> <?php echo $before_title; echo $price_filter_title; // Can set this with a widget option, or omit altogether echo $after_title; $maxprice = maxProductPrice(); $minprice = minProductPrice(); ?> <div class="well"> <input type="text" class="span2" data-slider-min="<?php echo $minprice; ?> " data-slider-max="<?php echo $maxprice; ?> " data-slider-step="5" data-slider-value="[<?php echo $minprice; ?> ,<?php echo $maxprice; ?> ]" id="sl2" ><br /> <span><span><i class="fa fa-inr"></i></span></span><b> <?php echo money_format('%!.0i', $minprice); ?> </b><b class="pull-right"><span><span><i class="fa fa-inr"></i></span></span> <?php echo money_format('%!.0i', $maxprice); ?> </b> </div> </div><!--/price-range--> </form> <script type="text/javascript"> jQuery(document).on("click",'input[type="checkbox"]',function() { type = jQuery(this).attr('name'); if(type != 'selectCategoryBox[]') { brandFilter(); } else { categoryFilter(); } }); function brandFilter (argument) { var formData = new FormData(jQuery('#productFilterForm')[0]); data_slider_value = jQuery('.tooltip-inner').text(); formData.append("action",'product_filter'); formData.append("data_slider_value",data_slider_value); jQuery.ajax({ type: 'POST', url: ajaxurl, data: formData, cache: false, contentType: false, processData: false, beforeSend:function (argument) { // jQuery('.overlay').fadeIn('slow'); // jQuery('.response').fadeIn('slow').html("Processing..."); }, success: function(result) { //jQuery('.response').fadeIn('slow').html(result).delay(5000).fadeOut('slow'); //jQuery('.overlay').delay(5100).fadeOut('slow'); content = ''; jQuery.each(result.catelog, function(i,product){ content += '<div class="col-sm-4 eachProduct jscroll-next">'; content += '<div class="product-image-wrapper">'; content += '<div class="single-products">'; content += '<a href="/product/'+product.product_id+'">'; content += '<div class="productinfo text-center">'; content += '<img src="'+product.image_url+'" alt="" />'; content += '<h2>MRP '+product.product_price+'</h2>'; content += '<a href="/product/'+product.product_id+'">'+product.product_name+'<?php //echo $product->product_name ?> </a>'; content += '</div>'; content += '</a>'; content += '</div>'; content += '</div>'; content += '</div>'; }); jQuery("#product_list").empty(); jQuery('#product_list').html(content); //if(content !='') // { // jQuery("#product_list").empty(); // jQuery('#product_list').append(content); // } content = ''; jQuery.each(result.categories, function(i,category){ content += '<div class="panel panel-default">'; content += '<div class="panel-heading">'; content += '<h4 class="panel-title">'; content += '<input type="checkbox" name="selectCategoryBox[]" id="category_id_'+category.category_id+'" value="'+category.category_id+'" class="large">'; content += '<a data-toggle="collapse" data-parent="#accordian" onclick ="submitFilter()" href="#sportswear">'+category.category_name+'</a>'; content += '</h4>'; content += '</div>'; content += '</div>'; }); // if(content !='') // { // jQuery("#categoryFilterAccordian").empty(); // jQuery('#categoryFilterAccordian').html(content); // } jQuery("#categoryFilterAccordian").empty(); jQuery('#categoryFilterAccordian').html(content); jQuery('input[type="checkbox"]').checkbox(); loadMore (); } }); } function categoryFilter (argument) { var formData = new FormData(jQuery('#productFilterForm')[0]); data_slider_value = jQuery('.tooltip-inner').text(); formData.append("action",'product_filter'); formData.append("data_slider_value",data_slider_value); jQuery.ajax({ type: 'POST', url: ajaxurl, data: formData, cache: false, contentType: false, processData: false, beforeSend:function (argument) { // jQuery('.overlay').fadeIn('slow'); // jQuery('.response').fadeIn('slow').html("Processing..."); }, success: function(result) { //jQuery('.response').fadeIn('slow').html(result).delay(5000).fadeOut('slow'); //jQuery('.overlay').delay(5100).fadeOut('slow'); content = ''; jQuery.each(result.catelog, function(i,product){ content += '<div class="col-sm-4 eachProduct jscroll-next">'; content += '<div class="product-image-wrapper">'; content += '<div class="single-products">'; content += '<a href="/product/'+product.product_id+'">'; content += '<div class="productinfo text-center">'; content += '<img src="'+product.image_url+'" alt="" />'; content += '<h2>MRP '+product.product_price+'</h2>'; content += '<a href="/product/'+product.product_id+'">'+product.product_name+'<?php //echo $product->product_name ?> </a>'; content += '</div>'; content += '</a>'; content += '</div>'; content += '</div>'; content += '</div>'; }); jQuery("#product_list").empty(); jQuery('#product_list').html(content); jQuery('input[type="checkbox"]').checkbox(); loadMore (); } }); } </script> <?php echo $after_widget; }