From a7d34b22aaf5ffd3ec0d30c191fc10d5f6d57acc Mon Sep 17 00:00:00 2001 From: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com> Date: Thu, 14 Jul 2022 17:29:40 +0800 Subject: [PATCH] Remove query for products type in Shipping Task (#33886) --- .../changelog/update-shipping-task-view-logic | 4 +++ .../OnboardingTasks/Tasks/Shipping.php | 10 +----- .../onboarding-tasks/tasks/shipping.php | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 plugins/woocommerce/changelog/update-shipping-task-view-logic diff --git a/plugins/woocommerce/changelog/update-shipping-task-view-logic b/plugins/woocommerce/changelog/update-shipping-task-view-logic new file mode 100644 index 00000000000..c117630576f --- /dev/null +++ b/plugins/woocommerce/changelog/update-shipping-task-view-logic @@ -0,0 +1,4 @@ +Significance: minor +Type: performance + +Improve performance of Shipping Task. diff --git a/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Shipping.php b/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Shipping.php index 55aa8129f58..33a074baaac 100644 --- a/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Shipping.php +++ b/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Shipping.php @@ -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 ); } /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php index a2afc85fed2..47c623c58c9 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php @@ -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. */