From 8ce5356943f8d6c4ce5e48c55cde4c384455ff5f Mon Sep 17 00:00:00 2001 From: Claudiu Lodromanean Date: Tue, 7 Feb 2017 13:46:00 -0800 Subject: [PATCH] 13106 Dont round values in get_on_sale_products --- .../class-wc-product-data-store-cpt.php | 2 +- tests/unit-tests/product/data-store.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 779f588ff07..268c9f3a563 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -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 CAST( meta.meta_value AS DECIMAL ) >= 0 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; " ); } diff --git a/tests/unit-tests/product/data-store.php b/tests/unit-tests/product/data-store.php index 936cbd2de62..8627029e611 100644 --- a/tests/unit-tests/product/data-store.php +++ b/tests/unit-tests/product/data-store.php @@ -349,4 +349,34 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case { $_attribute = $loaded_variation->get_attributes( 'edit' ); $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 ); + } }