* Improve WC Shipping & Tax logic

* Add changelog

* Simplify return statement

* Add test for filtering selected extensions

* Fix broken test
This commit is contained in:
Moon 2021-03-17 01:22:33 -07:00 committed by GitHub
parent 6b3fe5c475
commit fda300ff4f
7 changed files with 144 additions and 14 deletions

View File

@ -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.

View File

@ -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 }
/>
</>
);

View File

@ -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',
@ -258,13 +292,15 @@ const BundleExtensionCheckbox = ( { onChange, description, isChecked } ) => {
* @param {Array} plugins list of plugins
* @param {string} country Woo store country
* @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 } ) => (
<BundleExtensionCheckbox
key={ slug }

View File

@ -0,0 +1,34 @@
/**
* Internal dependencies
*/
import { filterBusinessExtensions } from '../flows/selective-bundle';
describe( 'BusinessDetails', () => {
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 );
} );
} );

View File

@ -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'

View File

@ -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

View File

@ -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 ) {