-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[Woo POS] Products catalog API: integrate with the Product Feed plugin #61763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
[Woo POS] Products catalog API: integrate with the Product Feed plugin #61763
Conversation
|
@coderabbitai full review |
|
@jaclync: I'll conduct a full review of this pull request. Give me a moment to analyze all the changes. 🧠 Learnings used✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThe POST /products/catalog endpoint now conditionally delegates to an async product-feed generator from the WooCommerce Product Feed for OpenAI plugin when available; otherwise it retains the existing synchronous flow. The catalog status enum was reduced to: pending, processing, complete. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Endpoint as POST /products/catalog
participant Checker as is_async_generator_available()
participant Sync as Sync Handler (legacy)
participant Async as request_catalog_async()
participant Generator as AsyncGenerator (external plugin)
Client->>Endpoint: POST /products/catalog
Endpoint->>Checker: check async generator available?
alt async generator available
Checker-->>Endpoint: true
Endpoint->>Async: request_catalog_async(fields, force_generate)
Async->>Generator: force_regeneration() / get_status()
Generator-->>Async: state (scheduled|in_progress|completed) [+ download_url if ready]
Note over Async: map (scheduled→pending, in_progress→processing, completed→complete)
Async-->>Endpoint: REST response (status, optional download_url)
else async unavailable
Checker-->>Endpoint: false
Endpoint->>Sync: existing synchronous request_catalog flow
Sync-->>Endpoint: REST response
end
Endpoint-->>Client: response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugins/woocommerce/changelog/WOOMOB-1455-pos-catalog-api-integration-with-product-feed-plugin(1 hunks)plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php(3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
**/*.{php,js,jsx,tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/avoid-regex.mdc)
**/*.{php,js,jsx,tsx,ts}: Avoid using regular expressions unless absolutely necessary to favor readability and maintainability
Only consider regex when no built-in language alternative (string/array APIs) fits the need
Only use regex when performance is critical and faster than alternatives, with measurements to justify
Use regex for complex pattern matching only if the pattern is well-documented and thoroughly tested
Allow regex when maintaining legacy code where an existing, correct pattern is being modified
If regex is necessary, document the pattern extensively to explain what it matches
If regex is necessary, add comprehensive tests covering edge cases and potential security issues
Use named capture groups in regex to improve readability when supported
Validate input before applying regex to ensure it is safe
Assess and mitigate security risks when using regex, including ReDoS and injection vulnerabilities
Avoid regex patterns that can cause catastrophic backtracking (ReDoS)
Do not construct regex from untrusted input to prevent injection attacks
Ensure regex patterns do not overmatch and unintentionally capture unexpected inputs
Files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit configuration file
**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
When making any changes to code that deletes or modifies orders/products/customer data, make sure that there are
sufficient checks in place to prevent accidental data loss. As an example, if deleting a draft order, check that
the order status is indeeddraftorcheckout-draft. Also think about whether race conditions could occur and
delete orders that don't belong to the current customer. When in doubt, ask for clarification in the PR comments.
Files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
🧠 Learnings (2)
📚 Learning: 2025-08-29T10:13:44.287Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60667
File: plugins/woocommerce/src/Blocks/BlockTypes/AddToCartForm.php:122-125
Timestamp: 2025-08-29T10:13:44.287Z
Learning: In WooCommerce, the ProductType class in plugins/woocommerce/src/Enums/ProductType.php contains string constants (not a PHP backed enum), so ProductType::VARIATION directly returns the string 'variation' and can be passed directly to methods like WC_Product::is_type() without needing ->value.
Applied to files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
📚 Learning: 2025-07-15T15:39:21.856Z
Learnt from: jorgeatorres
Repo: woocommerce/woocommerce PR: 59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
Applied to files:
plugins/woocommerce/changelog/WOOMOB-1455-pos-catalog-api-integration-with-product-feed-plugin
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
- GitHub Check: Blocks e2e tests 10/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests - Legacy MiniCart 1/3 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests - Legacy MiniCart 3/3 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests - Legacy MiniCart 2/3 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Blocks e2e tests 8/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 6/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 7/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 4/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 8.4 WP: latest (HPOS:off) [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 5/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
- GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: PHP: 8.4 WP: latest - Legacy MiniCart [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
🔇 Additional comments (4)
plugins/woocommerce/changelog/WOOMOB-1455-pos-catalog-api-integration-with-product-feed-plugin (1)
1-4: LGTM! Clear changelog entry.The changelog entry accurately describes the integration and follows WooCommerce conventions.
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php (3)
280-287: LGTM! Robust availability check.The method correctly checks both the plugin version constant and class existence, ensuring safe integration.
175-175: No breaking change identified; enum correctly reflects valid AsyncGenerator states.The 'failed' status removal is not a breaking change because the AsyncGenerator from the Product Feed plugin only returns three states:
scheduled(→pending),in_progress(→processing), andcompleted(→complete). There is no evidence thatfailedwas ever a valid state returned by AsyncGenerator. Error scenarios are properly handled via WP_Error exceptions with HTTP 500 status codes (lines 320, 335), which provides clear error communication to clients. The schema now accurately reflects the actual states the plugin returns.
84-88: Conditional async/sync delegation pattern is sound and properly implemented.Verification confirms both paths handle parameters appropriately:
- Fields: Pre-sanitized at line 81 via
sanitize_fields_arg()before either path uses them, so no additional sanitization needed in eitherrequest_catalog_async()or sync path.- force_generate flag: Both paths respect this parameter—sync path checks explicitly at line 96; async path passes to
get_status()orforce_regeneration()as appropriate.- Error handling: Sync path calls
get_catalog_file_info()and explicitly checks for WP_Error (lines 92–95). Async path delegates error handling to the AsyncGenerator plugin via try-catch wrapper (lines 295, 334), which is the intended design. The plugin is responsible for file existence checks and upload directory validation internally.The pattern correctly separates concerns: external plugin handles async logic when available; internal synchronous fallback provides explicit validation for backwards compatibility.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugins/woocommerce/changelog/WOOMOB-1455-pos-catalog-api-integration-with-product-feed-plugin(1 hunks)plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php(3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
**/*.{php,js,jsx,tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/avoid-regex.mdc)
**/*.{php,js,jsx,tsx,ts}: Avoid using regular expressions unless absolutely necessary to favor readability and maintainability
Only consider regex when no built-in language alternative (string/array APIs) fits the need
Only use regex when performance is critical and faster than alternatives, with measurements to justify
Use regex for complex pattern matching only if the pattern is well-documented and thoroughly tested
Allow regex when maintaining legacy code where an existing, correct pattern is being modified
If regex is necessary, document the pattern extensively to explain what it matches
If regex is necessary, add comprehensive tests covering edge cases and potential security issues
Use named capture groups in regex to improve readability when supported
Validate input before applying regex to ensure it is safe
Assess and mitigate security risks when using regex, including ReDoS and injection vulnerabilities
Avoid regex patterns that can cause catastrophic backtracking (ReDoS)
Do not construct regex from untrusted input to prevent injection attacks
Ensure regex patterns do not overmatch and unintentionally capture unexpected inputs
Files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit configuration file
**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
When making any changes to code that deletes or modifies orders/products/customer data, make sure that there are
sufficient checks in place to prevent accidental data loss. As an example, if deleting a draft order, check that
the order status is indeeddraftorcheckout-draft. Also think about whether race conditions could occur and
delete orders that don't belong to the current customer. When in doubt, ask for clarification in the PR comments.
Files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
🧠 Learnings (3)
📚 Learning: 2025-06-20T17:38:16.565Z
Learnt from: opr
Repo: woocommerce/woocommerce PR: 0
File: :0-0
Timestamp: 2025-06-20T17:38:16.565Z
Learning: WooCommerce legacy JavaScript files in plugins/woocommerce/client/legacy/js/ must use older JavaScript syntax and cannot use modern features like optional chaining (?.) due to browser compatibility requirements. Explicit null checking with && operators should be used instead.
Applied to files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
📚 Learning: 2025-08-29T10:13:44.287Z
Learnt from: Aljullu
Repo: woocommerce/woocommerce PR: 60667
File: plugins/woocommerce/src/Blocks/BlockTypes/AddToCartForm.php:122-125
Timestamp: 2025-08-29T10:13:44.287Z
Learning: In WooCommerce, the ProductType class in plugins/woocommerce/src/Enums/ProductType.php contains string constants (not a PHP backed enum), so ProductType::VARIATION directly returns the string 'variation' and can be passed directly to methods like WC_Product::is_type() without needing ->value.
Applied to files:
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
📚 Learning: 2025-07-15T15:39:21.856Z
Learnt from: jorgeatorres
Repo: woocommerce/woocommerce PR: 59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
Applied to files:
plugins/woocommerce/changelog/WOOMOB-1455-pos-catalog-api-integration-with-product-feed-plugin
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.4] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
- GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
🔇 Additional comments (4)
plugins/woocommerce/changelog/WOOMOB-1455-pos-catalog-api-integration-with-product-feed-plugin (1)
1-4: LGTM!The changelog entry correctly documents the integration with the Product Feed plugin for async catalog generation. The format, significance level, and description are appropriate.
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php (3)
84-88: LGTM!The conditional delegation to the async path maintains backwards compatibility by falling back to the synchronous flow when the Product Feed plugin is unavailable.
280-287: LGTM!The availability check properly guards against missing plugin integration by verifying both the plugin constant and the AsyncGenerator class existence.
175-175: No breaking change detected—review comment is based on incorrect assumptions.The schema enum at line 175 contains
'pending', 'processing', 'complete', but investigation reveals that a'failed'status was never returned by this endpoint. All error conditions returnWP_Errorobjects (HTTP 500), not a status value. The async generator maps three internal states (scheduled,in_progress,completed) to the three enum values—there is no failure state equivalent. Since no code path in the controller ever returned or checked for a'failed'status, removing it from the schema (if it was even present before) is not a breaking change for existing API consumers.Likely an incorrect or invalid review comment.
...ommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-catalog-controller.php
Show resolved
Hide resolved
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Testing GuidelinesHi @jorgeatorres @RadoslavGeorgiev , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
|
Claude finished @jaclync's task —— View job Backwards Compatibility ReviewSummaryRisk Level: Low This PR integrates the Products Catalog API with the Product Feed plugin for async catalog generation. The changes are well-contained with minimal BC risk because:
The single potential concern is the schema change, but investigation confirms this is a correction, not a breaking change. Detailed Analysis1. REST API Schema Change (class-wc-rest-products-catalog-controller.php:175) -'enum' => array( 'pending', 'processing', 'complete', 'failed' ),
+'enum' => array( 'pending', 'processing', 'complete' ),Impact: None. The
Mitigation: N/A - This is a schema correction, not a breaking change. API consumers never received 2. New Private Methods (lines 280-363)
Impact: None. Private methods with 3. Conditional Async Path (lines 85-88) if ( $this->is_async_generator_available() ) {
return $this->request_catalog_async( $fields, $force_generate );
}Impact: Low. Changes response timing but maintains identical schema:
BC Consideration: API consumers expecting immediate
Mitigation: None required—this is the intended feature behavior. Consumers should implement polling for non-complete statuses. 4. Error Handling All new error paths return appropriate
Impact: None. Consistent with existing error handling pattern. 5. External Dependencies New dependency on optional Product Feed plugin classes:
Impact: None. Defensive checks ensure graceful fallback (lines 285-287, 298-314). 6. Parameter Handling No changes to:
Impact: None. Testing FocusSince this is a feature-flagged development endpoint, focus testing on:
Ecosystem ImpactPayment Gateways: None—catalog endpoint unrelated to payment processing. Popular Extensions (Subscriptions/Bookings/Memberships): None—endpoint is for POS product catalog retrieval only. Custom Checkout Flows: None—endpoint unrelated to checkout. Themes/Templates: None—no template files modified. Confidence95% - High confidence due to:
The 5% uncertainty accounts for potential undocumented API consumers who might have implemented clients that don't handle all documented status values, though this would be a client-side implementation issue rather than a BC break. Recommendation: Approved from BC perspective. The integration is well-designed with proper isolation and fallback mechanisms. The feature flag ensures no production impact. |
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. |
Submission Review Guidelines:
Changes proposed in this Pull Request:
Part of WOOMOB-1455
This PR updates the feature-flagged
POST /wp-json/wc/v3/products/catalogendpoint to integrate with async product feed generation from theWooCommerce Product Feed for OpenAIplugin (abbreviated Product Feed plugin below) when installed and active. The plan is to move the Product Feed foundation code to core once the plugin has been tested in production with at least a few stores.Key features:
AsyncGeneratorfor background catalog generationpending,processing, orcompletewith download URL when readyforce_generateparameter to force regeneration of existing catalogsproducts-catalog-apidevelopment feature flagTechnical implementation:
AsyncGenerator::get_status()orforce_regeneration()for async processing when Product Feed plugin is activescheduled,in_progress,completed) to API response statesHow to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Prerequisite: ensure the
products-catalog-apidevelopment feature flag is enabled.Test Scenario 1: Async Catalog Generation (Plugin Active)
Prerequisite:
Install the Product Feed plugin using this zip file woocommerce-product-feed-for-openai.zip that includes a change to allow file access in the product feed directory p1762224153119989/1761032826.289079-slack-C09EWAXSYD9.
/wp-json/wc/v3/products/catalogwith admin authenticationstatus: One ofpending,processing, orcompletedownload_url: URL to download file (present when status iscomplete, null otherwise)complete, send another POST request to check updated statuscompletewith a validdownload_urldownload_urland verify it's a valid product catalog fileforce_generate=trueparameterTest Scenario 2: Fallback Behavior (Plugin Inactive)
/wp-json/wc/v3/products/catalogTesting that has already taken place:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment