Conversation
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
0a60ab9 to
bb030a0
Compare
|
Hi @gigitux, @nefeline, @thealexandrelara, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
nefeline
left a comment
There was a problem hiding this comment.
Exceptional work, @albarin ! I really appreciate your attention to the details on this implementation. Everything tested perfectly: the addition and removal of the transients for caching the requests are also spot on when it comes to plugin deactivation and updating the option for usage tracking on the database.
The fact that you have worked on adding tests is also fantastic! 👏
Just left a suggestion regarding the significance of this change, apart from that, we are off to a great start :)
quick question (not a blocker): did you test if things are still working as expected with AI with those changes in place? It's not super important in this first moment because these changes are behind the feature flag & we are planning to change the way we inject content in patterns down the line, but asking anyways so we can keep this in mind :)
|
@nefeline thanks for the review!
I just tried and in WooExpress AI still works just fine. However, I noticed an issue with the |
|
@nefeline I think the |
gigitux
left a comment
There was a problem hiding this comment.
LGTM! Thanks for your brilliant work! 🚀
I just left a comment, but just out of curiosity! 🚢
I just did & confirmed things are working as expected, thanks for checking 🙏 |
…WooCommerce, ensuring they are fetched from the relevant PTK categories (#47306) * Add PatternsToolkit class to fetch patterns from PTK * Pass the new PatternsToolkit class to the BlockPatterns constructor * Extract the pattern registration code to the 'register_block_pattern' function * Extract the file patterns registration to `register_block_patterns_from_files` * Registers patterns from ptk * Add ids of excluded patterns (because they have jetpack deps) * Add PTK client tests * Filter out patterns with post_type diff than "wp_block" * Add missing excluded pattern * Add error log and improve error messages from the PTK client * Extract function to register patterns to PatternRegistry class * Extract function to register patterns from PTK * Rename PatternsToolkitClient to PTKClient * Extract AI related code to the AIPatterns class * Rename test to match class name * Add missing package dep in BlockPatterns * Cache and register PTK patterns * Add feature flag * Fix linting errors * Add tests for the PatternRegistry * Add tests for the PTKPatternsStore * Add changefile(s) from automation for the following project(s): woocommerce * Check pattern ID exists to filter * Check title is set when registering the pattern * Remove unnecessary code from test * Add more patterns to the excluded list * Add actions to reset the patterns transient on plugin deactivation and tracking option updates * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions <[email protected]>

Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #47396
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
The main feature this PR adds is making available patterns coming from the PTK API that belong to the following categories:
Intro,About,Services, andTestimonials(only if the user allows tracking).Note: the feature is under the
pattern-toolkit-full-composabilityfeature flag.This PR also includes a refactor of the
BlockPatternsclass. This is an explanation of the changes and classes created:BlockPatterns: previously, it contained code related to the WC core patterns registration and some actions related to AI patterns. After the refactor, it only has the necessary code to register patterns, both from WC core and from the PTK API (using the new
PatternRegistryclass).Note: GitHub is hiding the diff for this class because it’s big, but please make sure to load it and review it as well.
PatternRegistry (new class): handles the registration of patterns. This code was previously on
BlockPatterns. It’s essentially the same code but adapted to register also patterns coming from the PTK API (not from files).AIPatterns (new class): handles everything related to the patterns with AI (there’s no new code here, it’s all extracted from
BlockPatterns).PTKPatternsStore (new class): it handles fetching PTK patterns and caching them to avoid making lots of requests to the PTK API.
PTKClient (new class): handles the requests to the PTK API to fetch patterns.
In case this helps, this is a more visual diagram to understand the structure:

How to test the changes in this Pull Request:
We are going to test with one pattern from each of the PTK categories:
Intro: Left-aligned header and buttonpattern.About: Fullwidth image, content pull rightpattern.Services: Three column pricing tablepattern.Review: A quote with scattered imagespattern.wp-admin/admin.php?page=wc-settings&tab=advanced§ion=woocommerce_comand make sureAllow usage of WooCommerce to be trackedis unchecked.wp-admin/tools.php?page=woocommerce-admin-test-helper, go toFeatures, and enablepattern-toolkit-full-composability.wp-admin/admin.php?page=wc-settings&tab=advanced§ion=woocommerce_comand check theAllow usage of WooCommerce to be tracked.wp-admin/admin.php?page=wc-settings&tab=advanced§ion=woocommerce_comand uncheck theAllow usage of WooCommerce to be tracked.Changelog entry
Details
Significance
Type
Message
[CYS] Refactor the pattern registration and add patterns from the PTK API.
Comment