Advanced Woo Search - Version 1.35

Version Description

  • Fix issue with position of search results box
  • Add 'aws_page_results' filter
  • Add support for 'order by' box in search results page
  • Fix issue fix re-index timeout
Download this release

Release Info

Developer Mihail Barinov
Plugin Icon 128x128 Advanced Woo Search
Version 1.35
Comparing to
See all releases

Code changes from version 1.34 to 1.35

advanced-woo-search.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
- Version: 1.34
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  exit;
17
  }
18
 
19
- define( 'AWS_VERSION', '1.34' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
@@ -41,15 +41,15 @@ final class AWS_Main {
41
  */
42
  protected static $_instance = null;
43
 
44
- /**
45
- * @var AWS_Main Array of all plugin data $data
46
- */
47
- private $data = array();
48
 
49
- /**
50
- * @var AWS_Main Cache instance
51
- */
52
- public $cache = null;
53
 
54
  /**
55
  * Main AWS_Main Instance
@@ -83,9 +83,9 @@ final class AWS_Main {
83
 
84
  load_plugin_textdomain( 'aws', false, dirname( plugin_basename( __FILE__ ) ). '/languages/' );
85
 
86
- $this->includes();
87
 
88
- add_action( 'init', array( $this, 'init' ), 0 );
89
 
90
  }
91
 
@@ -101,6 +101,7 @@ final class AWS_Main {
101
  include_once( 'includes/class-aws-markup.php' );
102
  include_once( 'includes/class-aws-search.php' );
103
  include_once( 'includes/class-aws-search-page.php' );
 
104
  include_once( 'includes/widget.php' );
105
  }
106
 
@@ -114,13 +115,24 @@ final class AWS_Main {
114
  return $markup->markup();
115
 
116
  }
117
-
118
- /*
119
- * Init plugin classes
120
- */
121
- public function init() {
122
- $this->cache = AWS_Cache::factory();
123
- }
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  /*
126
  * Load assets for search form
3
  /*
4
  Plugin Name: Advanced Woo Search
5
  Description: Advance ajax WooCommerce product search.
6
+ Version: 1.35
7
  Author: ILLID
8
  Author URI: https://advanced-woo-search.com/
9
  Text Domain: aws
16
  exit;
17
  }
18
 
19
+ define( 'AWS_VERSION', '1.35' );
20
 
21
 
22
  define( 'AWS_DIR', dirname( __FILE__ ) );
41
  */
42
  protected static $_instance = null;
43
 
44
+ /**
45
+ * @var AWS_Main Array of all plugin data $data
46
+ */
47
+ private $data = array();
48
 
49
+ /**
50
+ * @var AWS_Main Cache instance
51
+ */
52
+ public $cache = null;
53
 
54
  /**
55
  * Main AWS_Main Instance
83
 
84
  load_plugin_textdomain( 'aws', false, dirname( plugin_basename( __FILE__ ) ). '/languages/' );
85
 
86
+ $this->includes();
87
 
88
+ add_action( 'init', array( $this, 'init' ), 0 );
89
 
90
  }
91
 
101
  include_once( 'includes/class-aws-markup.php' );
102
  include_once( 'includes/class-aws-search.php' );
103
  include_once( 'includes/class-aws-search-page.php' );
104
+ include_once( 'includes/class-aws-order.php' );
105
  include_once( 'includes/widget.php' );
106
  }
107
 
115
  return $markup->markup();
116
 
117
  }
118
+
119
+ /*
120
+ * Sort products
121
+ */
122
+ public function order( $products, $order_by ) {
123
+
124
+ $order = new AWS_Order( $products, $order_by );
125
+
126
+ return $order->result();
127
+
128
+ }
129
+
130
+ /*
131
+ * Init plugin classes
132
+ */
133
+ public function init() {
134
+ $this->cache = AWS_Cache::factory();
135
+ }
136
 
137
  /*
138
  * Load assets for search form
assets/js/admin.js CHANGED
@@ -8,6 +8,7 @@ jQuery(document).ready(function ($) {
8
  var syncStatus;
9
  var processed;
10
  var toProcess;
 
11
 
12
  var $clearCacheBtn = $('#aws-clear-cache .button');
13
 
@@ -49,6 +50,8 @@ jQuery(document).ready(function ($) {
49
 
50
  processed = Math.floor( processed / toProcess * 100 );
51
 
 
 
52
  if ( 0 === response.data.offset && ! response.data.start ) {
53
 
54
  // Sync finished
@@ -76,6 +79,14 @@ jQuery(document).ready(function ($) {
76
  },
77
  error : function( jqXHR, textStatus ) {
78
  console.log( "Request failed: " + textStatus );
 
 
 
 
 
 
 
 
79
  },
80
  complete: function () {
81
  }
8
  var syncStatus;
9
  var processed;
10
  var toProcess;
11
+ var syncData = false;
12
 
13
  var $clearCacheBtn = $('#aws-clear-cache .button');
14
 
50
 
51
  processed = Math.floor( processed / toProcess * 100 );
52
 
53
+ syncData = response.data;
54
+
55
  if ( 0 === response.data.offset && ! response.data.start ) {
56
 
57
  // Sync finished
79
  },
80
  error : function( jqXHR, textStatus ) {
81
  console.log( "Request failed: " + textStatus );
82
+
83
+ if ( textStatus == 'timeout' || jqXHR.status == 504 ) {
84
+ console.log( 'timeout' );
85
+ if ( syncData ) {
86
+ setTimeout(function() { sync( syncData ); }, 1000);
87
+ }
88
+ }
89
+
90
  },
91
  complete: function () {
92
  }
assets/js/common.js CHANGED
@@ -230,12 +230,22 @@
230
 
231
  resultLayout: function () {
232
  var offset = self.offset();
 
 
233
 
234
- if ( offset ) {
235
 
236
  var width = self.outerWidth();
237
- var top = offset.top + $(self).innerHeight();
238
- var left = offset.left;
 
 
 
 
 
 
 
 
239
 
240
  $( d.resultBlock ).css({
241
  width : width,
230
 
231
  resultLayout: function () {
232
  var offset = self.offset();
233
+ var bodyOffset = $('body').offset();
234
+ var bodyPosition = $('body').css('position');
235
 
236
+ if ( offset && bodyOffset ) {
237
 
238
  var width = self.outerWidth();
239
+ var top = 0;
240
+ var left = 0;
241
+
242
+ if ( bodyPosition === 'relative' ) {
243
+ top = offset.top + $(self).innerHeight() - bodyOffset.top;
244
+ left = offset.left - bodyOffset.left;
245
+ } else {
246
+ top = offset.top + $(self).innerHeight();
247
+ left = offset.left;
248
+ }
249
 
250
  $( d.resultBlock ).css({
251
  width : width,
includes/class-aws-order.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ if ( ! class_exists( 'AWS_Order' ) ) :
8
+
9
+ /**
10
+ * Class for products sorting
11
+ */
12
+ class AWS_Order {
13
+
14
+ /**
15
+ * @var AWS_Order Array of products
16
+ */
17
+ private $products = array();
18
+
19
+ /**
20
+ * @var AWS_Order Order by value
21
+ */
22
+ private $order_by = null;
23
+
24
+ /**
25
+ * Constructor
26
+ */
27
+ public function __construct( $products, $order_by ) {
28
+
29
+ $this->products = $products;
30
+ $this->order_by = $order_by;
31
+
32
+ $this->order();
33
+
34
+ }
35
+
36
+ /*
37
+ * Sort products
38
+ */
39
+ private function order() {
40
+
41
+ switch( $this->order_by ) {
42
+
43
+ case 'price':
44
+
45
+ if ( isset( $this->products[0]['f_price'] ) ) {
46
+ usort( $this->products, array( $this, 'compare_price_asc' ) );
47
+ }
48
+
49
+ break;
50
+
51
+ case 'price-desc':
52
+
53
+ if ( isset( $this->products[0]['f_price'] ) ) {
54
+ usort( $this->products, array( $this, 'compare_price_desc' ) );
55
+ }
56
+
57
+ break;
58
+
59
+ case 'date':
60
+
61
+ if ( isset( $this->products[0]['post_data'] ) ) {
62
+ usort( $this->products, array( $this, 'compare_date' ) );
63
+ }
64
+
65
+ break;
66
+
67
+ case 'rating':
68
+
69
+ if ( isset( $this->products[0]['f_rating'] ) ) {
70
+ usort( $this->products, array( $this, 'compare_rating' ) );
71
+ }
72
+
73
+ break;
74
+
75
+ case 'popularity':
76
+
77
+ if ( isset( $this->products[0]['f_reviews'] ) ) {
78
+ usort( $this->products, array( $this, 'compare_reviews' ) );
79
+ }
80
+
81
+ break;
82
+
83
+ }
84
+
85
+ }
86
+
87
+ /*
88
+ * Compare price values asc
89
+ */
90
+ private function compare_price_asc( $a, $b ) {
91
+ $a = intval( $a['f_price'] * 100 );
92
+ $b = intval( $b['f_price'] * 100 );
93
+ if ($a == $b) {
94
+ return 0;
95
+ }
96
+ return ($a < $b) ? -1 : 1;
97
+ }
98
+
99
+ /*
100
+ * Compare price values desc
101
+ */
102
+ private function compare_price_desc( $a, $b ) {
103
+ $a = intval( $a['f_price'] * 100 );
104
+ $b = intval( $b['f_price'] * 100 );
105
+ if ($a == $b) {
106
+ return 0;
107
+ }
108
+ return ($a < $b) ? 1 : -1;
109
+ }
110
+
111
+ /*
112
+ * Compare date
113
+ */
114
+ private function compare_date( $a, $b ) {
115
+ $a = strtotime( $a['post_data']->post_date );
116
+ $b = strtotime( $b['post_data']->post_date );
117
+ if ($a == $b) {
118
+ return 0;
119
+ }
120
+ return ($a < $b) ? 1 : -1;
121
+ }
122
+
123
+ /*
124
+ * Compare rating
125
+ */
126
+ private function compare_rating( $a, $b ) {
127
+ $a = intval( $a['f_rating'] * 100 );
128
+ $b = intval( $b['f_rating'] * 100 );
129
+ if ($a == $b) {
130
+ return 0;
131
+ }
132
+ return ($a < $b) ? 1 : -1;
133
+ }
134
+
135
+ /*
136
+ * Compare rating
137
+ */
138
+ private function compare_reviews( $a, $b ) {
139
+ $a = intval( $a['f_reviews'] * 100 );
140
+ $b = intval( $b['f_reviews'] * 100 );
141
+ if ($a == $b) {
142
+ return 0;
143
+ }
144
+ return ($a < $b) ? 1 : -1;
145
+ }
146
+
147
+ /*
148
+ * Return array of sorted products
149
+ */
150
+ public function result() {
151
+
152
+ return $this->products;
153
+
154
+ }
155
+
156
+ }
157
+
158
+ endif;
includes/class-aws-search-page.php CHANGED
@@ -104,6 +104,17 @@ if ( ! class_exists( 'AWS_Search_Page' ) ) :
104
  $offset = ( $paged > 1 ) ? $paged * $posts_per_page - $posts_per_page : 0;
105
 
106
 
 
 
 
 
 
 
 
 
 
 
 
107
  $products = array_slice( $posts_array['products'], $offset, $posts_per_page );
108
 
109
 
104
  $offset = ( $paged > 1 ) ? $paged * $posts_per_page - $posts_per_page : 0;
105
 
106
 
107
+ if ( $query->query && isset( $query->query['orderby'] ) ) {
108
+ $order_by = $query->query['orderby'];
109
+
110
+ if ( isset( $posts_array['products'] ) && ! empty( $posts_array['products'] ) ) {
111
+
112
+ $posts_array['products'] = AWS()->order( $posts_array['products'], $order_by );
113
+
114
+ }
115
+
116
+ }
117
+
118
  $products = array_slice( $posts_array['products'], $offset, $posts_per_page );
119
 
120
 
includes/class-aws-search.php CHANGED
@@ -75,9 +75,10 @@ if ( ! class_exists( 'AWS_Search' ) ) :
75
  $s = str_replace( array( "\r", "\n" ), '', $s );
76
  $s = str_replace( $special_chars, '', $s );
77
 
78
- $cache_option_name = AWS()->cache->get_cache_name( $s );
79
 
80
- if ( $cache === 'true' ) {
 
81
  $res = AWS()->cache->get_from_cache_table( $cache_option_name );
82
  if ( $res ) {
83
  $cached_value = json_decode( $res );
@@ -89,7 +90,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
89
 
90
  $show_cats = AWS()->get_settings( 'show_cats' );
91
  $show_tags = AWS()->get_settings( 'show_tags' );
92
- $results_num = $keyword ? 100 : AWS()->get_settings( 'results_num' );
93
  $search_in = AWS()->get_settings( 'search_in' );
94
  $outofstock = AWS()->get_settings( 'outofstock' );
95
 
@@ -131,7 +132,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
131
  );
132
 
133
 
134
- if ( $cache === 'true' ) {
135
  AWS()->cache->insert_into_cache_table( $cache_option_name, $result_array );
136
  }
137
 
@@ -372,6 +373,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
372
  $sku = '';
373
  $stock_status = '';
374
 
 
375
  if ( $show_excerpt === 'true' ) {
376
  $excerpt = ( $excerpt_source === 'excerpt' && $post_data->post_excerpt ) ? $post_data->post_excerpt : $post_data->post_content;
377
  $excerpt = AWS_Helpers::html2txt( $excerpt );
@@ -422,6 +424,11 @@ if ( ! class_exists( 'AWS_Search' ) ) :
422
  }
423
  }
424
 
 
 
 
 
 
425
  // $categories = $product->get_categories( ',' );
426
  // $tags = $product->get_tags( ',' );
427
 
@@ -434,6 +441,9 @@ if ( ! class_exists( 'AWS_Search' ) ) :
434
  'on_sale' => $on_sale,
435
  'sku' => $sku,
436
  'stock_status' => $stock_status,
 
 
 
437
  'post_data' => $post_data
438
  );
439
 
75
  $s = str_replace( array( "\r", "\n" ), '', $s );
76
  $s = str_replace( $special_chars, '', $s );
77
 
78
+ $cache_option_name = '';
79
 
80
+ if ( $cache === 'true' && ! $keyword ) {
81
+ $cache_option_name = AWS()->cache->get_cache_name( $s );
82
  $res = AWS()->cache->get_from_cache_table( $cache_option_name );
83
  if ( $res ) {
84
  $cached_value = json_decode( $res );
90
 
91
  $show_cats = AWS()->get_settings( 'show_cats' );
92
  $show_tags = AWS()->get_settings( 'show_tags' );
93
+ $results_num = $keyword ? apply_filters( 'aws_page_results', 100 ) : AWS()->get_settings( 'results_num' );
94
  $search_in = AWS()->get_settings( 'search_in' );
95
  $outofstock = AWS()->get_settings( 'outofstock' );
96
 
132
  );
133
 
134
 
135
+ if ( $cache === 'true' && ! $keyword ) {
136
  AWS()->cache->insert_into_cache_table( $cache_option_name, $result_array );
137
  }
138
 
373
  $sku = '';
374
  $stock_status = '';
375
 
376
+
377
  if ( $show_excerpt === 'true' ) {
378
  $excerpt = ( $excerpt_source === 'excerpt' && $post_data->post_excerpt ) ? $post_data->post_excerpt : $post_data->post_content;
379
  $excerpt = AWS_Helpers::html2txt( $excerpt );
424
  }
425
  }
426
 
427
+
428
+ $f_price = $product->get_price();
429
+ $f_rating = $product->get_average_rating();
430
+ $f_reviews = $product->get_review_count();
431
+
432
  // $categories = $product->get_categories( ',' );
433
  // $tags = $product->get_tags( ',' );
434
 
441
  'on_sale' => $on_sale,
442
  'sku' => $sku,
443
  'stock_status' => $stock_status,
444
+ 'f_price' => $f_price,
445
+ 'f_rating' => $f_rating,
446
+ 'f_reviews' => $f_reviews,
447
  'post_data' => $post_data
448
  );
