-
Notifications
You must be signed in to change notification settings - Fork 219
Store Customization > Fetch product images from the Pexels API #11280
Conversation
…te_new_product method.
…f the ai generated content to ensure we wont override products modified by the store owner.
… of the media_sideload_image method outside the wp-admin area (via API) and other adjustments to the products generation and hashes
…the default image. Add a limit of 6 when quering the total products created by the store owner.
…rn method to rely on the results returned from the Pexels API.
… ai_connection as a param.
The release ZIP for this PR is accessible via:
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your great work! Overall, the code looks great. I added some comments, but I would suggest skipping the NIT ones. We can iterate and improve the code in successive iterations.
I tested this PR with the prompt:
I want to sell football clothes and gadgets.
I noticed that some images are not related to my prompt and some content is missing:
* @return bool | ||
*/ | ||
public function update_ai_connection_allowed_option( $option, $value ): bool { | ||
$ai_connection = new Connection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Should this class be a Singleton? Every time that we get the jwt_token, we do a fetch request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I'm doing this change on a separate PR 👍 !
Thanks for the testing here @gigitux ! This was a consequence of the limitations mentioned in the description of this PR. I did some additional fine-tuning to the prompts, between other changes, to ensure the store is updated with content/images that better fit the description. I still wanna do some additional changes to improve consistency, but we need to unblock the call for testing now, so I'm working on these changes as part of a separate PR. Thanks again for your review and tests here; much appreciated! 🙏 |
Completely agree! Let's 🚢 ! |
* 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. * Pass the AI connection as a param and update the get_images_for_pattern method to rely on the results returned from the Pexels API. * update the product updater class to rely on Pexels images and add the ai_connection as a param. * Remove the unused get_random_images method. * Update the patterns endpoint. * Delete unused ChatGPTClient class. * Introduce the new Pexels class. * Remove the Verticals references. * Update the reference for the alt description for images. * Update the scheduled action to populate patterns and products. * Remove unused Verticals classes. * Ensure the Pexels class already returns the array with the expected format for assignment to Patterns and Products. * Introduce the select_image_src_based_on_format method. * Increase max execution time * Increase max execution time * Update the request to rely on the WP.com external-media endpoint instead. * Improve performance for product content update. * Improve quality of images used in products and update queries. * Update the products query. * Move the media_sideload_image function dependencies to outside of the loop and add comment. * Update text content. * Merge base branch * Introduce the should_update_dummy_product method. * Update the method to be triggered on scheduled action to return true. * Change the image format for products to improve performance. * Make portrait the default fallback image format. * Address code review. * bail early if no business description provided. * Add an extra safety check in case of query errors. * Address CR. * Raise the default memory limit. * Update the prompt for the search term for images. * Make sure the 'woocommerce_blocks_allow_ai_connection' option is set to true if the site is connected to AI. * Update the prompt for AI generated content in patterns and initialize the images and alts for the patterns. * Update the prompt for products and introduce the update_dummy_products method. * Update the default number of images returned by Pexels. * Update the default fallback for the expected image format. * Update the prompt for selecting the images. * Add a character limit to the testimonials. * Increase timeout to fetch products data * Address code review.
* Empty commit for release pull request * Do a version bump to 11.4.1 * Add Instruction Notes and update the Changelog * Update the testing instructions and the changelog and the .zip link * Empty commit for release pull request * Remove the fontSize for the button (#11433) * [Store Customization MVP] Ensure the AI-generated content in patterns is updated on plugin update (#11210) * Update the patterns content after updating the plugin * Remove unused variable and use statement * Schedule action for updating the patterns content on plugin update (for both WooCommerce and WooCommerce Blocks.) * Update condition to remove the plugin folder name * Remove the update function from bootstrap.php * Remove unused use * Fix the condition, since $options['plugin'] is an array * Remove pattern file This was left empty by mistake in a merge, we need to remove the file or we get an error --------- Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> * Fix outer space and title (#11434) * Store Customization > Update products with AI generated content (#11155) * 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. * Patterns > Upload optimized version of placeholder image (#11441) * Improve vars name and remove duplicated user name (#11430) * Add overlay with 30% opacity (#11428) * [Store Customization] Update the "Footer with 3 Menus" (#11379) * Fix search bar, spacing and show text in one line * Set site log width * Adjust margins and search bar * Make the search bar fill space on mobile * Update column sizes * Remove width from site logo * [CYS Woo Express] Update large footer (#11413) * Update large footer * Update space between icons * Remove with from site logo * update changelog and testing instructions * bump to 11.4.2 version * [CYS Woo Express] Fix essential header (#11449) * Fix essential header * Fix spacing * update testing instructions * Make groups to adapt better to mobile views (#11463) * update testing instructions and changelog * Unify the search bar layout across patterns (#11445) * Unify the search bar layout across patterns * restore changes * [CYS Woo Express] Footer with simple menu and cart (#11409) * Update footer simple menu cart * Change structure to use rows not columns * Make search fill space * Fix spacing and switch mini-cart and menu * Unify the search bar * Remove mini cart * update testing instructions and changelog * Store Customization > Fetch product images from the Pexels API (#11280) * 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. * Pass the AI connection as a param and update the get_images_for_pattern method to rely on the results returned from the Pexels API. * update the product updater class to rely on Pexels images and add the ai_connection as a param. * Remove the unused get_random_images method. * Update the patterns endpoint. * Delete unused ChatGPTClient class. * Introduce the new Pexels class. * Remove the Verticals references. * Update the reference for the alt description for images. * Update the scheduled action to populate patterns and products. * Remove unused Verticals classes. * Ensure the Pexels class already returns the array with the expected format for assignment to Patterns and Products. * Introduce the select_image_src_based_on_format method. * Increase max execution time * Increase max execution time * Update the request to rely on the WP.com external-media endpoint instead. * Improve performance for product content update. * Improve quality of images used in products and update queries. * Update the products query. * Move the media_sideload_image function dependencies to outside of the loop and add comment. * Update text content. * Merge base branch * Introduce the should_update_dummy_product method. * Update the method to be triggered on scheduled action to return true. * Change the image format for products to improve performance. * Make portrait the default fallback image format. * Address code review. * bail early if no business description provided. * Add an extra safety check in case of query errors. * Address CR. * Raise the default memory limit. * Update the prompt for the search term for images. * Make sure the 'woocommerce_blocks_allow_ai_connection' option is set to true if the site is connected to AI. * Update the prompt for AI generated content in patterns and initialize the images and alts for the patterns. * Update the prompt for products and introduce the update_dummy_products method. * Update the default number of images returned by Pexels. * Update the default fallback for the expected image format. * Update the prompt for selecting the images. * Add a character limit to the testimonials. * Increase timeout to fetch products data * Address code review. * update changelog * add zip link * fix markdown * remove duplicate testing instructions --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com> Co-authored-by: Alba Rincón <albarin@users.noreply.github.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com> Co-authored-by: Luigi <gigitux@gmail.com>
* Empty commit for release pull request * Add changelog entries to readme.txt * Update version numbers * Add testing instructions * Update the changelog with #11421 * Always show the `Enable the shipping calculator on the cart page` option in WC Admin (#11421) * Always show `Enable the shipping calculator ...` Always show the `Enable the shipping calculator on the cart page` option no matter of what is used for the cart page. * Update remove_shipping_settings docblock to accurately describe its purpose. --------- Co-authored-by: Mike Jolley <mike.jolley@me.com> * Add a safe guard that the variable is set before accessing it (#11424) * Update zip package link * Modify the <main> HTML tag in the title to 'main' to ensure the title remains intact * Revert "Use the <header> element for the checkout header (#11222)" This reverts commit 045789e. * Remove #11222 from the Changelog and the Testing Notes * Remove #11190 from the Changelog and Testing Notes as it was never merged * Update .zip file with latest changes * Release: 11.4.2 (#11452) * Empty commit for release pull request * Do a version bump to 11.4.1 * Add Instruction Notes and update the Changelog * Update the testing instructions and the changelog and the .zip link * Empty commit for release pull request * Remove the fontSize for the button (#11433) * [Store Customization MVP] Ensure the AI-generated content in patterns is updated on plugin update (#11210) * Update the patterns content after updating the plugin * Remove unused variable and use statement * Schedule action for updating the patterns content on plugin update (for both WooCommerce and WooCommerce Blocks.) * Update condition to remove the plugin folder name * Remove the update function from bootstrap.php * Remove unused use * Fix the condition, since $options['plugin'] is an array * Remove pattern file This was left empty by mistake in a merge, we need to remove the file or we get an error --------- Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> * Fix outer space and title (#11434) * Store Customization > Update products with AI generated content (#11155) * 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. * Patterns > Upload optimized version of placeholder image (#11441) * Improve vars name and remove duplicated user name (#11430) * Add overlay with 30% opacity (#11428) * [Store Customization] Update the "Footer with 3 Menus" (#11379) * Fix search bar, spacing and show text in one line * Set site log width * Adjust margins and search bar * Make the search bar fill space on mobile * Update column sizes * Remove width from site logo * [CYS Woo Express] Update large footer (#11413) * Update large footer * Update space between icons * Remove with from site logo * update changelog and testing instructions * bump to 11.4.2 version * [CYS Woo Express] Fix essential header (#11449) * Fix essential header * Fix spacing * update testing instructions * Make groups to adapt better to mobile views (#11463) * update testing instructions and changelog * Unify the search bar layout across patterns (#11445) * Unify the search bar layout across patterns * restore changes * [CYS Woo Express] Footer with simple menu and cart (#11409) * Update footer simple menu cart * Change structure to use rows not columns * Make search fill space * Fix spacing and switch mini-cart and menu * Unify the search bar * Remove mini cart * update testing instructions and changelog * Store Customization > Fetch product images from the Pexels API (#11280) * 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. * Pass the AI connection as a param and update the get_images_for_pattern method to rely on the results returned from the Pexels API. * update the product updater class to rely on Pexels images and add the ai_connection as a param. * Remove the unused get_random_images method. * Update the patterns endpoint. * Delete unused ChatGPTClient class. * Introduce the new Pexels class. * Remove the Verticals references. * Update the reference for the alt description for images. * Update the scheduled action to populate patterns and products. * Remove unused Verticals classes. * Ensure the Pexels class already returns the array with the expected format for assignment to Patterns and Products. * Introduce the select_image_src_based_on_format method. * Increase max execution time * Increase max execution time * Update the request to rely on the WP.com external-media endpoint instead. * Improve performance for product content update. * Improve quality of images used in products and update queries. * Update the products query. * Move the media_sideload_image function dependencies to outside of the loop and add comment. * Update text content. * Merge base branch * Introduce the should_update_dummy_product method. * Update the method to be triggered on scheduled action to return true. * Change the image format for products to improve performance. * Make portrait the default fallback image format. * Address code review. * bail early if no business description provided. * Add an extra safety check in case of query errors. * Address CR. * Raise the default memory limit. * Update the prompt for the search term for images. * Make sure the 'woocommerce_blocks_allow_ai_connection' option is set to true if the site is connected to AI. * Update the prompt for AI generated content in patterns and initialize the images and alts for the patterns. * Update the prompt for products and introduce the update_dummy_products method. * Update the default number of images returned by Pexels. * Update the default fallback for the expected image format. * Update the prompt for selecting the images. * Add a character limit to the testimonials. * Increase timeout to fetch products data * Address code review. * update changelog * add zip link * fix markdown * remove duplicate testing instructions --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com> Co-authored-by: Alba Rincón <albarin@users.noreply.github.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com> Co-authored-by: Luigi <gigitux@gmail.com> * Release: 11.4.3 (#11496) * bump to 11.4.3 * Empty commit for release pull request * Improve Hero Product Chessboard pattern (#11423) * improve pattern * remove hardcoded font-size * address feedback * update to h2 * Remove group and separator to get rid of the extra space (#11477) * [Store Customization] Update the design for the Product Gallery pattern (#11464) * Remove rating, show only title and price * Improve title spacing and level * Patterns with Search Bar: improve style (#11478) * "Product Collection X Columns" patterns: align "no reviews" text with the star (#11468) * improve line-height * use variable * add testing instructions * Rename pattern (#11487) * update readme * Store Customization > Enhance the Hero Product Split pattern (#11505) * Update the bottom margin for the Hero Product Split and the heading from h3 to h2. * Update heading comment * update testing instructions * Simplify the `Hero Product 3 Split` pattern design (#11495) * Simplify the pattern design * Add char limits to the AI generated content * Fix url * update testing instructions * Product Search Block: unify border-radius (#11515) * add testing instructions * [Store Customization] Update the Centered Header Menu with Search Pattern (#11304) * Fix hidden elements on mobile and margins * Increase navigation items spacing * Add site logo width * Improve search bar and title font weight * Remove width from site logo * Unify search bar * Remove search, improve margins * Use columns to improve the mobile view * add testing instructions * Large Header pattern: improve the layout on mobile view (#11490) * Improve Large header * improve large header * use lens * add padding * add testing instructions * Fix "Large footer" left spacing (#11520) * Fix large footer left spacing * Use esc_html_e * add testing instructions * add zip file * improve testing instructions * update testing instructions * update testing instructions --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Alba Rincón <albarin@users.noreply.github.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com> Co-authored-by: Saad Tarhi <saad.trh@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com> Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Alba Rincón <albarin@users.noreply.github.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com> Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>
What
Update the image provider for the Customize Your Store experience, migrating from Verticals to Pexels. Additional changes made on this PR also include:
'woocommerce_blocks_allow_ai_connection'
option is updated to true whenever the store owner updates their business description (either via the onboarding flow or the store admin area). The option that stores the business description is available within WooExpress exclusively. The'woocommerce_blocks_allow_ai_connection'
option will be updated only if the site has an active connection with JetPack (therefore they accepted the terms and conditions).Implementation details
Instead of making requests directly to the Pexels API, we are now relying on WP.com's endpoint (
'/wpcom/v2/external-media/list/pexels'
) as a middleman to ensure there won't be any restrictions regarding rate limiting. JetPack is a dependency for this connection as their built-in client for this endpoint is being used to power the requests.Fixes #11461
Why
Given several restrictions and limitations we have found with the Verticals API, including low availability of images and incorrect classification of images, this update ensures the assignment of images to patterns and products by AI is consistent and more accurate.
Testing Instructions
Please consider any edge cases this change may have, and also other areas of the product this may impact.
Initial Setup
Or alternatively, create a new WordPress install from scratch (make sure the install is a Jurassic Ninja install or equivalent. Otherwise you won't be able to connect with Jetpack to test this PR).
/wp-admin/tools.php?page=woocommerce-admin-test-helper
and enablecustomize-store
feature flag:Test the AI-managed images
Known limitations:
In a few cases, you may notice that new images are not assigned to a product or pattern in particular. This is still under investigation, and a separate PR will be opened to address this limitation.
Sometimes, depending on the store description, images are not tightly associated with the expected content: more fine-tuning is happening in upcoming PRs.
Do not include in the Testing Notes
[] Should be tested by the development team exclusively
Screenshots or screencast
Screen.Recording.2023-10-26.at.09.59.01.mov
WooCommerce Visibility
Required:
Checklist
Required:
[type]
label or a[skip-changelog]
label.Conditional:
[skip-changelog]
label is not present).Changelog