[CYS] Proceed with product creation when their images fail to upload (#44031)

* Return error when the product creation fails

* Add changefile(s) from automation for the following project(s): woocommerce

* Continue with product creation even when the image upload fails

* Revert

* Add changefile(s) from automation for the following project(s): woocommerce

* Add changefile(s) from automation for the following project(s): woocommerce

* Add changefile(s) from automation for the following project(s): woocommerce

* Add a warning message with the error when creating the products with no images

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Alba Rincón 2024-01-25 12:49:45 +01:00 committed by GitHub
parent 0a1c4a6920
commit f46ffe1450
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 13 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
CYS: Proceed with product creation when their images fail to upload.

View File

@ -193,10 +193,6 @@ class UpdateProducts {
$image_alt = $product_data['title'];
$product_image_id = $this->product_image_upload( $product->get_id(), $image_src, $image_alt );
if ( is_wp_error( $product_image_id ) ) {
return new \WP_Error( 'error_uploading_image', $product_image_id->get_error_message() );
}
$saved_product = $this->product_update( $product, $product_image_id, $product_data['title'], $product_data['description'], $product_data['price'] );
if ( is_wp_error( $saved_product ) ) {
@ -294,10 +290,6 @@ class UpdateProducts {
$product_image_id = $this->product_image_upload( $product->get_id(), $ai_generated_product_content['image']['src'], $ai_generated_product_content['image']['alt'] );
if ( is_wp_error( $product_image_id ) ) {
return new \WP_Error( 'error_uploading_image', $product_image_id->get_error_message() );
}
$this->product_update( $product, $product_image_id, $ai_generated_product_content['title'], $ai_generated_product_content['description'], $ai_generated_product_content['price'] );
}
@ -470,10 +462,6 @@ class UpdateProducts {
$image_alt = self::DUMMY_PRODUCTS[ $i ]['title'];
$product_image_id = $this->product_image_upload( $product->get_id(), $image_src, $image_alt );
if ( is_wp_error( $product_image_id ) ) {
continue;
}
$this->product_update( $product, $product_image_id, self::DUMMY_PRODUCTS[ $i ]['title'], self::DUMMY_PRODUCTS[ $i ]['description'], self::DUMMY_PRODUCTS[ $i ]['price'] );
$i++;
@ -496,7 +484,17 @@ class UpdateProducts {
return new WP_Error( 'invalid_product', __( 'Invalid product.', 'woocommerce' ) );
}
$product->set_image_id( $product_image_id );
if ( ! is_wp_error( $product_image_id ) ) {
$product->set_image_id( $product_image_id );
} else {
wc_get_logger()->warning(
sprintf(
// translators: %s is a generated error message.
__( 'The image upload failed: "%s", creating the product without image', 'woocommerce' ),
$product_image_id->get_error_message()
),
);
}
$product->set_name( $product_title );
$product->set_description( $product_description );
$product->set_price( $product_price );