449
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Mihail Barinov
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GSE37FC4Y7CEY
4
  Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
5
  Requires at least: 4.0
6
- Tested up to: 4.9.2
7
- Stable tag: 1.34
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -75,6 +75,12 @@ Yep. This plugin is always compatible with the latest version of Woocommerce?
75
 
76
  == Changelog ==
77
 
 
 
 
 
 
 
78
  = 1.34 =
79
  * Add arrows navigation for search results
80
  * Fix bug with php 7+ vesion
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GSE37FC4Y7CEY
4
  Tags: widget, plugin, woocommerce, search, product search, woocommerce search, ajax search, live search, custom search, ajax, shortcode, better search, relevance search, relevant search, search by sku, search plugin, shop, store, wordpress search, wp ajax search, wp search, wp search plugin, sidebar, ecommerce, merketing, products, category search, instant-search, search highlight, woocommerce advanced search, woocommerce live search, WooCommerce Plugin, woocommerce product search
5
  Requires at least: 4.0
6
+ Tested up to: 4.9.4
7
+ Stable tag: 1.35
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
75
 
76
  == Changelog ==
77
 
78
+ = 1.35 =
79
+ * Fix issue with position of search results box
80
+ * Add 'aws_page_results' filter
81
+ * Add support for 'order by' box in search results page
82
+ * Fix issue fix re-index timeout
83
+
84
  = 1.34 =
85
  * Add arrows navigation for search results
86
  * Fix bug with php 7+ vesion