Fix Requested Changes

Changed to check if field exists and the field is not blank.
This commit is contained in:
Jack Boyle 2018-08-24 13:03:09 +10:00
parent fd33f2c2a6
commit 63b84ef407
3 changed files with 27 additions and 4 deletions

View File

@ -232,8 +232,15 @@ class WC_Data_Store_WP {
// Check for existing values if wildcard is used.
if ( '*' === $value ) {
$wp_query_args['meta_query'][] = array(
'key' => '_' . $key,
'compare' => 'EXISTS',
array(
'key' => '_' . $key,
'compare' => 'EXISTS',
),
array(
'key' => '_' . $key,
'value' => '',
'compare' => '!=',
),
);
} else {
$wp_query_args['meta_query'][] = array(

View File

@ -1631,8 +1631,15 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
// Check for existing values if wildcard is used.
if ( '*' === $manual_queries['sku'] ) {
$wp_query_args['meta_query'][] = array(
'key' => '_sku',
'compare' => 'EXISTS',
array(
'key' => '_sku',
'compare' => 'EXISTS',
),
array(
'key' => '_sku',
'value' => '',
'compare' => '!=',
),
);
} else {
$wp_query_args['meta_query'][] = array(

View File

@ -65,11 +65,20 @@ class WC_Tests_WC_Product_Query extends WC_Unit_Test_Case {
$results = $query->get_products();
$this->assertEquals( 1, count( $results ) );
$product3 = new WC_Product_Simple();
$product3->save();
// Get multiple products using wildcard.
$query = new WC_Product_Query();
$query->set( 'sku', '*' );
$results = $query->get_products();
$this->assertEquals( 2, count( $results ) );
// Test another field using wildcard.
$query = new WC_Product_Query();
$query->set( 'sale_price', '*' );
$results = $query->get_products();
$this->assertEquals( 2, count( $results ) );
}
/**