[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:
parent
0a1c4a6920
commit
f46ffe1450
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: update
|
||||
|
||||
CYS: Proceed with product creation when their images fail to upload.
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue