Fix Categories were being stripped from products during manual sync.#451
Fix Categories were being stripped from products during manual sync.#451iamdharmesh wants to merge 13 commits intotrunkfrom
Conversation
🔍 WordPress Plugin Check Report
📊 Report
❌ Errors (8)📁 includes/WC_Payments_Compatibility.php (1 error)
📁 includes/Framework/PaymentGateway/Admin/views/html-user-payment-token-editor-token.php (1 error)
📁 includes/Framework/PaymentGateway/Admin/views/html-user-payment-token-editor.php (1 error)
📁 includes/Framework/PaymentGateway/Admin/views/html-order-partial-capture.php (1 error)
📁 includes/Framework/PaymentGateway/Admin/views/html-user-profile-field-customer-id.php (1 error)
📁 includes/Framework/PaymentGateway/Admin/views/html-user-profile-section.php (1 error)
📁 includes/Framework/PaymentGateway/Admin/views/html-admin-gateway-status.php (1 error)
📁 includes/Admin/Product_Editor_Compatibility.php (1 error)
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
1f089b3 to
a658062
Compare
There was a problem hiding this comment.
Pull request overview
Fixes category assignment loss during Square→Woo sync (manual + interval) by centralizing multi-category extraction/import and updating sync handlers and E2E coverage accordingly.
Changes:
- Refactors Square category ID extraction/import into
Category::get_category_ids_from_catalog_item()and reuses it in product import and product updates. - Updates product update logic to assign multiple WooCommerce categories instead of a single category.
- Expands E2E utilities/specs to create, sync, and assert multiple categories.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/e2e/utils/square-sandbox.js | Adds support for multiple categories in Square sandbox helpers and catalog info extraction. |
| tests/e2e/utils/helper.js | Updates Woo product creation helper to handle multiple categories from a comma-delimited string. |
| tests/e2e/specs/d8.square-sor-multiple-variations.spec.js | Updates expected variation attribute ordering/values (test expectations). |
| tests/e2e/specs/c4.product-import.spec.js | Extends import test to validate multiple categories after Square import. |
| tests/e2e/specs/c2.woo-sor.spec.js | Extends Woo→Square sync test to validate multiple categories pushed to Square. |
| includes/Sync/Product_Import.php | Replaces inline category import logic with shared category-ID extraction helper. |
| includes/Handlers/Product.php | Updates product-from-Square handler to set multiple category terms. |
| includes/Handlers/Category.php | Introduces shared helper to map/import Square categories to Woo term IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
faisal-alvi
left a comment
There was a problem hiding this comment.
@iamdharmesh thanks for working on this!
When Square has no categories, we should explicitly set product categories to empty so Woo matches Square, or document that we intentionally leave existing categories. I have also added a few suggestions. Please have a look.
| try { | ||
| $response = wc_square()->get_api()->batch_retrieve_catalog_objects( $missing_category_ids ); | ||
| if ( $response->get_data() instanceof \Square\Models\BatchRetrieveCatalogObjectsResponse ) { | ||
| $missing_categories = $response->get_data()->getObjects(); |
There was a problem hiding this comment.
if getObjects() returns an empty array (e.g. deleted/invalid IDs), we only log on exception. Should we consider logging when some IDs were requested but none returned, for “category still missing” cases?
There was a problem hiding this comment.
We log exception if we didn't get a proper response, but not logging for the empty array? Could you please provide more information on what we want to do here? Thanks
|
@faisal-alvi this is ready for your review. |
All Submissions:
Changes proposed in this Pull Request:
In PR #408, we added support for syncing multiple categories. However, we missed adding this support to manual synchronization. This PR fixes an issue in manual and interval synchronization where categories were being stripped from products synced from Square.
Note
While working on this, I noticed that synced categories do not maintain the parent–child relationship during synchronization. I have reported a separate issue to explore implementation options and potentially address it.
Closes https://linear.app/a8c/issue/SQUARE-231/categories-get-stripped-off-from-products-that-are-synced-from-square
Steps to test the changes in this Pull Request:
Square SOR:
WooCommerce SOR:
Changelog entry