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,25 +100,27 @@ 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 =
mixedString: productTypes[ slug ].description &&
productTypes[ slug ].description + interpolateComponents( {
( productTypes[ slug ].more_url ? ' {{moreLink/}}' : '' ), mixedString:
components: { productTypes[ slug ].description +
moreLink: productTypes[ slug ].more_url ? ( ( productTypes[ slug ].more_url ? ' {{moreLink/}}' : '' ),
<Link components: {
href={ productTypes[ slug ].more_url } moreLink: productTypes[ slug ].more_url ? (
target="_blank" <Link
type="external" href={ productTypes[ slug ].more_url }
onClick={ () => this.onLearnMore( slug ) } target="_blank"
> type="external"
{ __( 'Learn more', 'woocommerce-admin' ) } onClick={ () => this.onLearnMore( slug ) }
</Link> >
) : ( { __( 'Learn more', 'woocommerce-admin' ) }
'' </Link>
), ) : (
}, ''
} ); ),
},
} );
return ( return (
<CheckboxControl <CheckboxControl

View File

@ -310,17 +310,24 @@ class Onboarding {
$products = array(); $products = array();
// Map product data by ID. // Map product data by ID.
foreach ( $product_data->products as $product_datum ) { if ( isset( $product_data ) && isset( $product_data->products ) ) {
$products[ $product_datum->id ] = $product_datum; 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. // 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() ) );
} }
} }