13106 Dont round values in get_on_sale_products

This commit is contained in:
Claudiu Lodromanean 2017-02-07 13:46:00 -08:00
parent 5888ef5b93
commit 8ce5356943
2 changed files with 31 additions and 1 deletions

View File

@ -671,7 +671,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
AND meta2.meta_key = '_price' AND meta2.meta_key = '_price'
AND CAST( meta.meta_value AS DECIMAL ) >= 0 AND CAST( meta.meta_value AS DECIMAL ) >= 0
AND CAST( meta.meta_value AS CHAR ) != '' AND CAST( meta.meta_value AS CHAR ) != ''
AND CAST( meta.meta_value AS DECIMAL ) = CAST( meta2.meta_value AS DECIMAL ) AND CAST( meta.meta_value AS DECIMAL(10,2) ) = CAST( meta2.meta_value AS DECIMAL(10,2) )
GROUP BY post.ID; GROUP BY post.ID;
" ); " );
} }

View File

@ -349,4 +349,34 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
$_attribute = $loaded_variation->get_attributes( 'edit' ); $_attribute = $loaded_variation->get_attributes( 'edit' );
$this->assertEquals( 'green', $_attribute['color'] ); $this->assertEquals( 'green', $_attribute['color'] );
} }
function test_get_on_sale_products() {
$product_store = new WC_Product_Data_Store_CPT();
$sale_product = WC_Helper_Product::create_simple_product();
$sale_product->set_sale_price( 3.49 );
$sale_product->set_regular_price( 3.99 );
$sale_product->set_price( $sale_product->get_sale_price() );
$sale_product->save();
$not_sale_product = WC_Helper_Product::create_simple_product();
$not_sale_product->set_regular_price( 4.00 );
$not_sale_product->set_price( $not_sale_product->get_regular_price() );
$not_sale_product->save();
$future_sale_product = WC_Helper_Product::create_simple_product();
$future_sale_product->set_date_on_sale_from( 'tomorrow' );
$future_sale_product->set_regular_price( 6.49 );
$future_sale_product->set_sale_price( 5.99 );
$future_sale_product->set_price( $future_sale_product->get_regular_price() );
$future_sale_product->save();
$sale_products = $product_store->get_on_sale_products();
$sale_product_ids = array_map( function( $product ){ return $product->id; }, $sale_products );
$this->assertContains( $sale_product->get_id(), $sale_product_ids );
$this->assertNotContains( $not_sale_product->get_id(), $sale_product_ids );
$this->assertNotContains( $future_sale_product->get_id(), $sale_product_ids );
}
} }