From 2341587cec42ff37c3030f3af00c56a1593ea896 Mon Sep 17 00:00:00 2001 From: Ruben Sargsyan Date: Fri, 7 Mar 2014 05:47:40 -0800 Subject: [PATCH 1/2] Price range widget checks variations too Fix for #800 --- .../widgets/price_range_widget.php | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/wpsc-components/theme-engine-v1/widgets/price_range_widget.php b/wpsc-components/theme-engine-v1/widgets/price_range_widget.php index a1a1fb0e0c..5489abbd7e 100755 --- a/wpsc-components/theme-engine-v1/widgets/price_range_widget.php +++ b/wpsc-components/theme-engine-v1/widgets/price_range_widget.php @@ -138,22 +138,31 @@ function wpsc_price_range( $args = null ) { } -if(isset($_GET['range'])){ +if ( isset( $_GET['range'] ) ) { add_filter( 'posts_where', 'wpsc_range_where' ); } function wpsc_range_where( $where ) { - global $wpdb, $wp_query; - $range = explode('-', $_GET['range']); - if(!strpos($where,'wpsc-product')) - return $where; - if(!$range[0]){ - $where .= " AND $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key=\"_wpsc_price\" AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") "; - }elseif(!$range[1]){ - $where .= " AND $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key=\"_wpsc_price\" AND $wpdb->postmeta.meta_value > " . ( $range[0]-1 ) . ") "; - }elseif($range[1] && $range[0]){ - $where .= " AND $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key=\"_wpsc_price\" AND $wpdb->postmeta.meta_value > " . ( $range[0]-1 ) . " AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") "; + global $wpdb; + + if ( ! strpos( $where, 'wpsc-product' ) ) { + return $where; + } + + $range = explode( '-', $_GET['range'] ); + + if ( empty( $range ) || $range[0] == 'all' ) { + return $where; + } + + if ( ! $range[0] ) { + $where .= " AND ( $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") OR $wpdb->posts.id IN ( SELECT $wpdb->posts.post_parent FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->posts.post_type = 'wpsc-product' AND $wpdb->posts.post_status = 'inherit' AND $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") ) "; + } elseif ( ! $range[1] ) { + $where .= " AND ( $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . ") OR $wpdb->posts.id IN ( SELECT $wpdb->posts.post_parent FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->posts.post_type = 'wpsc-product' AND $wpdb->posts.post_status = 'inherit' AND $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . ") ) "; + } elseif( $range[1] && $range[0] ) { + $where .= " AND ( $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . " AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") OR $wpdb->posts.id IN ( SELECT $wpdb->posts.post_parent FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->posts.post_type = 'wpsc-product' AND $wpdb->posts.post_status = 'inherit' AND $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . " AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") ) "; } + return $where; } -?> \ No newline at end of file +?> From c0f2c576a24dd97532597f5246a211dbae4030bf Mon Sep 17 00:00:00 2001 From: Ruben Sargsyan Date: Sat, 8 Mar 2014 09:04:51 -0800 Subject: [PATCH 2/2] strpos condition is changed Fix for #800 --- wpsc-components/theme-engine-v1/widgets/price_range_widget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpsc-components/theme-engine-v1/widgets/price_range_widget.php b/wpsc-components/theme-engine-v1/widgets/price_range_widget.php index 5489abbd7e..85b51b65fc 100755 --- a/wpsc-components/theme-engine-v1/widgets/price_range_widget.php +++ b/wpsc-components/theme-engine-v1/widgets/price_range_widget.php @@ -145,7 +145,7 @@ function wpsc_price_range( $args = null ) { function wpsc_range_where( $where ) { global $wpdb; - if ( ! strpos( $where, 'wpsc-product' ) ) { + if ( false === strpos( $where, 'wpsc-product' ) ) { return $where; }