Automattic / woocommerce-services

WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
GNU General Public License v2.0
107 stars 20 forks source link

Set a flag to indicate migration has started or has completed #2747

Closed harriswong closed 3 months ago

harriswong commented 3 months ago

Description

Upon clicking "Update now", this PR sets the migration state to MIGRATION_STATE_STARTED (2) before the migration begins. Then, the plugin install, activates WooCommerce Shipping and WooCommerce Tax. Followed by deactivating WCS&T. When it's done, it sets the migration state to MIGRATION_STATE_COMPLETED (3).

Related issue(s)

NA

Steps to reproduce & screenshots/GIFs

  1. Pull this branch, make sure you already have your WCS&T, Woo Shipping, Woo Tax setup in the plugins folder. Note, we can't test "install" because these aren't found on .org yet. If you want to test the install steps, you can test it with the "hello-dolly" plugin as described here https://github.com/Automattic/woocommerce-services/pull/2745.
  2. Open classes/class-wc-connect-service-settings-store.php and change is_eligible_for_migration() to return true. Something like this return $migration_state !== WC_Connect_API_Constants::MIGRATION_STATE_COMPLETED && true;. The true flag mimic the connect server's flag.
  3. Go to any order page and click "Create shipping label" image
  4. You should see the migration modal, click F12 to see the network tab in console. And click "Update now" image
  5. Confirm you are being redirected to plugins page and both WooCommerce Shipping and WooCommerce Tax are activated; while WCS&T is deactivated. Confirm that you are seeing the 4 requests in the network tab. image
  6. [bonus] Check your database table wp_options where name =wc_connect_options. In the serialized option_value, you should see "wcshipping_migration_state";i:3;.

Re-running the test

This PR sets a flag wcshipping_migration_state so once you "completed" migration, the modal won't show up again. To get around this, add WC_Connect_Options::delete_option('wcshipping_migration_state'); to the is_eligible_for_migration() function so it will always delete the option first. For example, my local dev testing function looks like this:

        public function is_eligible_for_migration() {
            WC_Connect_Options::delete_option('wcshipping_migration_state');
            $migration_state = WC_Connect_Options::get_option( 'wcshipping_migration_state' );
            //TODO: Check against the connect-server flag
            return $migration_state !== WC_Connect_API_Constants::MIGRATION_STATE_COMPLETED && true;
        }

Checklist

harriswong commented 3 months ago

👋 Hi @waclawjacek, I responded to all the comments. There are 2 remaining items to be discussed:

  1. Should we use a standalone option instead of using WC_Connect_Options::update_option?
  2. For the various states, are we okay to group that work into issue 134?

Please take another look!

harriswong commented 3 months ago

👋 Hey @waclawjacek , I have addressed all your comments, please take another look!