From 007bd21a35a5745f9ea75dc9c6b224cce37cf168 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Wed, 11 Sep 2024 15:39:28 +0800 Subject: [PATCH] Clean up purchase task (#51274) * Remove Purchase task * Add changelog --- .../changelog/update-remove-purchase-task | 4 + .../OnboardingTasks/Tasks/Purchase.php | 203 ------------------ .../onboarding-tasks/tasks/purchase.php | 186 ---------------- 3 files changed, 4 insertions(+), 389 deletions(-) create mode 100644 plugins/woocommerce/changelog/update-remove-purchase-task delete mode 100644 plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Purchase.php delete mode 100644 plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/purchase.php diff --git a/plugins/woocommerce/changelog/update-remove-purchase-task b/plugins/woocommerce/changelog/update-remove-purchase-task new file mode 100644 index 00000000000..20806d693a2 --- /dev/null +++ b/plugins/woocommerce/changelog/update-remove-purchase-task @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Clean up Purchase task diff --git a/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Purchase.php b/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Purchase.php deleted file mode 100644 index 2c9383f4a60..00000000000 --- a/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/Purchase.php +++ /dev/null @@ -1,203 +0,0 @@ -undo_dismiss(); - } - - /** - * Get the task arguments. - * ID. - * - * @return string - */ - public function get_id() { - return 'purchase'; - } - - /** - * Title. - * - * @return string - */ - public function get_title() { - $products = $this->get_paid_products_and_themes(); - $first_product = count( $products['purchaseable'] ) >= 1 ? $products['purchaseable'][0] : false; - - if ( ! $first_product ) { - return null; - } - - $product_label = isset( $first_product['label'] ) ? $first_product['label'] : $first_product['title']; - $additional_count = count( $products['purchaseable'] ) - 1; - - if ( $this->get_parent_option( 'use_completed_title' ) && $this->is_complete() ) { - return count( $products['purchaseable'] ) === 1 - ? sprintf( - /* translators: %1$s: a purchased product name */ - __( - 'You added %1$s', - 'woocommerce' - ), - $product_label - ) - : sprintf( - /* translators: %1$s: a purchased product name, %2$d the number of other products purchased */ - _n( - 'You added %1$s and %2$d other product', - 'You added %1$s and %2$d other products', - $additional_count, - 'woocommerce' - ), - $product_label, - $additional_count - ); - } - - return count( $products['purchaseable'] ) === 1 - ? sprintf( - /* translators: %1$s: a purchaseable product name */ - __( - 'Add %s to my store', - 'woocommerce' - ), - $product_label - ) - : sprintf( - /* translators: %1$s: a purchaseable product name, %2$d the number of other products to purchase */ - _n( - 'Add %1$s and %2$d more product to my store', - 'Add %1$s and %2$d more products to my store', - $additional_count, - 'woocommerce' - ), - $product_label, - $additional_count - ); - } - - /** - * Content. - * - * @return string - */ - public function get_content() { - $products = $this->get_paid_products_and_themes(); - - if ( count( $products['remaining'] ) === 1 ) { - return isset( $products['purchaseable'][0]['description'] ) ? $products['purchaseable'][0]['description'] : $products['purchaseable'][0]['excerpt']; - } - return sprintf( - /* translators: %1$s: list of product names comma separated, %2%s the last product name */ - __( - 'Good choice! You chose to add %1$s and %2$s to your store.', - 'woocommerce' - ), - implode( ', ', array_slice( $products['remaining'], 0, -1 ) ) . ( count( $products['remaining'] ) > 2 ? ',' : '' ), - end( $products['remaining'] ) - ); - } - - /** - * Action label. - * - * @return string - */ - public function get_action_label() { - return __( 'Purchase & install now', 'woocommerce' ); - } - - - /** - * Time. - * - * @return string - */ - public function get_time() { - return __( '2 minutes', 'woocommerce' ); - } - - /** - * Task completion. - * - * @return bool - */ - public function is_complete() { - $products = $this->get_paid_products_and_themes(); - return count( $products['remaining'] ) === 0; - } - - /** - * Dismissable. - * - * @return bool - */ - public function is_dismissable() { - return true; - } - - /** - * Task visibility. - * - * @return bool - */ - public function can_view() { - $products = $this->get_paid_products_and_themes(); - return count( $products['purchaseable'] ) > 0; - } - - /** - * Get purchaseable and remaining products. - * - * @return array purchaseable and remaining products and themes. - */ - public static function get_paid_products_and_themes() { - $relevant_products = OnboardingProducts::get_relevant_products(); - - $profiler_data = get_option( OnboardingProfile::DATA_OPTION, array() ); - $theme = isset( $profiler_data['theme'] ) ? $profiler_data['theme'] : null; - $paid_theme = $theme ? OnboardingThemes::get_paid_theme_by_slug( $theme ) : null; - if ( $paid_theme ) { - - $relevant_products['purchaseable'][] = $paid_theme; - - if ( isset( $paid_theme['is_installed'] ) && false === $paid_theme['is_installed'] ) { - $relevant_products['remaining'][] = $paid_theme['title']; - } - } - return $relevant_products; - } -} diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/purchase.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/purchase.php deleted file mode 100644 index 043052a0371..00000000000 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/purchase.php +++ /dev/null @@ -1,186 +0,0 @@ -task = new Purchase( new TaskList() ); - set_transient( - OnboardingThemes::THEMES_TRANSIENT, - array( - 'free' => array( - 'slug' => 'free', - 'is_installed' => false, - ), - 'paid' => array( - 'slug' => 'paid', - 'id' => 12312, - 'price' => '$79.00', - 'title' => 'theme title', - 'is_installed' => false, - ), - 'paid_installed' => array( - 'slug' => 'paid_installed', - 'id' => 12312, - 'price' => '$79.00', - 'title' => 'theme title', - 'is_installed' => true, - ), - 'free_with_price' => array( - 'slug' => 'free_with_price', - 'id' => 12312, - 'price' => '$0.00', - 'title' => 'theme title', - 'is_installed' => false, - ), - ) - ); - } - - /** - * Tear down. - */ - public function tearDown(): void { - parent::tearDown(); - delete_transient( OnboardingThemes::THEMES_TRANSIENT ); - delete_option( OnboardingProfile::DATA_OPTION ); - } - - /** - * Test is_complete function of Purchase task. - */ - public function test_is_complete_if_no_remaining_products() { - update_option( OnboardingProfile::DATA_OPTION, array( 'product_types' => array( 'physical' ) ) ); - $this->assertEquals( true, $this->task->is_complete() ); - } - - /** - * Test is_complete function of Purchase task. - */ - public function test_is_not_complete_if_remaining_paid_products() { - update_option( OnboardingProfile::DATA_OPTION, array( 'product_types' => array( 'memberships' ) ) ); - $this->assertEquals( false, $this->task->is_complete() ); - } - - /** - * Test is_complete function of Purchase task. - */ - public function test_is_complete_if_no_paid_themes() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array(), - 'theme' => 'free', - ) - ); - $this->assertEquals( true, $this->task->is_complete() ); - } - - /** - * Test is_complete function of Purchase task. - */ - public function test_is_not_complete_if_paid_theme_that_is_not_installed() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array(), - 'theme' => 'paid', - ) - ); - $this->assertEquals( false, $this->task->is_complete() ); - } - - /** - * Test is_complete function of Purchase task. - */ - public function test_is_complete_if_paid_theme_that_is_installed() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array(), - 'theme' => 'paid_installed', - ) - ); - $this->assertEquals( true, $this->task->is_complete() ); - } - - /** - * Test is_complete function of Purchase task. - */ - public function test_is_complete_if_free_theme_with_set_price() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array(), - 'theme' => 'free_with_price', - ) - ); - $this->assertEquals( true, $this->task->is_complete() ); - } - - /** - * Test the task title for a single paid item. - */ - public function test_get_title_if_single_paid_item() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array(), - 'theme' => 'paid', - ) - ); - $this->assertEquals( 'Add theme title to my store', $this->task->get_title() ); - } - - /** - * Test the task title if 2 paid items exist. - */ - public function test_get_title_if_multiple_paid_themes() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array( 'memberships' ), - 'theme' => 'paid', - ) - ); - $this->assertEquals( 'Add Memberships and 1 more product to my store', $this->task->get_title() ); - } - - /** - * Test the task title if multiple additional paid items exist. - */ - public function test_get_title_if_multiple_paid_products() { - update_option( - OnboardingProfile::DATA_OPTION, - array( - 'product_types' => array( 'memberships', 'bookings' ), - 'theme' => 'paid', - ) - ); - $this->assertEquals( 'Add Memberships and 2 more products to my store', $this->task->get_title() ); - } -}