Fix CYS updateStorePatters to use the new images endpoint structure (#43285)

* Return the correct empty images response

* Use the correct structure in the images endpoint response

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

* Throw error when no images and the store is already ai generated

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Alba Rincón 2024-01-05 17:56:51 +01:00 committed by GitHub
parent 6099718727
commit 5752bd7a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -238,7 +238,7 @@ export const updateStorePatterns = async (
const { images } = await apiFetch< {
ai_content_generated: boolean;
images: Array< unknown >;
images: { images: Array< unknown >; search_term: string };
} >( {
path: '/wc/private/ai/images',
method: 'POST',
@ -248,7 +248,20 @@ export const updateStorePatterns = async (
},
} );
if ( ! images.length ) {
const { is_ai_generated } = await apiFetch< {
is_ai_generated: boolean;
} >( {
path: '/wc/private/ai/store-info',
method: 'GET',
} );
if ( ! images.images.length ) {
if ( is_ai_generated ) {
throw new Error(
'AI content not generated: images not available'
);
}
await resetPatternsAndProducts()();
return;
}

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Use the new AI images endpoint response structure.

View File

@ -102,7 +102,10 @@ class Images extends AbstractRoute {
$images = ( new Pexels() )->get_images( $ai_connection, $token, $business_description );
if ( is_wp_error( $images ) ) {
$images = [];
$images = array(
'images' => array(),
'search_term' => '',
);
}
return rest_ensure_response(