Version Description
- Update search results page
- Fix some layout issues
Download this release
Release Info
Developer | Mihail Barinov |
Plugin | Advanced Woo Search |
Version | 1.10 |
Comparing to | |
See all releases |
Code changes from version 1.09 to 1.10
- advanced-woo-search.php +7 -2
- assets/css/admin.css +5 -1
- assets/js/common.js +39 -30
- includes/class-aws-admin.php +11 -8
- includes/class-aws-helpers.php +23 -0
- includes/class-aws-markup.php +3 -2
- includes/class-aws-search-page.php +220 -0
- includes/class-aws-search.php +43 -13
- languages/aws.pot +8 -0
- readme.txt +6 -2
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.
|
7 |
Author: ILLID
|
8 |
Text Domain: aws
|
9 |
*/
|
@@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
13 |
exit;
|
14 |
}
|
15 |
|
16 |
-
define( 'AWS_VERSION', '1.
|
17 |
|
18 |
|
19 |
define( 'AWS_DIR', dirname( __FILE__ ) );
|
@@ -89,6 +89,7 @@ final class AWS_Main {
|
|
89 |
include_once( 'includes/class-aws-table.php' );
|
90 |
include_once( 'includes/class-aws-markup.php' );
|
91 |
include_once( 'includes/class-aws-search.php' );
|
|
|
92 |
include_once( 'includes/widget.php' );
|
93 |
}
|
94 |
|
@@ -109,6 +110,10 @@ final class AWS_Main {
|
|
109 |
public function load_scripts() {
|
110 |
wp_enqueue_style( 'aws-style', AWS_URL . '/assets/css/common.css', array(), AWS_VERSION );
|
111 |
wp_enqueue_script( 'aws-script', AWS_URL . '/assets/js/common.js', array('jquery'), AWS_VERSION, true );
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
|
114 |
/*
|
3 |
/*
|
4 |
Plugin Name: Advanced Woo Search
|
5 |
Description: Advance ajax WooCommerce product search.
|
6 |
+
Version: 1.10
|
7 |
Author: ILLID
|
8 |
Text Domain: aws
|
9 |
*/
|
13 |
exit;
|
14 |
}
|
15 |
|
16 |
+
define( 'AWS_VERSION', '1.10' );
|
17 |
|
18 |
|
19 |
define( 'AWS_DIR', dirname( __FILE__ ) );
|
89 |
include_once( 'includes/class-aws-table.php' );
|
90 |
include_once( 'includes/class-aws-markup.php' );
|
91 |
include_once( 'includes/class-aws-search.php' );
|
92 |
+
include_once( 'includes/class-aws-search-page.php' );
|
93 |
include_once( 'includes/widget.php' );
|
94 |
}
|
95 |
|
110 |
public function load_scripts() {
|
111 |
wp_enqueue_style( 'aws-style', AWS_URL . '/assets/css/common.css', array(), AWS_VERSION );
|
112 |
wp_enqueue_script( 'aws-script', AWS_URL . '/assets/js/common.js', array('jquery'), AWS_VERSION, true );
|
113 |
+
wp_localize_script( 'aws-script', 'aws_vars', array(
|
114 |
+
'sale' => __( 'Sale!', 'aws' ),
|
115 |
+
'noresults' => __( 'Nothing found', 'aws' )
|
116 |
+
) );
|
117 |
}
|
118 |
|
119 |
/*
|
assets/css/admin.css
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
|
14 |
.sti-sortable {
|
15 |
border: 1px solid #C7C4C4;
|
16 |
-
background: #
|
17 |
list-style-type: none;
|
18 |
margin: 0;
|
19 |
padding: 5px;
|
@@ -21,6 +21,10 @@
|
|
21 |
min-height: 180px;
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
24 |
.sti-sortable li.sti-btn,
|
25 |
.sti-sortable li.highlight,
|
26 |
.sti-sortable li#excerpt {
|
13 |
|
14 |
.sti-sortable {
|
15 |
border: 1px solid #C7C4C4;
|
16 |
+
background: #fff7f7;
|
17 |
list-style-type: none;
|
18 |
margin: 0;
|
19 |
padding: 5px;
|
21 |
min-height: 180px;
|
22 |
}
|
23 |
|
24 |
+
.sti-sortable.enabled {
|
25 |
+
background: #ddf0dc;
|
26 |
+
}
|
27 |
+
|
28 |
.sti-sortable li.sti-btn,
|
29 |
.sti-sortable li.highlight,
|
30 |
.sti-sortable li#excerpt {
|
assets/js/common.js
CHANGED
@@ -4,37 +4,13 @@
|
|
4 |
var selector = '.aws-container';
|
5 |
var instance = 0;
|
6 |
var pluginPfx = 'aws_opts';
|
|
|
|
|
|
|
|
|
7 |
|
8 |
$.fn.aws_search = function( options ) {
|
9 |
|
10 |
-
|
11 |
-
instance++;
|
12 |
-
|
13 |
-
|
14 |
-
var self = $(this),
|
15 |
-
$searchForm = self.find('.aws-search-form'),
|
16 |
-
$searchField = self.find('.aws-search-field'),
|
17 |
-
haveResults = false,
|
18 |
-
requests = Array(),
|
19 |
-
searchFor = '',
|
20 |
-
cachedResponse = new Array();
|
21 |
-
|
22 |
-
|
23 |
-
var ajaxUrl = ( self.data('url') !== undefined ) ? self.data('url') : false;
|
24 |
-
//var siteUrl = ( self.data('siteurl') !== undefined ) ? self.data('siteurl') : false;
|
25 |
-
|
26 |
-
|
27 |
-
self.data( pluginPfx, {
|
28 |
-
minChars : ( self.data('min-chars') !== undefined ) ? self.data('min-chars') : 1,
|
29 |
-
showLoader: ( self.data('show-loader') !== undefined ) ? self.data('show-loader') : true,
|
30 |
-
instance: instance,
|
31 |
-
resultBlock: '#aws-search-result-' + instance
|
32 |
-
});
|
33 |
-
|
34 |
-
|
35 |
-
var d = self.data(pluginPfx);
|
36 |
-
|
37 |
-
|
38 |
var methods = {
|
39 |
|
40 |
init: function() {
|
@@ -179,7 +155,7 @@
|
|
179 |
|
180 |
if ( result.on_sale ) {
|
181 |
html += '<span class="aws_result_sale">';
|
182 |
-
html += '<span class="aws_onsale">
|
183 |
html += '</span>';
|
184 |
}
|
185 |
|
@@ -194,7 +170,7 @@
|
|
194 |
}
|
195 |
|
196 |
if ( response.cats.length <= 0 && response.tags.length <= 0 && response.products.length <= 0 ) {
|
197 |
-
html += '<li class="aws_result_item aws_no_result">
|
198 |
}
|
199 |
|
200 |
|
@@ -241,6 +217,39 @@
|
|
241 |
};
|
242 |
|
243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
if ( $searchForm.length > 0 ) {
|
245 |
methods.init.call(this);
|
246 |
}
|
4 |
var selector = '.aws-container';
|
5 |
var instance = 0;
|
6 |
var pluginPfx = 'aws_opts';
|
7 |
+
var translate = {
|
8 |
+
sale : aws_vars.sale,
|
9 |
+
noresults : aws_vars.noresults
|
10 |
+
};
|
11 |
|
12 |
$.fn.aws_search = function( options ) {
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
var methods = {
|
15 |
|
16 |
init: function() {
|
155 |
|
156 |
if ( result.on_sale ) {
|
157 |
html += '<span class="aws_result_sale">';
|
158 |
+
html += '<span class="aws_onsale">' + translate.sale + '</span>';
|
159 |
html += '</span>';
|
160 |
}
|
161 |
|
170 |
}
|
171 |
|
172 |
if ( response.cats.length <= 0 && response.tags.length <= 0 && response.products.length <= 0 ) {
|
173 |
+
html += '<li class="aws_result_item aws_no_result">' + translate.noresults + '</li>';
|
174 |
}
|
175 |
|
176 |
|
217 |
};
|
218 |
|
219 |
|
220 |
+
var self = $(this),
|
221 |
+
$searchForm = self.find('.aws-search-form'),
|
222 |
+
$searchField = self.find('.aws-search-field'),
|
223 |
+
haveResults = false,
|
224 |
+
requests = Array(),
|
225 |
+
searchFor = '',
|
226 |
+
cachedResponse = new Array();
|
227 |
+
|
228 |
+
|
229 |
+
var ajaxUrl = ( self.data('url') !== undefined ) ? self.data('url') : false;
|
230 |
+
|
231 |
+
|
232 |
+
if ( options === 'relayout' ) {
|
233 |
+
var d = self.data(pluginPfx);
|
234 |
+
methods.resultLayout();
|
235 |
+
return;
|
236 |
+
}
|
237 |
+
|
238 |
+
|
239 |
+
instance++;
|
240 |
+
|
241 |
+
self.data( pluginPfx, {
|
242 |
+
minChars : ( self.data('min-chars') !== undefined ) ? self.data('min-chars') : 1,
|
243 |
+
showLoader: ( self.data('show-loader') !== undefined ) ? self.data('show-loader') : true,
|
244 |
+
instance: instance,
|
245 |
+
resultBlock: '#aws-search-result-' + instance
|
246 |
+
});
|
247 |
+
|
248 |
+
|
249 |
+
var d = self.data(pluginPfx);
|
250 |
+
|
251 |
+
|
252 |
+
|
253 |
if ( $searchForm.length > 0 ) {
|
254 |
methods.init.call(this);
|
255 |
}
|
includes/class-aws-admin.php
CHANGED
@@ -294,7 +294,7 @@ class AWS_Admin {
|
|
294 |
|
295 |
<div class="sortable-title"><?php _e( 'Available fields', 'aws' ) ?></div>
|
296 |
|
297 |
-
<ul id="sti-sortable1" class="sti-sortable connectedSortable">
|
298 |
<?php
|
299 |
if ( count( $inactive_buttons ) > 0 ) {
|
300 |
foreach ($inactive_buttons as $button) {
|
@@ -310,7 +310,7 @@ class AWS_Admin {
|
|
310 |
|
311 |
<div class="sortable-title"><?php _e( 'Drag&drop to enable', 'aws' ) ?></div>
|
312 |
|
313 |
-
<ul id="sti-sortable2" class="sti-sortable connectedSortable">
|
314 |
<?php
|
315 |
if ( count( $active_buttons ) > 0 ) {
|
316 |
foreach ($active_buttons as $button) {
|
@@ -348,22 +348,25 @@ class AWS_Admin {
|
|
348 |
|
349 |
echo '<th>' . __( 'Reindex table', 'aws' ) . '</th>';
|
350 |
echo '<td>';
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
353 |
echo '</td>';
|
354 |
|
355 |
-
echo '
|
356 |
|
357 |
|
358 |
echo '<tr>';
|
359 |
|
360 |
echo '<th>' . __( 'Clear cache', 'aws' ) . '</th>';
|
361 |
echo '<td>';
|
362 |
-
|
363 |
-
|
364 |
echo '</td>';
|
365 |
|
366 |
-
echo '
|
367 |
|
368 |
|
369 |
}
|
294 |
|
295 |
<div class="sortable-title"><?php _e( 'Available fields', 'aws' ) ?></div>
|
296 |
|
297 |
+
<ul id="sti-sortable1" class="sti-sortable disabled connectedSortable">
|
298 |
<?php
|
299 |
if ( count( $inactive_buttons ) > 0 ) {
|
300 |
foreach ($inactive_buttons as $button) {
|
310 |
|
311 |
<div class="sortable-title"><?php _e( 'Drag&drop to enable', 'aws' ) ?></div>
|
312 |
|
313 |
+
<ul id="sti-sortable2" class="sti-sortable enabled connectedSortable">
|
314 |
<?php
|
315 |
if ( count( $active_buttons ) > 0 ) {
|
316 |
foreach ($active_buttons as $button) {
|
348 |
|
349 |
echo '<th>' . __( 'Reindex table', 'aws' ) . '</th>';
|
350 |
echo '<td>';
|
351 |
+
echo '<div id="aws-reindex"><input class="button" type="button" value="' . __( 'Reindex table', 'aws' ) . '"><span class="loader"></span></div><br><br>';
|
352 |
+
echo '<span class="description">' .
|
353 |
+
__( 'Update all data in plugins index table. Index table - table with products data where plugin is searching all typed terms.<br>Use this button if you think that plugin not shows last actual data in its search results.<br><strong>CAUTION:</strong> this can take large amount of time.', 'aws' ) . '<br><br>' .
|
354 |
+
__( 'Products in index:', 'aws' ) . '<strong> ' . AWS_Helpers::get_indexed_products_count() . '</strong>';
|
355 |
+
echo '</span>';
|
356 |
echo '</td>';
|
357 |
|
358 |
+
echo '</tr>';
|
359 |
|
360 |
|
361 |
echo '<tr>';
|
362 |
|
363 |
echo '<th>' . __( 'Clear cache', 'aws' ) . '</th>';
|
364 |
echo '<td>';
|
365 |
+
echo '<div id="aws-clear-cache"><input class="button" type="button" value="' . __( 'Clear cache', 'aws' ) . '"><span class="loader"></span></div><br>';
|
366 |
+
echo '<span class="description">' . __( 'Clear cache for all search results.', 'aws' ) . '</span>';
|
367 |
echo '</td>';
|
368 |
|
369 |
+
echo '</tr>';
|
370 |
|
371 |
|
372 |
}
|
includes/class-aws-helpers.php
CHANGED
@@ -38,6 +38,29 @@ if ( ! class_exists( 'AWS_Helpers' ) ) :
|
|
38 |
return $str;
|
39 |
}
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
|
43 |
endif;
|
38 |
return $str;
|
39 |
}
|
40 |
|
41 |
+
/*
|
42 |
+
* Get amount of indexed products
|
43 |
+
*/
|
44 |
+
static public function get_indexed_products_count() {
|
45 |
+
|
46 |
+
global $wpdb;
|
47 |
+
|
48 |
+
$table_name = $wpdb->prefix . AWS_INDEX_TABLE_NAME;
|
49 |
+
|
50 |
+
$indexed_products = 0;
|
51 |
+
|
52 |
+
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) {
|
53 |
+
|
54 |
+
$sql = "SELECT FOUND_ROWS() as rows FROM {$table_name} GROUP BY ID;";
|
55 |
+
|
56 |
+
$indexed_products = $wpdb->query( $sql );
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
return $indexed_products;
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
}
|
65 |
|
66 |
endif;
|
includes/class-aws-markup.php
CHANGED
@@ -34,7 +34,7 @@ if ( ! class_exists( 'AWS_Markup' ) ) :
|
|
34 |
|
35 |
$params = array(
|
36 |
'data-url' => admin_url('admin-ajax.php'),
|
37 |
-
'data-siteurl' =>
|
38 |
'data-show-loader' => $show_loader,
|
39 |
'data-min-chars' => $min_chars,
|
40 |
);
|
@@ -45,9 +45,10 @@ if ( ! class_exists( 'AWS_Markup' ) ) :
|
|
45 |
|
46 |
$markup = '';
|
47 |
$markup .= '<div class="aws-container" ' . $params_string . '>';
|
48 |
-
$markup .= '<form class="aws-search-form" action="' .
|
49 |
$markup .= '<input type="text" name="s" value="' . get_search_query() . '" class="aws-search-field" placeholder="' . $placeholder . '" autocomplete="off" />';
|
50 |
$markup .= '<input type="hidden" name="post_type" value="product">';
|
|
|
51 |
$markup .= '<div class="aws-search-result" style="display: none;"></div>';
|
52 |
$markup .= '</form>';
|
53 |
$markup .= '</div>';
|
34 |
|
35 |
$params = array(
|
36 |
'data-url' => admin_url('admin-ajax.php'),
|
37 |
+
'data-siteurl' => home_url(),
|
38 |
'data-show-loader' => $show_loader,
|
39 |
'data-min-chars' => $min_chars,
|
40 |
);
|
45 |
|
46 |
$markup = '';
|
47 |
$markup .= '<div class="aws-container" ' . $params_string . '>';
|
48 |
+
$markup .= '<form class="aws-search-form" action="' . home_url() . '" method="get" role="search" >';
|
49 |
$markup .= '<input type="text" name="s" value="' . get_search_query() . '" class="aws-search-field" placeholder="' . $placeholder . '" autocomplete="off" />';
|
50 |
$markup .= '<input type="hidden" name="post_type" value="product">';
|
51 |
+
$markup .= '<input type="hidden" name="type_aws" value="true">';
|
52 |
$markup .= '<div class="aws-search-result" style="display: none;"></div>';
|
53 |
$markup .= '</form>';
|
54 |
$markup .= '</div>';
|
includes/class-aws-search-page.php
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Integrate with WP_Query
|
4 |
+
*
|
5 |
+
* @since 1.0
|
6 |
+
* @package elasticpress
|
7 |
+
*/
|
8 |
+
|
9 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
+
exit; // Exit if accessed directly.
|
11 |
+
}
|
12 |
+
|
13 |
+
if ( ! class_exists( 'AWS_Search_Page' ) ) :
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Class for plugin search
|
17 |
+
*/
|
18 |
+
class AWS_Search_Page {
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Is set only when we are within a multisite loop
|
22 |
+
*
|
23 |
+
* @var bool|WP_Query
|
24 |
+
*/
|
25 |
+
private $query_stack = array();
|
26 |
+
|
27 |
+
private $posts_by_query = array();
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Return a singleton instance of the current class
|
31 |
+
*
|
32 |
+
* @return object
|
33 |
+
*/
|
34 |
+
public static function factory() {
|
35 |
+
static $instance = false;
|
36 |
+
|
37 |
+
if ( ! $instance ) {
|
38 |
+
$instance = new self();
|
39 |
+
$instance->setup();
|
40 |
+
}
|
41 |
+
|
42 |
+
return $instance;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Placeholder
|
47 |
+
*/
|
48 |
+
public function __construct() {}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Setup actions and filters for all things settings
|
52 |
+
*/
|
53 |
+
public function setup() {
|
54 |
+
|
55 |
+
// Make sure we return nothing for MySQL posts query
|
56 |
+
add_filter( 'posts_request', array( $this, 'filter_posts_request' ), 10, 2 );
|
57 |
+
|
58 |
+
// Query and filter to WP_Query
|
59 |
+
add_filter( 'the_posts', array( $this, 'filter_the_posts' ), 10, 2 );
|
60 |
+
|
61 |
+
// Add header
|
62 |
+
add_action( 'pre_get_posts', array( $this, 'action_pre_get_posts' ), 5 );
|
63 |
+
|
64 |
+
// Nukes the FOUND_ROWS() database query
|
65 |
+
add_filter( 'found_posts_query', array( $this, 'filter_found_posts_query' ), 5, 2 );
|
66 |
+
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Filter query string used for get_posts(). Query for posts and save for later.
|
71 |
+
* Return a query that will return nothing.
|
72 |
+
*
|
73 |
+
* @param string $request
|
74 |
+
* @param object $query
|
75 |
+
* @return string
|
76 |
+
*/
|
77 |
+
public function filter_posts_request( $request, $query ) {
|
78 |
+
|
79 |
+
if ( ( isset( $query->query_vars['s'] ) && ! isset( $_GET['type_aws'] ) ) || ! isset( $query->query_vars['s'] ) ) {
|
80 |
+
return $request;
|
81 |
+
}
|
82 |
+
|
83 |
+
$new_posts = array();
|
84 |
+
|
85 |
+
$posts_array = aws_search( $query->query_vars['s'] );
|
86 |
+
|
87 |
+
$query->found_posts = count( $posts_array['products'] );
|
88 |
+
$query->max_num_pages = ceil( count( $posts_array['products'] ) / $query->get( 'posts_per_page' ) );
|
89 |
+
|
90 |
+
$paged = $query->query_vars['paged'] ? $query->query_vars['paged'] : 1;
|
91 |
+
$offset = ( $paged > 1 ) ? $paged * $query->get( 'posts_per_page' ) - $query->get( 'posts_per_page' ) : 0;
|
92 |
+
|
93 |
+
|
94 |
+
$products = array_slice( $posts_array['products'], $offset, $query->get( 'posts_per_page' ) );
|
95 |
+
|
96 |
+
|
97 |
+
foreach ( $products as $post_array ) {
|
98 |
+
$post = new stdClass();
|
99 |
+
|
100 |
+
$post_data = $post_array['post_data'];
|
101 |
+
|
102 |
+
$post->ID = $post_data->ID;
|
103 |
+
$post->site_id = get_current_blog_id();
|
104 |
+
|
105 |
+
if ( ! empty( $post_data->site_id ) ) {
|
106 |
+
$post->site_id = $post_data->site_id;
|
107 |
+
}
|
108 |
+
|
109 |
+
$post_return_args = array(
|
110 |
+
'post_type',
|
111 |
+
'post_author',
|
112 |
+
'post_name',
|
113 |
+
'post_status',
|
114 |
+
'post_title',
|
115 |
+
'post_parent',
|
116 |
+
'post_content',
|
117 |
+
'post_excerpt',
|
118 |
+
'post_date',
|
119 |
+
'post_date_gmt',
|
120 |
+
'post_modified',
|
121 |
+
'post_modified_gmt',
|
122 |
+
'post_mime_type',
|
123 |
+
'comment_count',
|
124 |
+
'comment_status',
|
125 |
+
'ping_status',
|
126 |
+
'menu_order',
|
127 |
+
'permalink',
|
128 |
+
'terms',
|
129 |
+
'post_meta'
|
130 |
+
);
|
131 |
+
|
132 |
+
foreach ( $post_return_args as $key ) {
|
133 |
+
if ( isset( $post_data->$key ) ) {
|
134 |
+
$post->$key = $post_data->$key;
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
$post->awssearch = true; // Super useful for debugging
|
139 |
+
|
140 |
+
if ( $post ) {
|
141 |
+
$new_posts[] = $post;
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
|
146 |
+
$this->posts_by_query[spl_object_hash( $query )] = $new_posts;
|
147 |
+
|
148 |
+
|
149 |
+
global $wpdb;
|
150 |
+
|
151 |
+
return "SELECT * FROM $wpdb->posts WHERE 1=0";
|
152 |
+
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Filter the posts array to contain ES query results in EP_Post form. Pull previously queried posts.
|
157 |
+
*
|
158 |
+
* @param array $posts
|
159 |
+
* @param object &$query
|
160 |
+
* @return array
|
161 |
+
*/
|
162 |
+
public function filter_the_posts( $posts, &$query ) {
|
163 |
+
if ( ( isset( $query->query_vars['s'] ) && ! isset( $_GET['type_aws'] ) ) || ! isset( $query->query_vars['s'] ) || ! isset( $this->posts_by_query[spl_object_hash( $query )] ) ) {
|
164 |
+
return $posts;
|
165 |
+
}
|
166 |
+
|
167 |
+
$new_posts = $this->posts_by_query[spl_object_hash( $query )];
|
168 |
+
|
169 |
+
return $new_posts;
|
170 |
+
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Disables cache_results, adds header.
|
175 |
+
*
|
176 |
+
* @param $query
|
177 |
+
*/
|
178 |
+
public function action_pre_get_posts( $query ) {
|
179 |
+
if ( ( isset( $query->query_vars['s'] ) && ! isset( $_GET['type_aws'] ) ) || ! isset( $query->query_vars['s'] ) ) {
|
180 |
+
return;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* `cache_results` defaults to false but can be enabled
|
185 |
+
*/
|
186 |
+
$query->set( 'cache_results', false );
|
187 |
+
if ( ! empty( $query->query['cache_results'] ) ) {
|
188 |
+
$query->set( 'cache_results', true );
|
189 |
+
}
|
190 |
+
|
191 |
+
if ( ! headers_sent() ) {
|
192 |
+
/**
|
193 |
+
* Manually setting a header as $wp_query isn't yet initialized
|
194 |
+
* when we call: add_filter('wp_headers', 'filter_wp_headers');
|
195 |
+
*/
|
196 |
+
header( 'X-AWS-Search: true' );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Remove the found_rows from the SQL Query
|
202 |
+
*
|
203 |
+
* @param string $sql
|
204 |
+
* @param object $query
|
205 |
+
* @return string
|
206 |
+
*/
|
207 |
+
public function filter_found_posts_query( $sql, $query ) {
|
208 |
+
if ( ( isset( $query->query_vars['s'] ) && ! isset( $_GET['type_aws'] ) ) || ! isset( $query->query_vars['s'] ) ) {
|
209 |
+
return $sql;
|
210 |
+
}
|
211 |
+
|
212 |
+
return '';
|
213 |
+
}
|
214 |
+
|
215 |
+
}
|
216 |
+
|
217 |
+
|
218 |
+
endif;
|
219 |
+
|
220 |
+
AWS_Search_Page::factory();
|
includes/class-aws-search.php
CHANGED
@@ -16,10 +16,31 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
16 |
*/
|
17 |
private $data = array();
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
/**
|
20 |
* Constructor
|
21 |
*/
|
22 |
-
public function __construct() {
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
$this->data['settings'] = get_option( 'aws_settings' );
|
25 |
|
@@ -28,16 +49,13 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
28 |
|
29 |
}
|
30 |
|
31 |
-
|
32 |
-
* AJAX call action callback
|
33 |
-
*/
|
34 |
-
public function action_callback() {
|
35 |
|
36 |
global $wpdb;
|
37 |
|
38 |
$cache = AWS()->get_settings( 'cache' );
|
39 |
|
40 |
-
$s = esc_attr( $_POST['keyword'] );
|
41 |
$s = stripslashes( $s );
|
42 |
$s = str_replace( array( "\r", "\n" ), '', $s );
|
43 |
|
@@ -49,8 +67,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
49 |
// Check if value was already cached
|
50 |
if ($cached_value = get_option($cache_option_name)) {
|
51 |
$cached_value['cache'] = 'cached';
|
52 |
-
|
53 |
-
die;
|
54 |
}
|
55 |
|
56 |
}
|
@@ -73,7 +90,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
73 |
|
74 |
|
75 |
$this->data['s'] = $s;
|
76 |
-
$this->data['results_num'] = $results_num;
|
77 |
$this->data['search_terms'] = array();
|
78 |
$this->data['search_terms'] = array_unique( explode( ' ', $s ) );
|
79 |
$this->data['search_in'] = $search_in_arr;
|
@@ -103,7 +120,16 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
103 |
}
|
104 |
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
die;
|
109 |
|
@@ -270,7 +296,7 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
270 |
|
271 |
foreach ( $posts_ids as $post_id ) {
|
272 |
|
273 |
-
$product =
|
274 |
|
275 |
$post_data = $product->get_post_data();
|
276 |
|
@@ -331,7 +357,8 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
331 |
'categories' => $categories,
|
332 |
'tags' => $tags,
|
333 |
'on_sale' => $on_sale,
|
334 |
-
'sku' => $sku
|
|
|
335 |
);
|
336 |
|
337 |
$products_array[] = $new_result;
|
@@ -506,5 +533,8 @@ if ( ! class_exists( 'AWS_Search' ) ) :
|
|
506 |
|
507 |
endif;
|
508 |
|
|
|
509 |
|
510 |
-
|
|
|
|
16 |
*/
|
17 |
private $data = array();
|
18 |
|
19 |
+
/**
|
20 |
+
* Return a singleton instance of the current class
|
21 |
+
*
|
22 |
+
* @return object
|
23 |
+
*/
|
24 |
+
public static function factory() {
|
25 |
+
static $instance = false;
|
26 |
+
|
27 |
+
if ( ! $instance ) {
|
28 |
+
$instance = new self();
|
29 |
+
$instance->setup();
|
30 |
+
}
|
31 |
+
|
32 |
+
return $instance;
|
33 |
+
}
|
34 |
+
|
35 |
/**
|
36 |
* Constructor
|
37 |
*/
|
38 |
+
public function __construct() {}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Setup actions and filters for all things settings
|
42 |
+
*/
|
43 |
+
public function setup() {
|
44 |
|
45 |
$this->data['settings'] = get_option( 'aws_settings' );
|
46 |
|
49 |
|
50 |
}
|
51 |
|
52 |
+
public function search( $keyword = '' ) {
|
|
|
|
|
|
|
53 |
|
54 |
global $wpdb;
|
55 |
|
56 |
$cache = AWS()->get_settings( 'cache' );
|
57 |
|
58 |
+
$s = $keyword ? esc_attr( $keyword ) : esc_attr( $_POST['keyword'] );
|
59 |
$s = stripslashes( $s );
|
60 |
$s = str_replace( array( "\r", "\n" ), '', $s );
|
61 |
|
67 |
// Check if value was already cached
|
68 |
if ($cached_value = get_option($cache_option_name)) {
|
69 |
$cached_value['cache'] = 'cached';
|
70 |
+
return $cached_value;
|
|
|
71 |
}
|
72 |
|
73 |
}
|
90 |
|
91 |
|
92 |
$this->data['s'] = $s;
|
93 |
+
$this->data['results_num'] = $results_num ? $results_num : 10;
|
94 |
$this->data['search_terms'] = array();
|
95 |
$this->data['search_terms'] = array_unique( explode( ' ', $s ) );
|
96 |
$this->data['search_in'] = $search_in_arr;
|
120 |
}
|
121 |
|
122 |
|
123 |
+
return $result_array;
|
124 |
+
|
125 |
+
}
|
126 |
+
|
127 |
+
/*
|
128 |
+
* AJAX call action callback
|
129 |
+
*/
|
130 |
+
public function action_callback() {
|
131 |
+
|
132 |
+
echo json_encode( $this->search() );
|
133 |
|
134 |
die;
|
135 |
|
296 |
|
297 |
foreach ( $posts_ids as $post_id ) {
|
298 |
|
299 |
+
$product = wc_get_product( $post_id );
|
300 |
|
301 |
$post_data = $product->get_post_data();
|
302 |
|
357 |
'categories' => $categories,
|
358 |
'tags' => $tags,
|
359 |
'on_sale' => $on_sale,
|
360 |
+
'sku' => $sku,
|
361 |
+
'post_data' => $post_data
|
362 |
);
|
363 |
|
364 |
$products_array[] = $new_result;
|
533 |
|
534 |
endif;
|
535 |
|
536 |
+
AWS_Search::factory();
|
537 |
|
538 |
+
function aws_search( $keyword = '' ) {
|
539 |
+
return AWS_Search::factory()->search( $keyword );
|
540 |
+
}
|
languages/aws.pot
CHANGED
@@ -54,6 +54,14 @@ msgid ""
|
|
54 |
" )"
|
55 |
msgstr ""
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
#: advanced-woo-search.php:127
|
58 |
msgid "Settings"
|
59 |
msgstr ""
|
54 |
" )"
|
55 |
msgstr ""
|
56 |
|
57 |
+
#: advanced-woo-search.php:113
|
58 |
+
msgid "Sale!"
|
59 |
+
msgstr ""
|
60 |
+
|
61 |
+
#: advanced-woo-search.php:114
|
62 |
+
msgid "Nothing found"
|
63 |
+
msgstr ""
|
64 |
+
|
65 |
#: advanced-woo-search.php:127
|
66 |
msgid "Settings"
|
67 |
msgstr ""
|
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.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -64,6 +64,10 @@ Or insert this function inside php file ( often it used to insert form inside pa
|
|
64 |
|
65 |
== Changelog ==
|
66 |
|
|
|
|
|
|
|
|
|
67 |
= 1.09 =
|
68 |
* Make indexing of the products content much more fuster
|
69 |
* Fix several bugs
|
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.7.1
|
7 |
+
Stable tag: 1.10
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
64 |
|
65 |
== Changelog ==
|
66 |
|
67 |
+
= 1.10 =
|
68 |
+
* Update search results page
|
69 |
+
* Fix some layout issues
|
70 |
+
|
71 |
= 1.09 =
|
72 |
* Make indexing of the products content much more fuster
|
73 |
* Fix several bugs
|