Skip to content

Commit

Permalink
WC Shipping Migration Flow
Browse files Browse the repository at this point in the history
* Define Feature Announcement component and open it on click [122] (#2743)

* Define Feature Announcement component and add the content

* Open the feature announcement modal when user clicks on Create shipping label

* Make the copy translatable

* Aknowledge eligibility when opening the feature announcement modal

* Add buttons and polish styling

* Disable the modal for the time being

* Add missing text and update styling

* Remove redundant argument in selector

* Add modal left column not taking 100% of the height

* Remove useCallback from stub function

* Revert code formatting back

* Fix/adjust how feature announcement looks on smaller screens (#2746)

* Fix how Feature Announcement component looks on smaller screens

* Remove excess space in closing tag

* Install and activate a list of plugins during migrations (#2745)

* Add @wordpress/api-fetch package

* Created a place holder button to test plugin activation

* Update shrinkwrap since we installed api-fetch

* Use hello-dolly to test install and activate

* Use native fetch instead of apiFetch

* Remove apiFetch package

* Fix < /p> to </p>

* Bind activation and installation to the update button

* Deactivate WCS&T after installing Woo Shipping and Woo Tax

* Disable is_eligible_for_migration

Don't enable migration yet.

* Redirect to plugins after installation

* Fix deactivateWCSTPluginAPICall to return promise

* Use relative path for the actions in feature-announcement

* Add adminPluginPath in the js global config.

* Execute each task in steps and throw exception if any fails

* Fix fill-rule to fillRule and clip-rule to clipRule (#2748)

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

* Add connect/migration-flag endpoint

* Set a flag "wcshipping_migrated" to indicate it is migrated

* is_eligible_for_migration() now checks for the config as well

* Add migration done API call to the update button

* Update migration flag to migration state

* Update space to tabs

* Call API to update migration status to "started"

* Update migration state to completed in plugin deactivation hook

* Default is_eligible_for_migration to return false

* Update API constants to something like an enum instead

* PHP cs fixes

* Return 200 if option updated, 304 otherwise

* Remove redundancy in condition

* Inline code comment can not be a DocBlock

* Remove redundant class_exists() check for the enum class

* Return 500 if update_option failed

* Add admin notice on orders page for WCShipping migration (#2751)

* Use current_screen hook to trigger the add admin notice hook

* Add dimissable

* Added a button for "Upgrade now"

* Update "Confirm update" style

* Fix spaces

* Fix indentation

* Fix whitespace for linting

* Screen ID not found if using HPOS, fixed

* Update learn more link

* Add a new function is_on_order_list_page() to check order list page

* Get the migration banner info from the connect server (#2752)

* Add note to README with a fix for `npm i` getting stuck

* Retrieves the migration banner info from WooCommerce Connect Server

* Address PR comments

* Get the flag to display the migration banner from the connect server (#2755)

* Refactor code checking whether or not to display a migration banner

* Address PR comments

* Change dismiss icon and behaviour [shipping-140] (#2758)

* Add is-dismissable and button label from server

* Register separate stylesheet and add stylings for the banner and buttons

* Add functionality to dismiss and remember dismissal

* Add state machine to drive migration states (#2757)

* Add state machine to drive migration states

* Rename state to better describe its name

* Refactor the API call out so the runNext function is decouple from API status check

* Update migration state enums to include all states in the machine

* Store the state in the wcshipping_migration_state option.

This allows us to remember where we were and we can always restart the
migration based on the last known state.

* Remove comment.

* Pass the wcshipping_migration_state option into the FeatureAnnouncement react component

* Fix a bug where restarting from an error state didn't proceed to the next state

* Return 304 if state is not modified instead of throwing 4xx.

* Fix 'wcshippingMigrationState' is already declared in the upper scope error

* Refactor the state machine logic into its own module

* Use wcs-client as path and re-enable redirection

* Added comments to the migration-runner module

* Apply suggestions from code review

Lint fixes.

Co-authored-by: Fernando Espinosa <Ferdev@users.noreply.github.com>

* Wait for the migration to finish before setting isUpdating back to false

* Return the fetch Response object instead

* Added a function to check if state exists before using it.

Throw exception otherwise.

* Update client/components/migration/migration-runner.js

* Update client/components/migration/migration-runner.js

* Update client/components/migration/migration-runner.js

---------

Co-authored-by: Fernando Espinosa <Ferdev@users.noreply.github.com>

* Add a "deactivated" message to the plugins list entry (#2759)

* Add a "deactivated" message to the plugins list entry

* Update woocommerce-services.php

Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>

* Address PR comments

* Remove redundant `esc_html`

* Customize the after_plugin_row action for this plugin only

* Fix background color of deactivated message

---------

Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>

* Load the FeatureAnnouncement modal to the order listing page (#2756)

* Load a new javascript file when migration admin notice shows up

* Load redux store for admin notice

The redux store inlcudes only the label shipping's reducer and the initial states.

* semi-colon gets rendered out. Removing.

* Fix style and setup initial data from the PHP's side

* Use wcs-client alias for webpack otherwise order list page can't find it

* Add baseURL and redirect URL through the proper enqueued scripts

* Move inline styles to the migration scss

* Clicking "Confirm update" will start the migration process

* Remove phpcs:ignore because it does have a version

* Use ID as the selector for the modal update button instead.

* Fix merge conflict issues with the existing css and js overlaps

* Change testing 10s back to 3 * 24 * 60 * 60

* Fix admin notice dimissible button and cleaned up jquery

* After clicking dimiss, remove itself from the DOM until 3 days later

* Add EOL to the js file.

* Change headers to a callback to retrieve getNonce() after dependencies are loaded

* Refactor cookie function to window.wpCookies

* Add tracking data for the migration process (#2760)

* Add tracking data for the migration process

* Remove debugging output

* Add update value to tracked data

* Clicking "Maybe later" will dismiss feature announcement for 3 days (#2762)

* Clicking "Maybe later" will dismiss the modal for 3 days

* Do not display modal if it's previously dismissed

* Don't show the modal if the page isn't refreshed

* EOL in new file

* Apply suggestions from code review

Lint fixes.

Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>

---------

Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>

* Save transients after a migration has been completed (#2763)

* Save transients after a migration has been completed

* Use general options instead of WooCommerce Shipping & Tax's options

* Cast the migration state to int now that is saved as a global option

* Remove wcshipping_migration_state as option name

* Add missing tracking data for the migration process (#2765)

* Update tracking data when the migration is completed

* Move plugin entry deactivated message to WooCommerce Shipping

* Add missing imports for tracks in a static method

* Remove db migration and deactivation (#2767)

* Skip db and deactivating plugin and finish the migration once activation is done

* Remove woocommerce-tax from the download and activation list

* Because WCS&T is no longer deactivated, we can update the migration state when it quits

* No longer need to rely on plugin_deactivation() to update the final migration state

* Adapt the migration banner popup to reusing WCS&T (#2769)

* Change copy in migration popup

* Improve copy in migration popup

* Provide public path to js entry files (#2770)

* Display migration banner on all WC settings page [shipping-152] (#2771)

* Show upgrade banner on shipping settings page as well

* Make sure clicking the confirm upgrade button doesn't refresh the page

* Show update banner on all settings pages

* Rebase `wcs-migration` branch onto `trunk` (#2783)

* Tweak/issue 2750 - WordPress 6.6 and WooCommerce 9.0 Compatibility (#2754)

* Bump tested up to version

* add changelog

* update readme file

* woorelease: Product version bump update

* Revert "woorelease: Product version bump update"

This reverts commit 122c7b3.

* woorelease: Product version bump update

* Revert "woorelease: Product version bump update"

This reverts commit 642db4f.

* woorelease: Product version bump update

* Fix/issue 2712 - Make The Tariff Number Field a Required Field when the Destination is Within EU (#2764)

* add condition for EU tariff number

* add changelog

* edit the tariff number error text

* edit changelog

* woorelease: Product version bump update

* Conditionally load shipping functionality based on if WC Shipping is active (#2761)

* Rough take

* Do not change the name, this is still called WooCommerce Shipping & Tax

* Set `wc_services_will_handle_coexistence_with_woo_shipping_and_woo_tax` hook to indicate we will handle the coexistence

* Remove WC_Connect_Note_DHL_Live_Rates_Available notice todo

My concern was about the class not existing and thereby creating PHP fatal errors, but we require the file right before using it, so there's no issue even if shipping has not been generally initiated.

* Remove outdated todos

* Status page should respect shipping conditional loading (#2776)

* Conditionally hide shipping related status data

* Satisfy tests

* Introduce new "wc_services_will_disable_shipping_logic" hook (#2775)

* Reimplement logic that completely blocks WCS&T logic from initiating

* Introduce new hook for conditional loading

---------

Co-authored-by: Gerhard <potgieterg@gmail.com>

* Add changelog for WC Shipping compatibility (#2779)

* Conditionally shows legacy reports shipping tab (#2780)

* woorelease: Product version bump update

* Define Feature Announcement component and open it on click [122] (#2743)

* Define Feature Announcement component and add the content

* Open the feature announcement modal when user clicks on Create shipping label

* Make the copy translatable

* Aknowledge eligibility when opening the feature announcement modal

* Add buttons and polish styling

* Disable the modal for the time being

* Add missing text and update styling

* Remove redundant argument in selector

* Add modal left column not taking 100% of the height

* Remove useCallback from stub function

* Revert code formatting back

* Fix/adjust how feature announcement looks on smaller screens (#2746)

* Fix how Feature Announcement component looks on smaller screens

* Remove excess space in closing tag

* Install and activate a list of plugins during migrations (#2745)

* Add @wordpress/api-fetch package

* Created a place holder button to test plugin activation

* Update shrinkwrap since we installed api-fetch

* Use hello-dolly to test install and activate

* Use native fetch instead of apiFetch

* Remove apiFetch package

* Fix < /p> to </p>

* Bind activation and installation to the update button

* Deactivate WCS&T after installing Woo Shipping and Woo Tax

* Disable is_eligible_for_migration

Don't enable migration yet.

* Redirect to plugins after installation

* Fix deactivateWCSTPluginAPICall to return promise

* Use relative path for the actions in feature-announcement

* Add adminPluginPath in the js global config.

* Execute each task in steps and throw exception if any fails

* Fix fill-rule to fillRule and clip-rule to clipRule (#2748)

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

* Add connect/migration-flag endpoint

* Set a flag "wcshipping_migrated" to indicate it is migrated

* is_eligible_for_migration() now checks for the config as well

* Add migration done API call to the update button

* Update migration flag to migration state

* Update space to tabs

* Call API to update migration status to "started"

* Update migration state to completed in plugin deactivation hook

* Default is_eligible_for_migration to return false

* Update API constants to something like an enum instead

* PHP cs fixes

* Return 200 if option updated, 304 otherwise

* Remove redundancy in condition

* Inline code comment can not be a DocBlock

* Remove redundant class_exists() check for the enum class

* Return 500 if update_option failed

* Add admin notice on orders page for WCShipping migration (#2751)

* Use current_screen hook to trigger the add admin notice hook

* Add dimissable

* Added a button for "Upgrade now"

* Update "Confirm update" style

* Fix spaces

* Fix indentation

* Fix whitespace for linting

* Screen ID not found if using HPOS, fixed

* Update learn more link

* Add a new function is_on_order_list_page() to check order list page

* Get the migration banner info from the connect server (#2752)

* Add note to README with a fix for `npm i` getting stuck

* Retrieves the migration banner info from WooCommerce Connect Server

* Address PR comments

* Get the flag to display the migration banner from the connect server (#2755)

* Refactor code checking whether or not to display a migration banner

* Address PR comments

* Change dismiss icon and behaviour [shipping-140] (#2758)

* Add is-dismissable and button label from server

* Register separate stylesheet and add stylings for the banner and buttons

* Add functionality to dismiss and remember dismissal

* Add state machine to drive migration states (#2757)

* Add state machine to drive migration states

* Rename state to better describe its name

* Refactor the API call out so the runNext function is decouple from API status check

* Update migration state enums to include all states in the machine

* Store the state in the wcshipping_migration_state option.

This allows us to remember where we were and we can always restart the
migration based on the last known state.

* Remove comment.

* Pass the wcshipping_migration_state option into the FeatureAnnouncement react component

* Fix a bug where restarting from an error state didn't proceed to the next state

* Return 304 if state is not modified instead of throwing 4xx.

* Fix 'wcshippingMigrationState' is already declared in the upper scope error

* Refactor the state machine logic into its own module

* Use wcs-client as path and re-enable redirection

* Added comments to the migration-runner module

* Apply suggestions from code review

Lint fixes.

Co-authored-by: Fernando Espinosa <Ferdev@users.noreply.github.com>

* Wait for the migration to finish before setting isUpdating back to false

* Return the fetch Response object instead

* Added a function to check if state exists before using it.

Throw exception otherwise.

* Update client/components/migration/migration-runner.js

* Update client/components/migration/migration-runner.js

* Update client/components/migration/migration-runner.js

---------

Co-authored-by: Fernando Espinosa <Ferdev@users.noreply.github.com>

* Add a "deactivated" message to the plugins list entry (#2759)

* Add a "deactivated" message to the plugins list entry

* Update woocommerce-services.php

Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>

* Address PR comments

* Remove redundant `esc_html`

* Customize the after_plugin_row action for this plugin only

* Fix background color of deactivated message

---------

Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>

* Load the FeatureAnnouncement modal to the order listing page (#2756)

* Load a new javascript file when migration admin notice shows up

* Load redux store for admin notice

The redux store inlcudes only the label shipping's reducer and the initial states.

* semi-colon gets rendered out. Removing.

* Fix style and setup initial data from the PHP's side

* Use wcs-client alias for webpack otherwise order list page can't find it

* Add baseURL and redirect URL through the proper enqueued scripts

* Move inline styles to the migration scss

* Clicking "Confirm update" will start the migration process

* Remove phpcs:ignore because it does have a version

* Use ID as the selector for the modal update button instead.

* Fix merge conflict issues with the existing css and js overlaps

* Change testing 10s back to 3 * 24 * 60 * 60

* Fix admin notice dimissible button and cleaned up jquery

* After clicking dimiss, remove itself from the DOM until 3 days later

* Add EOL to the js file.

* Change headers to a callback to retrieve getNonce() after dependencies are loaded

* Refactor cookie function to window.wpCookies

* Add tracking data for the migration process (#2760)

* Add tracking data for the migration process

* Remove debugging output

* Add update value to tracked data

* Clicking "Maybe later" will dismiss feature announcement for 3 days (#2762)

* Clicking "Maybe later" will dismiss the modal for 3 days

* Do not display modal if it's previously dismissed

* Don't show the modal if the page isn't refreshed

* EOL in new file

* Apply suggestions from code review

Lint fixes.

Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>

---------

Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>

* Save transients after a migration has been completed (#2763)

* Save transients after a migration has been completed

* Use general options instead of WooCommerce Shipping & Tax's options

* Cast the migration state to int now that is saved as a global option

* Remove wcshipping_migration_state as option name

* Add missing tracking data for the migration process (#2765)

* Update tracking data when the migration is completed

* Move plugin entry deactivated message to WooCommerce Shipping

* Add missing imports for tracks in a static method

* Remove db migration and deactivation (#2767)

* Skip db and deactivating plugin and finish the migration once activation is done

* Remove woocommerce-tax from the download and activation list

* Because WCS&T is no longer deactivated, we can update the migration state when it quits

* No longer need to rely on plugin_deactivation() to update the final migration state

* Adapt the migration banner popup to reusing WCS&T (#2769)

* Change copy in migration popup

* Improve copy in migration popup

* Provide public path to js entry files (#2770)

* Display migration banner on all WC settings page [shipping-152] (#2771)

* Show upgrade banner on shipping settings page as well

* Make sure clicking the confirm upgrade button doesn't refresh the page

* Show update banner on all settings pages

---------

Co-authored-by: Luthfi Bintoro <iyut85@yahoo.com>
Co-authored-by: Sam Najian <sam.najian@automattic.com>
Co-authored-by: Harris Wong <harris.wong@automattic.com>
Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>
Co-authored-by: Gerhard <potgieterg@gmail.com>
Co-authored-by: Sam Najian <dev.samnajian@gmail.com>

* Fix error launching the migration popup (#2784)

* Upgrade jetpack packages to version compatible with WCShipping (#2785)

* Use latest WP version for e2e tests

* Merge `trunk` into `wcs-migration` (#2795)

* Tweak/issue 2750 - WordPress 6.6 and WooCommerce 9.0 Compatibility (#2754)

* Bump tested up to version

* add changelog

* update readme file

* woorelease: Product version bump update

* Revert "woorelease: Product version bump update"

This reverts commit 122c7b3.

* woorelease: Product version bump update

* Revert "woorelease: Product version bump update"

This reverts commit 642db4f.

* woorelease: Product version bump update

* Fix/issue 2712 - Make The Tariff Number Field a Required Field when the Destination is Within EU (#2764)

* add condition for EU tariff number

* add changelog

* edit the tariff number error text

* edit changelog

* woorelease: Product version bump update

* Conditionally load shipping functionality based on if WC Shipping is active (#2761)

* Rough take

* Do not change the name, this is still called WooCommerce Shipping & Tax

* Set `wc_services_will_handle_coexistence_with_woo_shipping_and_woo_tax` hook to indicate we will handle the coexistence

* Remove WC_Connect_Note_DHL_Live_Rates_Available notice todo

My concern was about the class not existing and thereby creating PHP fatal errors, but we require the file right before using it, so there's no issue even if shipping has not been generally initiated.

* Remove outdated todos

* Status page should respect shipping conditional loading (#2776)

* Conditionally hide shipping related status data

* Satisfy tests

* Introduce new "wc_services_will_disable_shipping_logic" hook (#2775)

* Reimplement logic that completely blocks WCS&T logic from initiating

* Introduce new hook for conditional loading

---------

Co-authored-by: Gerhard <potgieterg@gmail.com>

* Add changelog for WC Shipping compatibility (#2779)

* Conditionally shows legacy reports shipping tab (#2780)

* woorelease: Product version bump update

* Update readme.txt to indicate that a new Woo Shipping plugin is available for download. (#2789)

* Update changelog

* Remove changelog and updated copy

* Make sure docker-compose command exists (#2793)

---------

Co-authored-by: Luthfi Bintoro <iyut85@yahoo.com>
Co-authored-by: Sam Najian <sam.najian@automattic.com>
Co-authored-by: Harris Wong <harris.wong@automattic.com>
Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>
Co-authored-by: Gerhard <potgieterg@gmail.com>
Co-authored-by: Sam Najian <dev.samnajian@gmail.com>

* Add a new widget in settings to start the migration (#2796)

* Add a new widget in settings to start the migration

* Add tracks event for migration settings widget

* Update changelog and readme

* Update changelog.txt copy

Update the copy to "A new migration experience from this plugin to the newly released WooCommerce Shipping plugin."

Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>

* Update feature announcement copy

* Do not test on SKU, woocommerce/woocommerce#47476 changed sku behaviour in tests

* Update version for migration work

---------

Co-authored-by: Sam Najian <dev.samnajian@gmail.com>
Co-authored-by: Harris Wong <harris.wong@automattic.com>
Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>
Co-authored-by: André Kallehauge <3846700+kallehauge@users.noreply.github.com>
Co-authored-by: Luthfi Bintoro <iyut85@yahoo.com>
Co-authored-by: Sam Najian <sam.najian@automattic.com>
  • Loading branch information
7 people authored Aug 27, 2024
1 parent 58630e1 commit 4168786
Show file tree
Hide file tree
Showing 34 changed files with 1,623 additions and 270 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ If you'd just like to check out the latest code and/or wish to contribute code,
* For Development: run `npm run up`, let the process finish, connect your site to Jetpack using Jurassic Tube or ngrok.
* For testing or pre-production use: Run `npm run dist` which will build the files into the `dist` folder, and will be loaded by the plugin without any additional configuration

## Security
*note*: if `npm install` gets stuck, you may have to update your GitHub urls in your git config. Use this command to fix it:

```git config --global url.https://github.com/.insteadOf git://github.com/```


## SECURITY

Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic).

Expand Down
51 changes: 51 additions & 0 deletions assets/stylesheets/migration_to_wcshipping_admin_notice.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Manunally load the migration component's style sheet because it is bundled(webpack)
// in style.css but style.css isn't loaded in the order listing page.
// This .scss file will be loaded so we are including it here.
@import 'components/migration/style';

.notice.wcst-wcshipping-migration-notice {
padding: 12px;
color: var(--Gutenberg-Gray-900, #1E1E1E);
font-size: 13px;
font-style: normal;
font-weight: 400;
line-height: 150%;

.wcst-wcshipping-migration-notice__content {
display: flex;
flex-direction: row;
margin-bottom: 12px;

p {
margin: 0;
flex-grow: 1;
}

.notice-dismiss {
width: 24px;
height: 24px;
padding: 0;
position: relative;

&:before {
content: '\f335';
color: #1E1E1E;
}
}

.hide-dismissible {
display: none;
}
}

.action-button {
color: #3858E9;
margin: 12px 0;
border: 1px solid #3858E9;
padding: 11.5px 12px 11.5px 12px;
border-radius: 2px;
background-color: #fff;
cursor: pointer;
margin: 0;
}
}
1 change: 1 addition & 0 deletions assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
@import 'components/dialog/style';
@import 'components/popover/style';
@import 'components/tooltip/style';
@import 'components/migration/style';

// Just the tooltip WordPress Component styles is all we use for now.
@import "~@wordpress/base-styles/colors";
Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** WooCommerce Shipping & Tax Changelog ***

= 2.8.0 - 2024-xx-xx =
* Add - A new migration experience from this plugin to the newly released WooCommerce Shipping plugin.

= 2.7.0 - 2024-07-25 =
* Add - Parallel compatibility with WooCommerce Shipping plugin.

Expand Down
21 changes: 12 additions & 9 deletions classes/class-wc-connect-account-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ public function get() {
$last_box_id = $last_box_id === 'individual' ? '' : $last_box_id;
$last_service_id = get_user_meta( get_current_user_id(), 'wc_connect_last_service_id', true );
$last_carrier_id = get_user_meta( get_current_user_id(), 'wc_connect_last_carrier_id', true );
$wcshipping_migration_state = intval( get_option( 'wcshipping_migration_state' ) );

return array(
'storeOptions' => $this->settings_store->get_store_options(),
'formData' => $this->settings_store->get_account_settings(),
'formMeta' => array(
'can_manage_payments' => $this->settings_store->can_user_manage_payment_methods(),
'can_edit_settings' => true,
'master_user_name' => $connection_owner ? $connection_owner->display_name : '',
'master_user_login' => $connection_owner ? $connection_owner->user_login : '',
'master_user_wpcom_login' => $connection_owner_wpcom_data ? $connection_owner_wpcom_data['login'] : '',
'master_user_email' => $connection_owner_wpcom_data ? $connection_owner_wpcom_data['email'] : '',
'payment_methods' => $this->payment_methods_store->get_payment_methods(),
'add_payment_method_url' => $this->payment_methods_store->get_add_payment_method_url(),
'warnings' => array( 'payment_methods' => $payment_methods_warning ),
'can_manage_payments' => $this->settings_store->can_user_manage_payment_methods(),
'can_edit_settings' => true,
'master_user_name' => $connection_owner ? $connection_owner->display_name : '',
'master_user_login' => $connection_owner ? $connection_owner->user_login : '',
'master_user_wpcom_login' => $connection_owner_wpcom_data ? $connection_owner_wpcom_data['login'] : '',
'master_user_email' => $connection_owner_wpcom_data ? $connection_owner_wpcom_data['email'] : '',
'payment_methods' => $this->payment_methods_store->get_payment_methods(),
'add_payment_method_url' => $this->payment_methods_store->get_add_payment_method_url(),
'warnings' => array( 'payment_methods' => $payment_methods_warning ),
'is_eligible_to_migrate' => $this->settings_store->is_eligible_for_migration(),
'wcshipping_migration_state' => $wcshipping_migration_state,
),
'userMeta' => array(
'last_box_id' => $last_box_id,
Expand Down
2 changes: 1 addition & 1 deletion classes/class-wc-connect-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
* @return array|WP_Error
*/
public function get_service_schemas() {
$response_body = $this->request( 'POST', '/services' );
$response_body = $this->request( 'POST', '/services', array( 'settings' => array( 'wcship_migration_supported' => true ) ) );

if ( is_wp_error( $response_body ) ) {
return $response_body;
Expand Down
6 changes: 3 additions & 3 deletions classes/class-wc-connect-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function is_active() {
public static function is_staging_site() {
$jetpack_status = new Status();

return $jetpack_status->is_staging_site();
return $jetpack_status->in_safe_mode();
}

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ public static function is_current_user_connection_owner() {
*/
public static function is_connected() {
return self::get_connection_manager()->is_connected() &&
self::get_connection_manager()->has_connected_owner();
self::get_connection_manager()->has_connected_owner();
}

/**
Expand All @@ -149,7 +149,7 @@ public static function connect_site( $redirect_url ) {
// phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- URL generated by the Jetpack Connection package.
wp_redirect(
add_query_arg(
[ 'from' => self::JETPACK_PLUGIN_SLUG ],
array( 'from' => self::JETPACK_PLUGIN_SLUG ),
$connection_manager->get_authorization_url( null, $redirect_url )
)
);
Expand Down
27 changes: 26 additions & 1 deletion classes/class-wc-connect-service-schemas-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function __construct( WC_Connect_API_Client $api_client, WC_Connect_Logge

$this->api_client = $api_client;
$this->logger = $logger;

}

public function fetch_service_schemas_from_connect_server() {
Expand Down Expand Up @@ -262,5 +261,31 @@ public function get_predefined_packages_schema() {

return $predefined_packages;
}

/**
* Returns the WooCommerce Shipping and WooCommerce Tax migration enabled status
*
* @return bool
*/
public function is_wcship_wctax_migration_enabled() {
$service_schemas = $this->get_service_schemas();

return is_object( $service_schemas ) && property_exists( $service_schemas, 'features' ) && property_exists( $service_schemas->features, 'wcshippingtax_upgrade_banner' ) && ! empty( $service_schemas->features->wcshippingtax_upgrade_banner );
}

/**
* Returns the WooCommerce Shipping and WooCommerce Tax upgrade banners
*
* @return object|null The banners schema or null if no such id was found
*/
public function get_wcship_wctax_upgrade_banner() {
$service_schemas = $this->get_service_schemas();

if ( $this->is_wcship_wctax_migration_enabled() ) {
return $service_schemas->features->wcshippingtax_upgrade_banner;
}

return null;
}
}
}
15 changes: 14 additions & 1 deletion classes/class-wc-connect-service-settings-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ protected function sort_services( $a, $b ) {
}

return ( $a->instance_id > $b->instance_id ) ? 1 : -1;

}

/**
Expand Down Expand Up @@ -617,6 +616,20 @@ public function get_package_lookup() {
return $lookup;
}

public function is_eligible_for_migration() {
$migration_dismissed = false;
if ( isset( $_COOKIE[ WC_Connect_Loader::MIGRATION_DISMISSAL_COOKIE_KEY ] ) && (int) $_COOKIE[ WC_Connect_Loader::MIGRATION_DISMISSAL_COOKIE_KEY ] === 1 ) {
$migration_dismissed = true;
}

$migration_state = get_option( 'wcshipping_migration_state' );

$migration_pending = ! $migration_state || WC_Connect_WCST_To_WCShipping_Migration_State_Enum::COMPLETED !== intval( $migration_state );
$migration_enabled = $this->service_schemas_store->is_wcship_wctax_migration_enabled();

return $migration_pending && $migration_enabled && ! $migration_dismissed;
}

private function translate_unit( $value ) {
switch ( $value ) {
case 'kg':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Enum for WCS&T to WCShipping migration states.
*/
class WC_Connect_WCST_To_WCShipping_Migration_State_Enum {
// These are used for WCS&T to WCShipping migration.
public const NOT_STARTED = 1;
public const STARTED = 2;
public const ERROR_STARTED = 3;
public const INSTALLING = 4;
public const ERROR_INSTALLING = 5;
public const ACTIVATING = 6;
public const ERROR_ACTIVATING = 7;
public const DB_MIGRATION = 8;
public const ERROR_DB_MIGRATION = 9;
public const DEACTIVATING = 10;
public const ERROR_DEACTIVATING = 11;
public const COMPLETED = 12;

public static function is_valid_value( $state ) {
$valid_states = array(
self::NOT_STARTED,
self::STARTED,
self::ERROR_STARTED,
self::INSTALLING,
self::ERROR_INSTALLING,
self::ACTIVATING,
self::ERROR_ACTIVATING,
self::DB_MIGRATION,
self::ERROR_DB_MIGRATION,
self::DEACTIVATING,
self::ERROR_DEACTIVATING,
self::COMPLETED,
);
return in_array( $state, $valid_states, true );
}
}
75 changes: 75 additions & 0 deletions classes/class-wc-rest-connect-migration-flag-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( class_exists( 'WC_REST_Connect_Migration_Flag_Controller' ) ) {
return;
}

class WC_REST_Connect_Migration_Flag_Controller extends WC_REST_Connect_Base_Controller {
protected $rest_base = 'connect/migration-flag';

/**
* Tracks instance.
*
* @var WC_Connect_Tracks
*/
protected $tracks;

public function __construct( $api_client, $settings_store, $logger, $tracks ) {
parent::__construct( $api_client, $settings_store, $logger );

$this->set_tracks( $tracks );
}

/**
* Set tracks instance.
*
* @param WC_Connect_Tracks $tracks Tracks instance.
*/
public function set_tracks( $tracks ) {
$this->tracks = $tracks;
}

public function post( $request ) {
$params = $request->get_json_params();
$migration_state = intval( $params['migration_state'] );
if ( ! WC_Connect_WCST_To_WCShipping_Migration_State_Enum::is_valid_value( $migration_state ) ) {
$error = new WP_Error(
'invalid_migration_state',
__( 'Invalid migration state. Can not update migration state.', 'woocommerce-services' ),
array( 'status' => 400 )
);
return $error;
}

$existing_migration_state = get_option( 'wcshipping_migration_state' );
if ( $existing_migration_state && intval( $existing_migration_state ) === $migration_state ) {
return new WP_REST_Response( array( 'result' => 'Migration flag is the same, no changes needed.' ), 304 );
}

$result = update_option( 'wcshipping_migration_state', $migration_state );

if ( $result ) {
$this->tracks->record_user_event(
'migration_flag_state_update',
array(
'migration_state' => $migration_state,
'updated' => $result,
)
);

return new WP_REST_Response( array( 'result' => 'Migration flag updated successfully.' ), 200 );
}

$error = new WP_Error(
'wcst_to_wcshipping_migration_failed_to_update',
__( 'Unable to update migration flag. The flag could not be updated.', 'woocommerce-services' ),
array( 'status' => 500 )
);
$this->logger->log( $error, __CLASS__ );
return $error;
}
}
2 changes: 2 additions & 0 deletions client/apps/shipping-settings/view-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import classNames from 'classnames';
*/
// from calypso
import GlobalNotices from 'components/global-notices';
import MigratorSettings from '../../extensions/woocommerce/woocommerce-services/views/migrator-settings';
import LabelSettings from '../../extensions/woocommerce/woocommerce-services/views/label-settings';
import notices from 'notices';
import Packages from '../../extensions/woocommerce/woocommerce-services/views/packages';
Expand Down Expand Up @@ -69,6 +70,7 @@ class LabelSettingsWrapper extends Component {
return (
<div>
<GlobalNotices id="notices" notices={ notices.list } />
<MigratorSettings />
<LabelSettings onChange={ this.onChange } />
<Packages onChange={ this.onChange } />
<LiveRatesCarriersList carrierIds={ liveRatesTypes } />
Expand Down
1 change: 1 addition & 0 deletions client/components/migration/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TIME_TO_REMMEMBER_DISMISSAL_SECONDS = 3 * 24 * 60 * 60; // 3 Days - number of seconds
Loading

0 comments on commit 4168786

Please sign in to comment.