From fda300ff4fb6c1338b578df12da60152e1d9fc7e Mon Sep 17 00:00:00 2001 From: Moon Date: Wed, 17 Mar 2021 01:22:33 -0700 Subject: [PATCH] Improve WC Shipping & Tax logic (https://github.com/woocommerce/woocommerce-admin/pull/6547) * Improve WC Shipping & Tax logic * Add changelog * Simplify return statement * Add test for filtering selected extensions * Fix broken test --- .../woocommerce-admin/TESTING-INSTRUCTIONS.md | 29 ++++++++++ .../flows/selective-bundle/index.js | 31 ++++++++--- .../selective-extensions-bundle/index.js | 53 ++++++++++++++++--- .../steps/business-details/test/index.js | 34 ++++++++++++ .../packages/data/src/plugins/constants.js | 8 +++ plugins/woocommerce-admin/readme.txt | 1 + .../complete-business-section.js | 2 +- 7 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 plugins/woocommerce-admin/client/profile-wizard/steps/business-details/test/index.js diff --git a/plugins/woocommerce-admin/TESTING-INSTRUCTIONS.md b/plugins/woocommerce-admin/TESTING-INSTRUCTIONS.md index d1895c21302..d55ac87f0bf 100644 --- a/plugins/woocommerce-admin/TESTING-INSTRUCTIONS.md +++ b/plugins/woocommerce-admin/TESTING-INSTRUCTIONS.md @@ -117,6 +117,35 @@ UPDATE `wp_options` SET `option_value`=UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 ``` - No note should have been added. +### Improve WC Shipping & Tax logic #6547 + +**Scenario 1** - Exclude the WooCommerce Shipping mention if the user is not in the US + +1. Start OBW and enter an address that is not in the US +2. Choose "food and drink" from the Industry (this forces Business Details to display "Free features" tab) +3. When you get to the "Business Details", click "Free features" +4. Expand "Add recommended business features to my site" by clicking the down arrow. +5. Confirm that "WooCommerce Shipping" is not listed + +**Scenario 2**- Exclude the WooCommerce Shipping mention if the user is in the US but only selected digital products in the Product Types step + +1. Start OBW and enter an address that is in the US. +2. Choose "food and drink" from the Industry (this forces Business Details to display the "Free features" tab) +3. Choose "Downloads" from the Product Types step. +4. When you get to the Business Details step, expand "Add recommended business features to my site" by clicking the down arrow. +5. Confirm that "WooCommerce Shipping" is not listed + +**Scenario 3** - Include WooCommerce Tax if the user is in one of the following countries: US | FR | GB | DE | CA | PL | AU | GR | BE | PT | DK | SE + +1. Start OBW and enter an address that is in one of the following countries + + US | FR | GB | DE | CA | PL | AU | GR | BE | PT | DK | SE + +2. Continue to the Business Details step. +3. Expand "Add recommended business features to my site" by clicking the down arrow. +4. Confirm that "WooCommerce Tax" is listed. +>>>>>>> bbeebaf91 (Add changelog) + ### Use wc filter to get status tabs for tools category #6525 1. Register a new tab via the filter. diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js index 70311332b94..aa9af3e77e3 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js @@ -36,6 +36,26 @@ import './style.scss'; const BUSINESS_DETAILS_TAB_NAME = 'business-details'; const FREE_FEATURES_TAB_NAME = 'free-features'; +export const filterBusinessExtensions = ( extensionInstallationOptions ) => { + return ( + Object.keys( extensionInstallationOptions ) + .filter( + ( key ) => + extensionInstallationOptions[ key ] && + key !== 'install_extensions' + ) + .map( ( key ) => { + // Remove anything after : + // Please refer to selective-extensions-bundle/index.js + // installableExtensions variable + // this is to allow duplicate slugs (Tax & Shipping for example) + return key.split( ':' )[ 0 ]; + } ) + // remove duplicate + .filter( ( item, index, arr ) => arr.indexOf( item ) === index ) + ); +}; + class BusinessDetails extends Component { constructor() { super(); @@ -69,12 +89,8 @@ class BusinessDetails extends Component { const { getCurrencyConfig } = this.context; - const businessExtensions = Object.keys( + const businessExtensions = filterBusinessExtensions( extensionInstallationOptions - ).filter( - ( key ) => - extensionInstallationOptions[ key ] && - key !== 'install_extensions' ); recordEvent( 'storeprofiler_store_business_features_continue', { @@ -88,7 +104,9 @@ class BusinessDetails extends Component { extensionInstallationOptions ).every( ( val ) => val ), install_woocommerce_services: - extensionInstallationOptions[ 'woocommerce-services' ], + extensionInstallationOptions[ + 'woocommerce-services:shipping' + ] || extensionInstallationOptions[ 'woocommerce-services:tax' ], install_mailchimp: extensionInstallationOptions[ 'mailchimp-for-woocommerce' ], install_mailpoet: extensionInstallationOptions.mailpoet, @@ -413,6 +431,7 @@ class BusinessDetails extends Component { onSubmit={ this.onContinue } country={ country } industry={ profileItems.industry } + productTypes={ profileItems.product_types } /> ); diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js index 74027854030..106d2cfb396 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/selective-extensions-bundle/index.js @@ -68,7 +68,7 @@ const installableExtensions = [ }, }, { - slug: 'woocommerce-services', + slug: 'woocommerce-services:shipping', description: generatePluginDescriptionWithLink( __( 'Print shipping labels with {{link}}WooCommerce Shipping{{/link}}', @@ -76,6 +76,40 @@ const installableExtensions = [ ), 'shipping' ), + isVisible: ( countryCode, industry, productTypes ) => { + return ( + countryCode === 'US' || + ( countryCode === 'US' && + productTypes.length === 1 && + productTypes[ 0 ] === 'downloads' ) + ); + }, + }, + { + slug: 'woocommerce-services:tax', + description: generatePluginDescriptionWithLink( + __( + 'Get automated sales tax with {{link}}WooCommerce Tax{{/link}}', + 'woocommerce-admin' + ), + 'tax' + ), + isVisible: ( countryCode ) => { + return [ + 'US', + 'FR', + 'GB', + 'DE', + 'CA', + 'PL', + 'AU', + 'GR', + 'BE', + 'PT', + 'DK', + 'SE', + ].includes( countryCode ); + }, }, { slug: 'jetpack', @@ -255,16 +289,18 @@ const BundleExtensionCheckbox = ( { onChange, description, isChecked } ) => { * Returns plugins that either don't have the acceptedCountryCodes param or one defined * that includes the passed in country. * - * @param {Array} plugins list of plugins + * @param {Array} plugins list of plugins * @param {string} country Woo store country - * @param {Array} industry List of selected industries + * @param {Array} industry List of selected industries + * @param {Array} productTypes List of selected product types */ -const getVisiblePlugins = ( plugins, country, industry ) => { +const getVisiblePlugins = ( plugins, country, industry, productTypes ) => { const countryCode = getCountryCode( country ); return plugins.filter( ( plugin ) => - ! plugin.isVisible || plugin.isVisible( countryCode, industry ) + ! plugin.isVisible || + plugin.isVisible( countryCode, industry, productTypes ) ); }; @@ -273,6 +309,7 @@ export const SelectiveExtensionsBundle = ( { onSubmit, country, industry, + productTypes, } ) => { const [ showExtensions, setShowExtensions ] = useState( false ); const [ values, setValues ] = useState( {} ); @@ -283,7 +320,8 @@ export const SelectiveExtensionsBundle = ( { const plugins = getVisiblePlugins( curr.plugins, country, - industry + industry, + productTypes ).reduce( ( pluginAcc, { slug } ) => { return { ...pluginAcc, [ slug ]: true }; }, {} ); @@ -370,7 +408,8 @@ export const SelectiveExtensionsBundle = ( { { getVisiblePlugins( plugins, country, - industry + industry, + productTypes ).map( ( { description, slug } ) => ( { + test( 'filtering extensions', () => { + const extensions = { + 'creative-mail-by-constant-contact': true, + 'facebook-for-woocommerce': true, + install_extensions: true, + jetpack: true, + 'kliken-marketing-for-google': true, + 'mailchimp-for-woocommerce': true, + 'woocommerce-payments': true, + 'woocommerce-services:shipping': true, + 'woocommerce-services:tax': true, + }; + + const expectedExtensions = [ + 'creative-mail-by-constant-contact', + 'facebook-for-woocommerce', + 'jetpack', + 'kliken-marketing-for-google', + 'mailchimp-for-woocommerce', + 'woocommerce-payments', + 'woocommerce-services', + ]; + + const filteredExtensions = filterBusinessExtensions( extensions ); + + expect( filteredExtensions ).toEqual( expectedExtensions ); + } ); +} ); diff --git a/plugins/woocommerce-admin/packages/data/src/plugins/constants.js b/plugins/woocommerce-admin/packages/data/src/plugins/constants.js index cdd42688582..39bc4e2e8c8 100644 --- a/plugins/woocommerce-admin/packages/data/src/plugins/constants.js +++ b/plugins/woocommerce-admin/packages/data/src/plugins/constants.js @@ -48,6 +48,14 @@ export const pluginNames = { 'WooCommerce Shipping & Tax', 'woocommerce-admin' ), + 'woocommerce-services:shipping': __( + 'WooCommerce Shipping & Tax', + 'woocommerce-admin' + ), + 'woocommerce-services:tax': __( + 'WooCommerce Shipping & Tax', + 'woocommerce-admin' + ), 'woocommerce-shipstation-integration': __( 'WooCommerce ShipStation Gateway', 'woocommerce-admin' diff --git a/plugins/woocommerce-admin/readme.txt b/plugins/woocommerce-admin/readme.txt index 38b9ce16dd5..1e4ad4a7093 100644 --- a/plugins/woocommerce-admin/readme.txt +++ b/plugins/woocommerce-admin/readme.txt @@ -83,6 +83,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt - Fix: Add gross sales column to CSV export #6567 - Dev: Add filter to profile wizard steps #6564 - Tweak: Adjust targeting store age for the Add First Product note #6554 +- Tweak: Improve WC Shipping & Tax logic #6547 - Dev: Add nav intro modal tests #6518 - Dev: Use wc filter to get status tabs for tools category #6525 - Tweak: Remove mobile activity panel toggle #6539 diff --git a/plugins/woocommerce-admin/tests/e2e/specs/activate-and-setup/complete-business-section.js b/plugins/woocommerce-admin/tests/e2e/specs/activate-and-setup/complete-business-section.js index 07efbafc958..e597bc65036 100644 --- a/plugins/woocommerce-admin/tests/e2e/specs/activate-and-setup/complete-business-section.js +++ b/plugins/woocommerce-admin/tests/e2e/specs/activate-and-setup/complete-business-section.js @@ -75,7 +75,7 @@ export async function unselectAllFeaturesAndContinue( await waitForElementCount( page, '.components-checkbox-control__input', - shouldWCPayBeListed ? 9 : 8 + shouldWCPayBeListed ? 10 : 7 ); const wcPayLabel = await getElementByText( 'a', 'WooCommerce Payments' ); if ( shouldWCPayBeListed ) {