Exclude simple products from variations reports by default (#49244)

* Make use of simple products exclusion filter regardless of included products

* Add unit test

* Add changefile(s) from automation for the following project(s): woocommerce

* Update reports-variations.php: Remove since comment

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
martynmjones 2024-07-09 10:48:05 +01:00 committed by GitHub
parent a5aef5f599
commit ab67891874
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 4 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Exclude simple products from variations reports by default.

View File

@ -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 );

View File

@ -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.
*