From c8f9d7673c17f94412127017f56b5ed89199e758 Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Mon, 25 Nov 2019 10:35:35 -0500 Subject: [PATCH] Fix notices and display issues that can occur when a WCCOM product api request fails (https://github.com/woocommerce/woocommerce-admin/pull/3291) --- .../profile-wizard/steps/product-types.js | 40 ++++++++++--------- .../src/Features/Onboarding.php | 13 ++++-- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/product-types.js b/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/product-types.js index 5e90191747c..21be2089aff 100644 --- a/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/product-types.js +++ b/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/product-types.js @@ -100,25 +100,27 @@ class ProductTypes extends Component {
{ Object.keys( productTypes ).map( slug => { - const helpText = interpolateComponents( { - mixedString: - productTypes[ slug ].description + - ( productTypes[ slug ].more_url ? ' {{moreLink/}}' : '' ), - components: { - moreLink: productTypes[ slug ].more_url ? ( - this.onLearnMore( slug ) } - > - { __( 'Learn more', 'woocommerce-admin' ) } - - ) : ( - '' - ), - }, - } ); + const helpText = + productTypes[ slug ].description && + interpolateComponents( { + mixedString: + productTypes[ slug ].description + + ( productTypes[ slug ].more_url ? ' {{moreLink/}}' : '' ), + components: { + moreLink: productTypes[ slug ].more_url ? ( + this.onLearnMore( slug ) } + > + { __( 'Learn more', 'woocommerce-admin' ) } + + ) : ( + '' + ), + }, + } ); return ( products as $product_datum ) { - $products[ $product_datum->id ] = $product_datum; + if ( isset( $product_data ) && isset( $product_data->products ) ) { + foreach ( $product_data->products as $product_datum ) { + if ( isset( $product_datum->id ) ) { + $products[ $product_datum->id ] = $product_datum; + } + } } // Loop over product types and append data. foreach ( $product_types as $key => $product_type ) { - if ( isset( $product_type['product'] ) ) { + if ( isset( $product_type['product'] ) && isset( $products[ $product_type['product'] ] ) ) { /* translators: Amount of product per year (e.g. Bookings - $240.00 per year) */ $product_types[ $key ]['label'] .= sprintf( __( ' — %s per year', 'woocommerce-admin' ), html_entity_decode( $products[ $product_type['product'] ]->price ) ); $product_types[ $key ]['description'] = $products[ $product_type['product'] ]->excerpt; $product_types[ $key ]['more_url'] = $products[ $product_type['product'] ]->link; + } elseif ( isset( $product_type['product'] ) ) { + /* translators: site currency symbol (used to show that the product costs money) */ + $product_types[ $key ]['label'] .= sprintf( __( ' — %s', 'woocommerce-admin' ), html_entity_decode( get_woocommerce_currency_symbol() ) ); } }