Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Store Customization > Update products with AI generated content (#11155)
Browse files Browse the repository at this point in the history
* Introduce the ProductUpdater class.

* Update the image assignment for the default products content.

* Update the default products content.

* Introduce the generate_content and get_placeholder_products methods.

* Update the get_placeholder_products method and introduce the new create_new_product method.

* Verify the hash of the product content and compare it with the hash of the ai generated content to ensure we wont override products modified by the store owner.

* Add docblocks and update the structure for the ProductUpdater class.

* Pass the vertical images as a param for the PatternUpdater and the ProductUpdater.

* Update the provided variable to the PatternUpdater class.

* Update the ProductUpdater class to include the requirements for usage of the media_sideload_image method outside the wp-admin area (via API) and other adjustments to the products generation and hashes

* remove unnecessary calls to post/product images.

* Update the loop for generating products.

* Further adjustments to the Product Updater.

* Provide the business_description as a param for the generate_content ProductUpdates

* Update the default timeout for the AI connection; update the path to the default image. Add a limit of 6 when quering the total products created by the store owner.

* Add new neutral placeholder images for products and patterns.

* Update the prompt and the logic for the placeholder images.

* Remove placeholder images.

* Increase max execution time

* Update the products query.

* Move the media_sideload_image function dependencies to outside of the loop and add comment.

* Update text content.

* Address code review.

* bail early if no business description provided.

* Add an extra safety check in case of query errors.

* Address CR.
  • Loading branch information
nefeline authored and gigitux committed Oct 25, 2023
1 parent db3ab92 commit 131bb84
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Automattic\WooCommerce\Blocks\Domain\Package;
use Automattic\WooCommerce\Blocks\Patterns\PatternUpdater;
use Automattic\WooCommerce\Blocks\Patterns\ProductUpdater;
use Automattic\WooCommerce\Blocks\Verticals\Client;
use Automattic\WooCommerce\Blocks\Verticals\VerticalsSelector;

Expand Down Expand Up @@ -279,8 +280,10 @@ public function update_patterns_content( $value ) {
return $vertical_id;
}

$vertical_images = ( new Client() )->get_vertical_images( $vertical_id );
$business_description = get_option( VerticalsSelector::STORE_DESCRIPTION_OPTION_KEY );

return ( new PatternUpdater() )->create_patterns_content( $vertical_id, new Client(), $business_description );
( new PatternUpdater() )->generate_content( $vertical_images, $business_description );
( new ProductUpdater() )->generate_content( $vertical_images, $business_description );
}
}
13 changes: 3 additions & 10 deletions src/Patterns/PatternUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,12 @@ public function __construct() {
/**
* Creates the patterns content for the given vertical.
*
* @param int $vertical_id The vertical id.
* @param Client $verticals_api_client The verticals API client.
* @param string $business_description The business description.
* @param array|WP_Error $vertical_images The array of vertical images.
* @param string $business_description The business description.
*
* @return bool|WP_Error
*/
public function create_patterns_content( $vertical_id, $verticals_api_client, $business_description = '' ) {
if ( ! is_int( $vertical_id ) ) {
return new WP_Error( 'invalid_vertical_id', __( 'The vertical id is invalid.', 'woo-gutenberg-products-block' ) );
}

$vertical_images = $verticals_api_client->get_vertical_images( $vertical_id );

public function generate_content( $vertical_images, $business_description ) {
if ( is_wp_error( $vertical_images ) ) {
return $vertical_images;
}
Expand Down
Loading

0 comments on commit 131bb84

Please sign in to comment.