Fix notices and display issues that can occur when a WCCOM product api request fails (https://github.com/woocommerce/woocommerce-admin/pull/3291)

This commit is contained in:
Justin Shreve 2019-11-25 10:35:35 -05:00 committed by GitHub
parent c5f0fa90b2
commit c8f9d7673c
2 changed files with 31 additions and 22 deletions

View File

@ -100,7 +100,9 @@ class ProductTypes extends Component {
<Card> <Card>
<div className="woocommerce-profile-wizard__checkbox-group"> <div className="woocommerce-profile-wizard__checkbox-group">
{ Object.keys( productTypes ).map( slug => { { Object.keys( productTypes ).map( slug => {
const helpText = interpolateComponents( { const helpText =
productTypes[ slug ].description &&
interpolateComponents( {
mixedString: mixedString:
productTypes[ slug ].description + productTypes[ slug ].description +
( productTypes[ slug ].more_url ? ' {{moreLink/}}' : '' ), ( productTypes[ slug ].more_url ? ' {{moreLink/}}' : '' ),

View File

@ -310,17 +310,24 @@ class Onboarding {
$products = array(); $products = array();
// Map product data by ID. // Map product data by ID.
if ( isset( $product_data ) && isset( $product_data->products ) ) {
foreach ( $product_data->products as $product_datum ) { foreach ( $product_data->products as $product_datum ) {
if ( isset( $product_datum->id ) ) {
$products[ $product_datum->id ] = $product_datum; $products[ $product_datum->id ] = $product_datum;
} }
}
}
// Loop over product types and append data. // Loop over product types and append data.
foreach ( $product_types as $key => $product_type ) { 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) */ /* 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 ]['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 ]['description'] = $products[ $product_type['product'] ]->excerpt;
$product_types[ $key ]['more_url'] = $products[ $product_type['product'] ]->link; $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() ) );
} }
} }