CYS - reset products and pattern when the site doesn't have AI generated content (#42970)
* CYS - reset products and pattern when the site doesn't have AI generated content * Add changefile(s) from automation for the following project(s): woocommerce * fix lint --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
2f2e573f48
commit
24d0fed8e5
|
@ -479,6 +479,17 @@ const resetPatternsAndProducts = () => async () => {
|
|||
woocommerce_blocks_allow_ai_connection: 'yes',
|
||||
} );
|
||||
|
||||
const response = await apiFetch< {
|
||||
is_ai_generated: boolean;
|
||||
} >( {
|
||||
path: '/wc/private/ai/store-info',
|
||||
method: 'GET',
|
||||
} );
|
||||
|
||||
if ( response.is_ai_generated ) {
|
||||
return;
|
||||
}
|
||||
|
||||
return Promise.all( [
|
||||
apiFetch( {
|
||||
path: '/wc/private/ai/patterns',
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: enhancement
|
||||
|
||||
CYS - Reset products and pattern when the site doesn't have AI generated content.
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\StoreApi\Routes\V1\AI;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Patterns\PatternsHelper;
|
||||
use Automattic\WooCommerce\Blocks\Patterns\ProductUpdater;
|
||||
use Automattic\WooCommerce\StoreApi\Routes\V1\AbstractRoute;
|
||||
|
||||
/**
|
||||
* StoreInfo class.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class StoreInfo extends AbstractRoute {
|
||||
/**
|
||||
* The route identifier.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const IDENTIFIER = 'ai/store-info';
|
||||
|
||||
/**
|
||||
* The schema item identifier.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SCHEMA_TYPE = 'ai/store-info';
|
||||
|
||||
/**
|
||||
* Get the path of this REST route.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_path() {
|
||||
return '/ai/store-info';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get method arguments for this REST route.
|
||||
*
|
||||
* @return array An array of endpoints.
|
||||
*/
|
||||
public function get_args() {
|
||||
return [
|
||||
[
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => [ $this, 'get_response' ],
|
||||
'permission_callback' => [ Middleware::class, 'is_authorized' ],
|
||||
],
|
||||
'schema' => [ $this->schema, 'get_public_item_schema' ],
|
||||
'allow_batch' => [ 'v1' => true ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the store title powered by AI.
|
||||
*
|
||||
* @param \WP_REST_Request $request Request object.
|
||||
*
|
||||
* @return bool|string|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
protected function get_route_response( \WP_REST_Request $request ) {
|
||||
$product_updater = new ProductUpdater();
|
||||
$patterns = PatternsHelper::get_patterns_ai_data_post();
|
||||
|
||||
$products = $product_updater->fetch_product_ids( 'dummy' );
|
||||
|
||||
if ( empty( $products ) && ! isset( $patterns ) ) {
|
||||
return rest_ensure_response(
|
||||
array(
|
||||
'is_ai_generated' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return rest_ensure_response(
|
||||
array(
|
||||
'is_ai_generated' => true,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -67,6 +67,7 @@ class RoutesController {
|
|||
Routes\V1\AI\Product::IDENTIFIER => Routes\V1\AI\Product::class,
|
||||
Routes\V1\AI\Products::IDENTIFIER => Routes\V1\AI\Products::class,
|
||||
Routes\V1\AI\BusinessDescription::IDENTIFIER => Routes\V1\AI\BusinessDescription::class,
|
||||
Routes\V1\AI\StoreInfo::IDENTIFIER => Routes\V1\AI\StoreInfo::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ class SchemaController {
|
|||
Schemas\V1\AI\ProductSchema::IDENTIFIER => Schemas\V1\AI\ProductSchema::class,
|
||||
Schemas\V1\AI\ProductsSchema::IDENTIFIER => Schemas\V1\AI\ProductsSchema::class,
|
||||
Schemas\V1\AI\BusinessDescriptionSchema::IDENTIFIER => Schemas\V1\AI\BusinessDescriptionSchema::class,
|
||||
Schemas\V1\AI\StoreInfoSchema::IDENTIFIER => Schemas\V1\AI\StoreInfoSchema::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
namespace Automattic\WooCommerce\StoreApi\Schemas\V1\AI;
|
||||
|
||||
use Automattic\WooCommerce\StoreApi\Schemas\V1\AbstractSchema;
|
||||
|
||||
/**
|
||||
* StoreInfoSchema class.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class StoreInfoSchema extends AbstractSchema {
|
||||
/**
|
||||
* The schema item name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'ai/store-info';
|
||||
|
||||
/**
|
||||
* The schema item identifier.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const IDENTIFIER = 'ai/store-info';
|
||||
|
||||
/**
|
||||
* Store Info schema properties.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_properties() {
|
||||
return [];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue