Remove query for products type in Shipping Task (#33886)

This commit is contained in:
Adrian Duffell 2022-07-14 17:29:40 +08:00 committed by GitHub
parent 5093710ad4
commit a7d34b22aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 9 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: performance
Improve performance of Shipping Task.

View File

@ -174,15 +174,7 @@ class Shipping extends Task {
$profiler_data = get_option( OnboardingProfile::DATA_OPTION, array() );
$product_types = isset( $profiler_data['product_types'] ) ? $profiler_data['product_types'] : array();
return in_array( 'physical', $product_types, true ) ||
count(
wc_get_products(
array(
'virtual' => false,
'limit' => 1,
)
)
) > 0;
return in_array( 'physical', $product_types, true );
}
/**

View File

@ -61,6 +61,37 @@ class WC_Admin_Tests_OnboardingTasks_Task_Shipping extends WC_Unit_Test_Case {
return array_merge( $features, array( 'shipping-smart-defaults' ) );
}
/**
* Test can_view function of task when store only sells physical products.
*/
public function test_can_view_return_true_when_sell_only_physical_type() {
update_option(
OnboardingProfile::DATA_OPTION,
array(
'product_types' => array(
'physical',
),
)
);
$this->assertEquals( $this->task->can_view(), true );
}
/**
* Test can_view function of task when store sells physical and digital products.
*/
public function test_can_view_return_true_when_sell_physical_and_digital_type() {
update_option(
OnboardingProfile::DATA_OPTION,
array(
'product_types' => array(
'physical',
'digital',
),
)
);
$this->assertEquals( $this->task->can_view(), true );
}
/**
* Test can_view function of task when store only sells digital products.
*/