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:
parent
a5aef5f599
commit
ab67891874
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Exclude simple products from variations reports by default.
|
|
@ -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 );
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue