Advanced AJAX Product Filters - Version 1.1.1

Version Description

  • Fix - most of the bugs for almost a month period
Download this release

Release Info

Developer dholovnia
Plugin Icon wp plugin Advanced AJAX Product Filters
Version 1.1.1
Comparing to
See all releases

Code changes from version 1.1.0.8 to 1.1.1

README.md CHANGED
@@ -5,7 +5,7 @@ Donate link: http://berocket.com
5
  Tags: filters, product filters, ajax product filters, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce ajax product filters, widget, plugin
6
  Requires at least: 4.0
7
  Tested up to: 4.2.2
8
- Stable tag: 1.1.0.7
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
5
  Tags: filters, product filters, ajax product filters, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce ajax product filters, widget, plugin
6
  Requires at least: 4.0
7
  Tested up to: 4.2.2
8
+ Stable tag: 1.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
css/widget.css CHANGED
@@ -160,7 +160,7 @@ span.product-size{
160
  text-align: right;
161
  }
162
 
163
- .berocket_aapf_widget li.slider span.slide{
164
  clear: both;
165
  height: auto;
166
  text-align: right;
@@ -172,6 +172,7 @@ span.product-size{
172
  border-radius: 0;
173
  height: 4px;
174
  padding: 0;
 
175
  }
176
 
177
  .berocket_filter_slider.ui-widget-content .ui-slider-range, .berocket_filter_price_slider.ui-widget-content .ui-slider-range{
@@ -186,7 +187,7 @@ span.product-size{
186
  top: -4px;
187
  }
188
 
189
- .berocket_aapf_widget li.slider span.slide{
190
  clear: both;
191
  height: auto;
192
  }
160
  text-align: right;
161
  }
162
 
163
+ .berocket_aapf_widget li.slider div.slide{
164
  clear: both;
165
  height: auto;
166
  text-align: right;
172
  border-radius: 0;
173
  height: 4px;
174
  padding: 0;
175
+ display: block;
176
  }
177
 
178
  .berocket_filter_slider.ui-widget-content .ui-slider-range, .berocket_filter_price_slider.ui-widget-content .ui-slider-range{
187
  top: -4px;
188
  }
189
 
190
+ .berocket_aapf_widget li.slider div.slide{
191
  clear: both;
192
  height: auto;
193
  }
includes/functions.php CHANGED
@@ -95,11 +95,11 @@ if( ! function_exists( 'br_parse_order_by' ) ){
95
  $args['meta_key'] = 'total_sales';
96
 
97
  // Sorting handled later though a hook
98
- add_filter( 'posts_clauses', array( 'WC_Query', 'order_by_popularity_post_clauses' ) );
99
  break;
100
  case 'rating' :
101
  // Sorting handled later though a hook
102
- add_filter( 'posts_clauses', array( 'WC_Query', 'order_by_rating_post_clauses' ) );
103
  break;
104
  case 'title' :
105
  $args['orderby'] = 'title';
@@ -121,6 +121,7 @@ if( ! function_exists( 'br_aapf_args_parser' ) ){
121
  function br_aapf_args_parser( $args = array() ) {
122
  $attributes_terms = $tax_query = array();
123
  $attributes = apply_filters( 'berocket_aapf_listener_get_attributes', br_aapf_get_attributes() );
 
124
 
125
  if ( @$attributes ) {
126
  foreach ( $attributes as $k => $v ) {
@@ -135,7 +136,10 @@ if( ! function_exists( 'br_aapf_args_parser' ) ){
135
 
136
  if ( @$_POST['terms'] ) {
137
  foreach ( $_POST['terms'] as $t ) {
138
- $taxonomies[ $t[0] ][] = $attributes_terms[ $t[0] ][ $t[1] ];
 
 
 
139
  $taxonomies_operator[ $t[0] ] = $t[2];
140
  }
141
  }
95
  $args['meta_key'] = 'total_sales';
96
 
97
  // Sorting handled later though a hook
98
+ add_filter( 'posts_clauses', array( 'BeRocket_AAPF', 'order_by_popularity_post_clauses' ) );
99
  break;
100
  case 'rating' :
101
  // Sorting handled later though a hook
102
+ add_filter( 'posts_clauses', array( 'BeRocket_AAPF', 'order_by_rating_post_clauses' ) );
103
  break;
104
  case 'title' :
105
  $args['orderby'] = 'title';
121
  function br_aapf_args_parser( $args = array() ) {
122
  $attributes_terms = $tax_query = array();
123
  $attributes = apply_filters( 'berocket_aapf_listener_get_attributes', br_aapf_get_attributes() );
124
+ $taxonomies = array();
125
 
126
  if ( @$attributes ) {
127
  foreach ( $attributes as $k => $v ) {
136
 
137
  if ( @$_POST['terms'] ) {
138
  foreach ( $_POST['terms'] as $t ) {
139
+ if( !isset($taxonomies[ $t[0] ]) ){
140
+ $taxonomies[ $t[0] ] = array();
141
+ }
142
+ $taxonomies[ $t[0] ][] = @ $attributes_terms[ $t[0] ][ $t[1] ];
143
  $taxonomies_operator[ $t[0] ] = $t[2];
144
  }
145
  }
includes/widget.php CHANGED
@@ -44,15 +44,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
44
  $br_options = apply_filters( 'berocket_aapf_listener_br_options', get_option('br_filters_options') );
45
  if( @ $br_options['filters_turn_off'] || is_product() ) return false;
46
 
47
- global $wp_query, $wp;
48
-
49
- wp_register_style( 'berocket_aapf_widget-style', plugins_url( '../css/widget.css', __FILE__ ), array(), BeRocket_AJAX_filters_version );
50
- wp_enqueue_style( 'berocket_aapf_widget-style' );
51
-
52
- /* custom scrollbar */
53
- wp_enqueue_script( 'berocket_aapf_widget-scroll-script', plugins_url( '../js/scrollbar/Scrollbar.concat.min.js', __FILE__ ), array( 'jquery' ), BeRocket_AJAX_filters_version );
54
- wp_register_style( 'berocket_aapf_widget-scroll-style', plugins_url( '../css/scrollbar/Scrollbar.min.css', __FILE__ ), array(), BeRocket_AJAX_filters_version );
55
- wp_enqueue_style( 'berocket_aapf_widget-scroll-style' );
56
 
57
  /* main scripts */
58
  wp_enqueue_script( 'jquery-ui-core' );
@@ -73,10 +65,18 @@ class BeRocket_AAPF_Widget extends WP_Widget {
73
  $post_temrs = @ json_encode( $_POST['terms'] );
74
  }
75
 
 
 
 
 
 
 
76
  wp_localize_script(
77
  'berocket_aapf_widget-script',
78
  'the_ajax_script',
79
  array(
 
 
80
  'current_page_url' => preg_replace( "~paged?/[0-9]+/?~", "", home_url( $wp->request ) ),
81
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
82
  'product_cat' => $wp_query_product_cat,
@@ -263,7 +263,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
263
  set_query_var( 'text_before_price', @ $text_before_price );
264
  set_query_var( 'text_after_price', @ $text_after_price );
265
  }
266
- set_query_var( 'first_page_jump', $first_page_jump );
267
 
268
  br_get_template_part( $type );
269
 
@@ -484,14 +484,16 @@ class BeRocket_AAPF_Widget extends WP_Widget {
484
  add_filter( 'woocommerce_pagination_args', array( __CLASS__, 'pagination_args' ) );
485
 
486
  $args = apply_filters( 'berocket_aapf_listener_wp_query_args', array() );
487
-
 
 
 
488
  $woocommerce_hide_out_of_stock_items = BeRocket_AAPF_Widget::woocommerce_hide_out_of_stock_items();
489
  if( $woocommerce_hide_out_of_stock_items == 'yes' ) {
490
  $args['post__in'] = BeRocket_AAPF::remove_out_of_stock( $args['post__in'] );
491
- } else {
492
- $args['post__in'] = array();
493
  }
494
-
 
495
  $args['post__in'] = BeRocket_AAPF::limits_filter( $args['post__in'] );
496
  $args['post__in'] = BeRocket_AAPF::price_filter( $args['post__in'] );
497
  $args['post_status'] = 'publish';
@@ -563,6 +565,10 @@ class BeRocket_AAPF_Widget extends WP_Widget {
563
  echo apply_filters( 'berocket_aapf_listener_no_products_message', "<p class='no-products woocommerce-info" . ( ( $br_options['no_products_class'] ) ? ' '.$br_options['no_products_class'] : '' ) . "'>" . $br_options['no_products_message'] . "</p>" );
564
  $_RESPONSE['no_products'] = ob_get_contents();
565
  ob_end_clean();
 
 
 
 
566
  }
567
  echo json_encode( $_RESPONSE );
568
 
@@ -612,7 +618,7 @@ class BeRocket_AAPF_Widget extends WP_Widget {
612
 
613
  $pagenum = (int) $pagenum;
614
 
615
- $request = remove_query_arg( 'paged', preg_replace( "~".home_url()."~", "", $_POST['location'] ) );
616
 
617
  $home_root = parse_url(home_url());
618
  $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
44
  $br_options = apply_filters( 'berocket_aapf_listener_br_options', get_option('br_filters_options') );
45
  if( @ $br_options['filters_turn_off'] || is_product() ) return false;
46
 
47
+ global $wp_query, $wp, $sitepress;
 
 
 
 
 
 
 
 
48
 
49
  /* main scripts */
50
  wp_enqueue_script( 'jquery-ui-core' );
65
  $post_temrs = @ json_encode( $_POST['terms'] );
66
  }
67
 
68
+ if ( method_exists($sitepress, 'get_current_language') ) {
69
+ $current_language = $sitepress->get_current_language();
70
+ } else {
71
+ $current_language = '';
72
+ }
73
+
74
  wp_localize_script(
75
  'berocket_aapf_widget-script',
76
  'the_ajax_script',
77
  array(
78
+ 'version' => BeRocket_AJAX_filters_version,
79
+ 'current_language' => $current_language,
80
  'current_page_url' => preg_replace( "~paged?/[0-9]+/?~", "", home_url( $wp->request ) ),
81
  'ajaxurl' => admin_url( 'admin-ajax.php' ),
82
  'product_cat' => $wp_query_product_cat,
263
  set_query_var( 'text_before_price', @ $text_before_price );
264
  set_query_var( 'text_after_price', @ $text_after_price );
265
  }
266
+ set_query_var( 'first_page_jump', @ $first_page_jump );
267
 
268
  br_get_template_part( $type );
269
 
484
  add_filter( 'woocommerce_pagination_args', array( __CLASS__, 'pagination_args' ) );
485
 
486
  $args = apply_filters( 'berocket_aapf_listener_wp_query_args', array() );
487
+
488
+ if( ! isset($args['post__in']) ) {
489
+ $args['post__in'] = array();
490
+ }
491
  $woocommerce_hide_out_of_stock_items = BeRocket_AAPF_Widget::woocommerce_hide_out_of_stock_items();
492
  if( $woocommerce_hide_out_of_stock_items == 'yes' ) {
493
  $args['post__in'] = BeRocket_AAPF::remove_out_of_stock( $args['post__in'] );
 
 
494
  }
495
+ $args['post__in'] = BeRocket_AAPF::remove_hidden( $args['post__in'] );
496
+
497
  $args['post__in'] = BeRocket_AAPF::limits_filter( $args['post__in'] );
498
  $args['post__in'] = BeRocket_AAPF::price_filter( $args['post__in'] );
499
  $args['post_status'] = 'publish';
565
  echo apply_filters( 'berocket_aapf_listener_no_products_message', "<p class='no-products woocommerce-info" . ( ( $br_options['no_products_class'] ) ? ' '.$br_options['no_products_class'] : '' ) . "'>" . $br_options['no_products_message'] . "</p>" );
566
  $_RESPONSE['no_products'] = ob_get_contents();
567
  ob_end_clean();
568
+ } else {
569
+ $_RESPONSE['products'] = str_replace( 'explode=explode#038;', '', $_RESPONSE['products'] );
570
+ $_RESPONSE['products'] = str_replace( '&#038;explode=explode', '', $_RESPONSE['products'] );
571
+ $_RESPONSE['products'] = str_replace( '?explode=explode', '', $_RESPONSE['products'] );
572
  }
573
  echo json_encode( $_RESPONSE );
574
 
618
 
619
  $pagenum = (int) $pagenum;
620
 
621
+ $request = remove_query_arg( 'paged', preg_replace( "~".home_url()."~", "", @$_POST['location'] ) );
622
 
623
  $home_root = parse_url(home_url());
624
  $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
js/widget.min.js CHANGED
@@ -1,5 +1,4 @@
1
  /* packer link http://dean.edwards.name/packer/ */
2
-
3
  (function ($){
4
  $(document).ready(function (){
5
 
@@ -148,7 +147,7 @@
148
  }
149
  }
150
 
151
- function updateProducts( $force ){
152
  if ( typeof $force == 'undefined' ) $force = false;
153
  // if we have update_button on the page we must wait for it to be clicked
154
  if ( ! $force && berocket_aapf_widget_wait_for_button ) return false;
@@ -163,6 +162,7 @@
163
  update_selected_area();
164
 
165
  args = {
 
166
  terms: berocket_aapf_widget_product_filters,
167
  price: berocket_aapf_widget_product_price_limit,
168
  limits: berocket_aapf_widget_product_limits,
@@ -225,18 +225,20 @@
225
  url = the_ajax_script.ajaxurl;
226
  }
227
  if(the_ajax_script.ajax_request_load) {
228
- args.terms = '';
229
- args.price = '';
230
- args.limits = '';
231
- args.product_cat = '';
232
- args.action = '';
233
- args.orderby = '';
234
- args.orderby = '';
235
  }
236
- $.post(url, args, function (data) {
237
  $('.woocommerce-result-count').remove();
238
  $('.woocommerce-pagination').remove();
239
  $('form.woocommerce-ordering').remove();
 
 
240
 
241
  // call user func on_update
242
  if( the_ajax_script.user_func != null )
1
  /* packer link http://dean.edwards.name/packer/ */
 
2
  (function ($){
3
  $(document).ready(function (){
4
 
147
  }
148
  }
149
 
150
+ function updateProducts ( $force ){
151
  if ( typeof $force == 'undefined' ) $force = false;
152
  // if we have update_button on the page we must wait for it to be clicked
153
  if ( ! $force && berocket_aapf_widget_wait_for_button ) return false;
162
  update_selected_area();
163
 
164
  args = {
165
+ current_language: the_ajax_script.current_language,
166
  terms: berocket_aapf_widget_product_filters,
167
  price: berocket_aapf_widget_product_price_limit,
168
  limits: berocket_aapf_widget_product_limits,
225
  url = the_ajax_script.ajaxurl;
226
  }
227
  if(the_ajax_script.ajax_request_load) {
228
+ new_args = {
229
+ location: args.location
230
+ };
231
+ }
232
+ else
233
+ {
234
+ new_args = args;
235
  }
236
+ $.post(url, new_args, function (data) {
237
  $('.woocommerce-result-count').remove();
238
  $('.woocommerce-pagination').remove();
239
  $('form.woocommerce-ordering').remove();
240
+ $('#content .berocket_lgv_widget').remove();
241
+ $('#content .br_lgv_product_count_block').remove();
242
 
243
  // call user func on_update
244
  if( the_ajax_script.user_func != null )
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: http://berocket.com
5
  Tags: filters, product filters, ajax product filters, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce ajax product filters, widget, plugin
6
  Requires at least: 4.0
7
  Tested up to: 4.2.2
8
- Stable tag: 1.1.0.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -139,6 +139,9 @@ http://woocommerce-product-filter.berocket.com
139
 
140
  == Changelog ==
141
 
 
 
 
142
  = 1.1.0.8 =
143
  * Fix - removing PHP 5.5 code
144
 
5
  Tags: filters, product filters, ajax product filters, advanced product filters, woocommerce filters, woocommerce product filters, woocommerce ajax product filters, widget, plugin
6
  Requires at least: 4.0
7
  Tested up to: 4.2.2
8
+ Stable tag: 1.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
139
 
140
  == Changelog ==
141
 
142
+ = 1.1.1 =
143
+ * Fix - most of the bugs for almost a month period
144
+
145
  = 1.1.0.8 =
146
  * Fix - removing PHP 5.5 code
147
 
templates/admin-settings.php CHANGED
@@ -93,7 +93,7 @@
93
  <th scope="row"><?php _e('Template ajax load fix', BeRocket_AJAX_domain) ?></th>
94
  <td>
95
  <input name="br_filters_options[ajax_request_load]" type='checkbox' value='1' <?php if( @$options['ajax_request_load'] ) echo "checked='checked'";?>/>
96
- <span style="color:#666666;margin-left:2px;"><?php _e('Use all plugins on ajax load(can slow down products loading)', BeRocket_AJAX_domain) ?></span>
97
  </td>
98
  </tr>
99
  </table>
93
  <th scope="row"><?php _e('Template ajax load fix', BeRocket_AJAX_domain) ?></th>
94
  <td>
95
  <input name="br_filters_options[ajax_request_load]" type='checkbox' value='1' <?php if( @$options['ajax_request_load'] ) echo "checked='checked'";?>/>
96
+ <span style="color:#666666;margin-left:2px;"><?php _e('Use all plugins on ajax load (can fix visual issues but slow down products loading)', BeRocket_AJAX_domain) ?></span>
97
  </td>
98
  </tr>
99
  </table>
templates/admin.php CHANGED
@@ -56,16 +56,16 @@
56
  <p>
57
  <a href="#" class='berocket_aapf_advanced_settings_pointer'><?php _e('Advanced Settings', BeRocket_AJAX_domain) ?></a>
58
  </p>
59
- <div class='berocket_aapf_advanced_settings'>
60
  <p>
61
  <label for="<?php echo $this->get_field_id( 'css_class' ); ?>"><?php _e('CSS Class:', BeRocket_AJAX_domain) ?> </label>
62
- <input id="<?php echo $this->get_field_id( 'css_class' ); ?>" type="text" name="<?php echo $this->get_field_name( 'css_class' ); ?>" value="<?php echo $instance['css_class']; ?>" class="berocket_aapf_widget_admin_css_class_input" />
63
  <small>(use white space for multiple classes)</small>
64
  </p>
65
  <p>
66
  <label><?php _e('Product Category:', BeRocket_AJAX_domain) ?>
67
  <label class="berocket_aapf_advanced_settings_subcategory">
68
- <input type="checkbox" name="<?php echo $this->get_field_name( 'cat_propagation' ); ?>" <?php if ( $instance['cat_propagation'] ) echo 'checked'; ?> value="1" class="berocket_aapf_widget_admin_height_input" />
69
  <?php _e('include subcats?', BeRocket_AJAX_domain) ?>
70
  </label>
71
  </label>
56
  <p>
57
  <a href="#" class='berocket_aapf_advanced_settings_pointer'><?php _e('Advanced Settings', BeRocket_AJAX_domain) ?></a>
58
  </p>
59
+ <div class='berocket_aapf_advanced_settings' style="display:none;">
60
  <p>
61
  <label for="<?php echo $this->get_field_id( 'css_class' ); ?>"><?php _e('CSS Class:', BeRocket_AJAX_domain) ?> </label>
62
+ <input id="<?php echo $this->get_field_id( 'css_class' ); ?>" type="text" name="<?php echo $this->get_field_name( 'css_class' ); ?>" value="<?php echo @ $instance['css_class']; ?>" class="berocket_aapf_widget_admin_css_class_input" />
63
  <small>(use white space for multiple classes)</small>
64
  </p>
65
  <p>
66
  <label><?php _e('Product Category:', BeRocket_AJAX_domain) ?>
67
  <label class="berocket_aapf_advanced_settings_subcategory">
68
+ <input type="checkbox" name="<?php echo $this->get_field_name( 'cat_propagation' ); ?>" <?php if ( @ $instance['cat_propagation'] ) echo 'checked'; ?> value="1" class="berocket_aapf_widget_admin_height_input" />
69
  <?php _e('include subcats?', BeRocket_AJAX_domain) ?>
70
  </label>
71
  </label>
templates/checkbox.php CHANGED
@@ -41,5 +41,5 @@ if ( @ $terms ):
41
  </li>
42
  <?php
43
  endforeach; ?>
44
- <li class="berocket_widget_show_values"<?php if( !$hiden_value ) echo 'style="display: none;"'; ?>>Show value<span class="show_button"></span></li>
45
  <?php endif; ?>
41
  </li>
42
  <?php
43
  endforeach; ?>
44
+ <li class="berocket_widget_show_values"<?php if( !$hiden_value ) echo ' style="display: none;"'; ?>>Show value<span class="show_button"></span></li>
45
  <?php endif; ?>
templates/radio.php CHANGED
@@ -31,5 +31,5 @@ if ( $terms ):
31
  </span>
32
  </li>
33
  <?php endforeach; ?>
34
- <li class="berocket_widget_show_values"<?php if( !$hiden_value ) echo 'style="display: none;"'; ?>>Show value<span class="show_button"></span></li>
35
  <?php endif; ?>
31
  </span>
32
  </li>
33
  <?php endforeach; ?>
34
+ <li class="berocket_widget_show_values"<?php if( !$hiden_value ) echo ' style="display: none;"'; ?>>Show value<span class="show_button"></span></li>
35
  <?php endif; ?>
templates/slider.php CHANGED
@@ -8,11 +8,11 @@
8
  <?php echo $text_before_price ?><input type='text' disabled id='text_<?php echo $filter_slider_id . $unique ?>_2' value='<?php echo $slider_value2 ?>'
9
  /><?php echo $text_after_price ?>
10
  </span>
11
- <span class='slide <?php echo @ $uo['class']['slider'] ?>'>
12
  <div class='<?php echo $slider_class ?>' data-taxonomy='<?php echo $filter_slider_id ?>'
13
  data-min='<?php echo $min ?>' data-max='<?php echo $max ?>'
14
  data-value1='<?php echo $slider_value1 ?>' data-value2='<?php echo $slider_value2 ?>'
15
  data-fields_1='text_<?php echo $filter_slider_id . $unique ?>_1'
16
  data-fields_2='text_<?php echo $filter_slider_id . $unique ?>_2'></div>
17
- </span>
18
  </li>
8
  <?php echo $text_before_price ?><input type='text' disabled id='text_<?php echo $filter_slider_id . $unique ?>_2' value='<?php echo $slider_value2 ?>'
9
  /><?php echo $text_after_price ?>
10
  </span>
11
+ <div class='slide <?php echo @ $uo['class']['slider'] ?>'>
12
  <div class='<?php echo $slider_class ?>' data-taxonomy='<?php echo $filter_slider_id ?>'
13
  data-min='<?php echo $min ?>' data-max='<?php echo $max ?>'
14
  data-value1='<?php echo $slider_value1 ?>' data-value2='<?php echo $slider_value2 ?>'
15
  data-fields_1='text_<?php echo $filter_slider_id . $unique ?>_1'
16
  data-fields_2='text_<?php echo $filter_slider_id . $unique ?>_2'></div>
17
+ </div>
18
  </li>
templates/widget_start.php CHANGED
@@ -1,2 +1,2 @@
1
- <h3 class="widget-title berocket_aapf_widget-title <?php echo $css_class ?>"><span><?php echo $title ?></span></h3>
2
  <ul class='berocket_aapf_widget <?php echo $class ?> <?php echo $css_class ?>' <?php echo $style ?> data-scroll_theme='<?php echo $scroll_theme ?>'>
1
+ <?php if ( @ $title ) { ?><h3 class="widget-title berocket_aapf_widget-title <?php echo $css_class ?>"><span><?php echo $title ?></span></h3><?php } ?>
2
  <ul class='berocket_aapf_widget <?php echo $class ?> <?php echo $css_class ?>' <?php echo $style ?> data-scroll_theme='<?php echo $scroll_theme ?>'>
woocommerce-filters.php CHANGED
@@ -3,19 +3,19 @@
3
  * Plugin Name: Advanced AJAX Product Filters for WooCommerce
4
  * Plugin URI: http://berocket.com/wp-plugins/product-filters
5
  * Description: Advanced AJAX Product Filters for WooCommerce
6
- * Version: 1.1.0.8
7
  * Author: BeRocket
8
  * Author URI: http://berocket.com
9
  */
10
 
11
- define( "BeRocket_AJAX_filters_version", '1.1.0.7');
12
- define( "BeRocket_AJAX_domain", 'BRaapf');
13
 
14
  define( "AAPF_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" );
15
  define( "AAPF_URL", plugin_dir_url( __FILE__ ) );
16
 
17
- require_once dirname( __FILE__ ).'/includes/widget.php';
18
- require_once dirname( __FILE__ ).'/includes/functions.php';
19
 
20
  /**
21
  * Class BeRocket_AAPF
@@ -37,6 +37,9 @@ class BeRocket_AAPF {
37
  register_uninstall_hook(__FILE__, array( __CLASS__, 'br_delete_plugin_options' ) );
38
 
39
  if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && br_get_woocommerce_version() >= 2.1 ) {
 
 
 
40
  add_action( 'admin_menu', array( __CLASS__, 'br_add_options_page' ) );
41
  add_action( 'admin_init', array( __CLASS__, 'register_br_options' ) );
42
  add_action( 'init', array( __CLASS__, 'init' ) );
@@ -47,67 +50,80 @@ class BeRocket_AAPF {
47
  if( @ $_GET['filters'] and ! @ defined( 'DOING_AJAX' ) ) {
48
  add_filter( 'pre_get_posts', array( __CLASS__, 'apply_user_filters' ) );
49
  }
50
- if($_GET['explode'] == 'explode') {
 
51
  add_action( 'woocommerce_before_template_part', array( 'BeRocket_AAPF_Widget', 'pre_get_posts'), 999999 );
52
  add_action( 'wp_footer', array( 'BeRocket_AAPF_Widget', 'end_clean'), 999999 );
53
  add_action( 'init', array( 'BeRocket_AAPF_Widget', 'start_clean'), 1 );
54
  }
55
  } else {
56
  if( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
57
- add_action( 'admin_notices', array( __CLASS__, 'update_woocommerce ' ) );
58
  } else {
59
  add_action( 'admin_notices', array( __CLASS__, 'no_woocommerce' ) );
60
  }
61
  }
62
  }
63
 
64
- public function init() {
65
- load_plugin_textdomain(BeRocket_AJAX_domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
 
 
 
 
 
 
 
 
66
  }
67
 
68
- public function no_woocommerce() {
69
  ?>
70
  <div class="error">
71
- <p><?php _e('Activate WooCommerce plugin before', BeRocket_AJAX_domain) ?></p>
72
  </div>
73
  <?php
74
  }
75
 
76
- public function update_woocommerce() {
77
  ?>
78
  <div class="error">
79
- <p><?php _e('Update WooCommerce plugin', BeRocket_AJAX_domain) ?></p>
80
  </div>
81
  <?php
82
  }
83
 
84
- public static function br_add_options_page(){
85
- add_submenu_page( 'woocommerce', __('Product Filters Settings', BeRocket_AJAX_domain), __('Product Filters', BeRocket_AJAX_domain), 'manage_options', 'br-product-filters', array( __CLASS__, 'br_render_form' ) );
86
  }
87
 
88
- public static function shortcode( $atts = array() ){
89
  $a = shortcode_atts(
90
  array(
91
- 'widget_type' => 'filter',
92
- 'attribute' => '',
93
- 'type' => 'checkbox',
94
- 'filter_type' => 'attribute',
95
- 'operator' => 'OR',
96
- 'title' => '',
97
- 'product_cat' => null,
98
  'cat_propagation' => '',
99
- 'height' => 'auto',
100
- 'scroll_theme' => 'dark',
101
- ), $atts );
102
- if(isset($a['product_cat']))
103
- $a['product_cat'] = json_encode(explode("|",$a['product_cat']));
 
 
 
 
104
  if ( ! $a['attribute'] || ! $a['type'] ) return false;
105
 
106
  $BeRocket_AAPF_Widget = new BeRocket_AAPF_Widget();
107
  $BeRocket_AAPF_Widget->widget( array(), $a );
108
  }
109
 
110
- public static function br_render_form(){
111
  wp_enqueue_script( 'berocket_aapf_widget-colorpicker', plugins_url( 'js/colpick.js', __FILE__ ), array( 'jquery' ), BeRocket_AJAX_filters_version );
112
  wp_enqueue_script( 'berocket_aapf_widget-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), BeRocket_AJAX_filters_version );
113
 
@@ -119,16 +135,16 @@ class BeRocket_AAPF {
119
  include AAPF_TEMPLATE_PATH . "admin-settings.php";
120
  }
121
 
122
- public static function apply_user_filters( $query ){
123
  if( $query->is_main_query() and
124
  ( is_shop() or $query->get( 'post_type' ) == 'product' or $query->get( 'product_cat' ) )
125
  or
126
  $query->is_page() && 'page' == get_option( 'show_on_front' ) && $query->get('page_id') == wc_get_page_id('shop')
127
- ){
128
  br_aapf_args_converter();
129
  $args = br_aapf_args_parser();
130
 
131
- if( @ $_POST['price'] ){
132
  list( $_GET['min_price'], $_GET['max_price'] ) = $_POST['price'];
133
  add_filter( 'loop_shop_post_in', array( 'WC_QUERY', 'price_filter' ) );
134
  }
@@ -138,8 +154,8 @@ class BeRocket_AAPF {
138
  }
139
 
140
  $args_fields = array( 'meta_key', 'tax_query', 'fields', 'where', 'join', 'meta_query' );
141
- foreach( $args_fields as $args_field ){
142
- if( @ $args[$args_field] ){
143
  $query->set( $args_field, $args[$args_field] );
144
  }
145
  }
@@ -148,7 +164,7 @@ class BeRocket_AAPF {
148
  return $query;
149
  }
150
 
151
- public static function remove_out_of_stock( $filtered_posts ){
152
  global $wpdb;
153
  $matched_products_query = $wpdb->get_results( "
154
  SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts
@@ -156,12 +172,41 @@ class BeRocket_AAPF {
156
  WHERE post_type IN ( 'product', 'product_variation' ) AND post_status = 'publish'
157
  AND meta_key = '_stock_status' AND meta_value != 'outofstock'", OBJECT_K );
158
  $matched_products = array( 0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  foreach ( $matched_products_query as $product ) {
160
  if ( $product->post_type == 'product' )
161
  $matched_products[] = $product->ID;
162
  if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) )
163
  $matched_products[] = $product->post_parent;
164
  }
 
165
  $matched_products = @ array_unique( $matched_products );
166
 
167
  if ( sizeof( $filtered_posts ) == 0) {
@@ -169,10 +214,11 @@ class BeRocket_AAPF {
169
  } else {
170
  $filtered_posts = array_intersect( $filtered_posts, $matched_products );
171
  }
 
172
  return (array) $filtered_posts;
173
  }
174
 
175
- public static function limits_filter( $filtered_posts ){
176
  global $wpdb;
177
 
178
  if ( @ $_POST['limits'] ) {
@@ -189,8 +235,7 @@ class BeRocket_AAPF {
189
  ", $v[0], $v[1], $v[2] ), OBJECT_K );
190
 
191
  if ( $matched_products_query ) {
192
- if($matched_products === false)
193
- {
194
  $matched_products = array( 0 );
195
  foreach ( $matched_products_query as $product ) {
196
  if ( $product->post_type == 'product' )
@@ -198,9 +243,7 @@ class BeRocket_AAPF {
198
  if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) )
199
  $matched_products[] = $product->post_parent;
200
  }
201
- }
202
- else
203
- {
204
  $new_products = array( 0 );
205
  foreach ( $matched_products_query as $product ) {
206
  if ( $product->post_type == 'product' && in_array($product->ID, $matched_products))
@@ -212,15 +255,15 @@ class BeRocket_AAPF {
212
  }
213
  }
214
  }
215
- if($matched_products === false)
216
- {
217
  $matched_products = array( 0 );
218
  }
219
 
220
  $matched_products = @ array_unique( $matched_products );
221
 
222
  // Filter the id's
223
- if ( sizeof( $filtered_posts ) == 0) {
224
  $filtered_posts = $matched_products;
225
  } else {
226
  $filtered_posts = array_intersect( $filtered_posts, $matched_products );
@@ -298,15 +341,15 @@ class BeRocket_AAPF {
298
  register_setting( 'br_filters_plugin_options', 'br_filters_options' );
299
  }
300
 
301
- public static function br_add_defaults(){
302
  $tmp = get_option( 'br_filters_options' );
303
- if( @ $tmp['chk_default_options_db'] == '1' or ! @ is_array( $tmp ) ){
304
  delete_option( 'br_filters_options' );
305
  update_option( 'br_filters_options', BeRocket_AAPF::$defaults );
306
  }
307
  }
308
 
309
- public static function br_delete_plugin_options(){
310
  delete_option( 'br_filters_options' );
311
  }
312
 
@@ -314,6 +357,31 @@ class BeRocket_AAPF {
314
  return get_option( 'posts_per_page' );
315
  }
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  }
318
 
319
  new BeRocket_AAPF;
3
  * Plugin Name: Advanced AJAX Product Filters for WooCommerce
4
  * Plugin URI: http://berocket.com/wp-plugins/product-filters
5
  * Description: Advanced AJAX Product Filters for WooCommerce
6
+ * Version: 1.1.1
7
  * Author: BeRocket
8
  * Author URI: http://berocket.com
9
  */
10
 
11
+ define( "BeRocket_AJAX_filters_version", '1.1.0.7' );
12
+ define( "BeRocket_AJAX_domain", 'BRaapf' );
13
 
14
  define( "AAPF_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" );
15
  define( "AAPF_URL", plugin_dir_url( __FILE__ ) );
16
 
17
+ require_once dirname( __FILE__ ) . '/includes/widget.php';
18
+ require_once dirname( __FILE__ ) . '/includes/functions.php';
19
 
20
  /**
21
  * Class BeRocket_AAPF
37
  register_uninstall_hook(__FILE__, array( __CLASS__, 'br_delete_plugin_options' ) );
38
 
39
  if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && br_get_woocommerce_version() >= 2.1 ) {
40
+ if ( defined('DOING_AJAX') && DOING_AJAX ) {
41
+ add_action( 'setup_theme', array( __CLASS__, 'WPML_fix' ) );
42
+ }
43
  add_action( 'admin_menu', array( __CLASS__, 'br_add_options_page' ) );
44
  add_action( 'admin_init', array( __CLASS__, 'register_br_options' ) );
45
  add_action( 'init', array( __CLASS__, 'init' ) );
50
  if( @ $_GET['filters'] and ! @ defined( 'DOING_AJAX' ) ) {
51
  add_filter( 'pre_get_posts', array( __CLASS__, 'apply_user_filters' ) );
52
  }
53
+
54
+ if( @ $_GET['explode'] == 'explode' ) {
55
  add_action( 'woocommerce_before_template_part', array( 'BeRocket_AAPF_Widget', 'pre_get_posts'), 999999 );
56
  add_action( 'wp_footer', array( 'BeRocket_AAPF_Widget', 'end_clean'), 999999 );
57
  add_action( 'init', array( 'BeRocket_AAPF_Widget', 'start_clean'), 1 );
58
  }
59
  } else {
60
  if( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
61
+ add_action( 'admin_notices', array( __CLASS__, 'update_woocommerce' ) );
62
  } else {
63
  add_action( 'admin_notices', array( __CLASS__, 'no_woocommerce' ) );
64
  }
65
  }
66
  }
67
 
68
+ public static function init() {
69
+ load_plugin_textdomain( BeRocket_AJAX_domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
70
+
71
+ wp_register_style( 'berocket_aapf_widget-style', plugins_url( 'css/widget.css', __FILE__ ), array(), BeRocket_AJAX_filters_version );
72
+ wp_enqueue_style( 'berocket_aapf_widget-style' );
73
+
74
+ /* custom scrollbar */
75
+ wp_enqueue_script( 'berocket_aapf_widget-scroll-script', plugins_url( 'js/scrollbar/Scrollbar.concat.min.js', __FILE__ ), array( 'jquery' ), BeRocket_AJAX_filters_version );
76
+ wp_register_style( 'berocket_aapf_widget-scroll-style', plugins_url( 'css/scrollbar/Scrollbar.min.css', __FILE__ ), array(), BeRocket_AJAX_filters_version );
77
+ wp_enqueue_style( 'berocket_aapf_widget-scroll-style' );
78
  }
79
 
80
+ public static function no_woocommerce() {
81
  ?>
82
  <div class="error">
83
+ <p><?php _e( 'Activate WooCommerce plugin before', BeRocket_AJAX_domain ) ?></p>
84
  </div>
85
  <?php
86
  }
87
 
88
+ public static function update_woocommerce() {
89
  ?>
90
  <div class="error">
91
+ <p><?php _e( 'Update WooCommerce plugin', BeRocket_AJAX_domain ) ?></p>
92
  </div>
93
  <?php
94
  }
95
 
96
+ public static function br_add_options_page() {
97
+ add_submenu_page( 'woocommerce', __( 'Product Filters Settings', BeRocket_AJAX_domain ), __( 'Product Filters', BeRocket_AJAX_domain ), 'manage_options', 'br-product-filters', array( __CLASS__, 'br_render_form' ) );
98
  }
99
 
100
+ public static function shortcode( $atts = array() ) {
101
  $a = shortcode_atts(
102
  array(
103
+ 'widget_type' => 'filter',
104
+ 'attribute' => '',
105
+ 'type' => 'checkbox',
106
+ 'filter_type' => 'attribute',
107
+ 'operator' => 'OR',
108
+ 'title' => '',
109
+ 'product_cat' => null,
110
  'cat_propagation' => '',
111
+ 'height' => 'auto',
112
+ 'scroll_theme' => 'dark',
113
+ ), $atts
114
+ );
115
+
116
+ if ( isset( $a['product_cat'] ) ) {
117
+ $a['product_cat'] = json_encode( explode( "|", $a['product_cat'] ) );
118
+ }
119
+
120
  if ( ! $a['attribute'] || ! $a['type'] ) return false;
121
 
122
  $BeRocket_AAPF_Widget = new BeRocket_AAPF_Widget();
123
  $BeRocket_AAPF_Widget->widget( array(), $a );
124
  }
125
 
126
+ public static function br_render_form() {
127
  wp_enqueue_script( 'berocket_aapf_widget-colorpicker', plugins_url( 'js/colpick.js', __FILE__ ), array( 'jquery' ), BeRocket_AJAX_filters_version );
128
  wp_enqueue_script( 'berocket_aapf_widget-admin', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), BeRocket_AJAX_filters_version );
129
 
135
  include AAPF_TEMPLATE_PATH . "admin-settings.php";
136
  }
137
 
138
+ public static function apply_user_filters( $query ) {
139
  if( $query->is_main_query() and
140
  ( is_shop() or $query->get( 'post_type' ) == 'product' or $query->get( 'product_cat' ) )
141
  or
142
  $query->is_page() && 'page' == get_option( 'show_on_front' ) && $query->get('page_id') == wc_get_page_id('shop')
143
+ ) {
144
  br_aapf_args_converter();
145
  $args = br_aapf_args_parser();
146
 
147
+ if ( @ $_POST['price'] ) {
148
  list( $_GET['min_price'], $_GET['max_price'] ) = $_POST['price'];
149
  add_filter( 'loop_shop_post_in', array( 'WC_QUERY', 'price_filter' ) );
150
  }
154
  }
155
 
156
  $args_fields = array( 'meta_key', 'tax_query', 'fields', 'where', 'join', 'meta_query' );
157
+ foreach ( $args_fields as $args_field ) {
158
+ if ( @ $args[$args_field] ) {
159
  $query->set( $args_field, $args[$args_field] );
160
  }
161
  }
164
  return $query;
165
  }
166
 
167
+ public static function remove_out_of_stock( $filtered_posts ) {
168
  global $wpdb;
169
  $matched_products_query = $wpdb->get_results( "
170
  SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts
172
  WHERE post_type IN ( 'product', 'product_variation' ) AND post_status = 'publish'
173
  AND meta_key = '_stock_status' AND meta_value != 'outofstock'", OBJECT_K );
174
  $matched_products = array( 0 );
175
+
176
+ foreach ( $matched_products_query as $product ) {
177
+ if ( $product->post_type == 'product' )
178
+ $matched_products[] = $product->ID;
179
+ if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) )
180
+ $matched_products[] = $product->post_parent;
181
+ }
182
+
183
+ $matched_products = @ array_unique( $matched_products );
184
+
185
+ if ( sizeof( $filtered_posts ) == 0) {
186
+ $filtered_posts = $matched_products;
187
+ } else {
188
+ $filtered_posts = array_intersect( $filtered_posts, $matched_products );
189
+ }
190
+
191
+ return (array) $filtered_posts;
192
+ }
193
+
194
+ public static function remove_hidden( $filtered_posts ) {
195
+ global $wpdb;
196
+ $matched_products_query = $wpdb->get_results( "
197
+ SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts
198
+ INNER JOIN $wpdb->postmeta as meta ON ID = meta.post_id
199
+ WHERE post_type IN ( 'product', 'product_variation' ) AND post_status = 'publish'
200
+ AND meta_key = '_visibility' AND meta_value NOT IN ('hidden', 'search')", OBJECT_K );
201
+ $matched_products = array( 0 );
202
+
203
  foreach ( $matched_products_query as $product ) {
204
  if ( $product->post_type == 'product' )
205
  $matched_products[] = $product->ID;
206
  if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) )
207
  $matched_products[] = $product->post_parent;
208
  }
209
+
210
  $matched_products = @ array_unique( $matched_products );
211
 
212
  if ( sizeof( $filtered_posts ) == 0) {
214
  } else {
215
  $filtered_posts = array_intersect( $filtered_posts, $matched_products );
216
  }
217
+
218
  return (array) $filtered_posts;
219
  }
220
 
221
+ public static function limits_filter( $filtered_posts ) {
222
  global $wpdb;
223
 
224
  if ( @ $_POST['limits'] ) {
235
  ", $v[0], $v[1], $v[2] ), OBJECT_K );
236
 
237
  if ( $matched_products_query ) {
238
+ if ( $matched_products === false ) {
 
239
  $matched_products = array( 0 );
240
  foreach ( $matched_products_query as $product ) {
241
  if ( $product->post_type == 'product' )
243
  if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) )
244
  $matched_products[] = $product->post_parent;
245
  }
246
+ } else {
 
 
247
  $new_products = array( 0 );
248
  foreach ( $matched_products_query as $product ) {
249
  if ( $product->post_type == 'product' && in_array($product->ID, $matched_products))
255
  }
256
  }
257
  }
258
+
259
+ if ( $matched_products === false ) {
260
  $matched_products = array( 0 );
261
  }
262
 
263
  $matched_products = @ array_unique( $matched_products );
264
 
265
  // Filter the id's
266
+ if ( sizeof( $filtered_posts ) == 0 ) {
267
  $filtered_posts = $matched_products;
268
  } else {
269
  $filtered_posts = array_intersect( $filtered_posts, $matched_products );
341
  register_setting( 'br_filters_plugin_options', 'br_filters_options' );
342
  }
343
 
344
+ public static function br_add_defaults() {
345
  $tmp = get_option( 'br_filters_options' );
346
+ if ( @ $tmp['chk_default_options_db'] == '1' or ! @ is_array( $tmp ) ){
347
  delete_option( 'br_filters_options' );
348
  update_option( 'br_filters_options', BeRocket_AAPF::$defaults );
349
  }
350
  }
351
 
352
+ public static function br_delete_plugin_options() {
353
  delete_option( 'br_filters_options' );
354
  }
355
 
357
  return get_option( 'posts_per_page' );
358
  }
359
 
360
+ public static function WPML_fix() {
361
+ global $sitepress;
362
+ if ( method_exists( $sitepress, 'switch_lang' ) && isset( $_POST['current_language'] ) && $_POST['current_language'] !== $sitepress->get_default_language() ) {
363
+ $sitepress->switch_lang( $_POST['current_language'], true );
364
+ }
365
+ }
366
+
367
+ public static function order_by_popularity_post_clauses( $args ) {
368
+ global $wpdb;
369
+ $args['orderby'] = "$wpdb->postmeta.meta_value+0 DESC, $wpdb->posts.post_date DESC";
370
+ return $args;
371
+ }
372
+
373
+ public static function order_by_rating_post_clauses( $args ) {
374
+ global $wpdb;
375
+ $args['fields'] .= ", AVG( $wpdb->commentmeta.meta_value ) as average_rating ";
376
+ $args['where'] .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";
377
+ $args['join'] .= "
378
+ LEFT OUTER JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID)
379
+ LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)
380
+ ";
381
+ $args['orderby'] = "average_rating DESC, $wpdb->posts.post_date DESC";
382
+ $args['groupby'] = "$wpdb->posts.ID";
383
+ return $args;
384
+ }
385
  }
386
 
387
  new BeRocket_AAPF;