diff --git a/plugins/woocommerce/changelog/49244-fix-37940-remove-simple-products-from-variation-report b/plugins/woocommerce/changelog/49244-fix-37940-remove-simple-products-from-variation-report new file mode 100644 index 00000000000..b838c1ee429 --- /dev/null +++ b/plugins/woocommerce/changelog/49244-fix-37940-remove-simple-products-from-variation-report @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Exclude simple products from variations reports by default. \ No newline at end of file diff --git a/plugins/woocommerce/src/Admin/API/Reports/Variations/DataStore.php b/plugins/woocommerce/src/Admin/API/Reports/Variations/DataStore.php index 6b84a8c216d..ddcb6e048bf 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Variations/DataStore.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Variations/DataStore.php @@ -179,10 +179,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { if ( $included_variations ) { $this->subquery->add_sql_clause( 'where', "AND {$order_product_lookup_table}.variation_id IN ({$included_variations})" ); - } elseif ( ! $included_products ) { - if ( $this->should_exclude_simple_products( $query_args ) ) { - $this->subquery->add_sql_clause( 'where', "AND {$order_product_lookup_table}.variation_id != 0" ); - } + } elseif ( $this->should_exclude_simple_products( $query_args ) ) { + $this->subquery->add_sql_clause( 'where', "AND {$order_product_lookup_table}.variation_id != 0" ); } $order_status_filter = $this->get_status_subquery( $query_args ); diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-variations.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-variations.php index 499f2f3293e..d8906331c79 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-variations.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-variations.php @@ -88,6 +88,35 @@ class WC_Admin_Tests_API_Reports_Variations extends WC_REST_Unit_Test_Case { $this->assertArrayHasKey( 'variation', $variation_report['_links'] ); } + /** + * Test to confirm that simple products are excluded from the variations reports by default + */ + public function test_simple_products_excluded_from_variations_reports_by_default() { + wp_set_current_user( $this->user ); + WC_Helper_Reports::reset_stats_dbs(); + + $simple_product = WC_Helper_Product::create_simple_product(); + + $order = WC_Helper_Order::create_order( 1, $simple_product ); + $order->set_status( 'completed' ); + $order->set_total( 15 ); + $order->save(); + + WC_Helper_Queue::run_all_pending(); + + $request = new WP_REST_Request( 'GET', $this->endpoint ); + $request->set_query_params( + array( + 'product_includes' => $simple_product->get_id(), + ) + ); + $response = $this->server->dispatch( $request ); + $reports = $response->get_data(); + + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 0, count( $reports ) ); + } + /** * Test getting reports with the `variations` param. *