Merge pull request #29043 from woocommerce/fix/25261
Fix price filtering when there are variations.
This commit is contained in:
commit
10f92ca091
|
@ -622,9 +622,9 @@ class WC_Query {
|
|||
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['where'] .= $wpdb->prepare(
|
||||
' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',
|
||||
$current_min_price,
|
||||
$current_max_price
|
||||
' AND NOT (%f<wc_product_meta_lookup.min_price OR %f>wc_product_meta_lookup.max_price ) ',
|
||||
$current_max_price,
|
||||
$current_min_price
|
||||
);
|
||||
return $args;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Tests for WC_Query.
|
||||
*/
|
||||
class WC_Query_Test extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox 'price_filter_post_clauses' generates the proper 'where' clause when there are 'max_price' and 'min_price' arguments in the query.
|
||||
*/
|
||||
public function test_price_filter_post_clauses_creates_the_proper_where_clause() {
|
||||
// phpcs:disable Squiz.Commenting
|
||||
$wp_query = new class() {
|
||||
public function is_main_query() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
// phpcs:enable Squiz.Commenting
|
||||
|
||||
$_GET['min_price'] = '100';
|
||||
$_GET['max_price'] = '200';
|
||||
|
||||
$sut = new WC_Query();
|
||||
|
||||
$args = array(
|
||||
'join' => '(JOIN CLAUSE)',
|
||||
'where' => '(WHERE CLAUSE)',
|
||||
);
|
||||
|
||||
$args = $sut->price_filter_post_clauses( $args, $wp_query );
|
||||
$expected = '(WHERE CLAUSE) AND NOT (200.000000<wc_product_meta_lookup.min_price OR 100.000000>wc_product_meta_lookup.max_price ) ';
|
||||
|
||||
$this->assertEquals( $expected, $args['where'] );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue