fix: add null guards for getItemOptionData()->getValues() calls#482
fix: add null guards for getItemOptionData()->getValues() calls#482slash1andy wants to merge 3 commits intowoocommerce:trunkfrom
Conversation
Three locations in API.php call getItemOptionData()->getValues() without checking for null, crashing sync jobs when Square returns ITEM_OPTION objects with null item_option_data. Apply the same guard pattern already used in Product_Import.php (lines 789 and 894). Fixes SQUARE-292.
The update_catalog_variation() method calls getItemOptionData()->getValues() without checking for null, matching the same pattern fixed in API.php. Part of SQUARE-292.
iamdharmesh
left a comment
There was a problem hiding this comment.
Thanks @slash1andy. Looks good to me.
qasumitbagthariya
left a comment
There was a problem hiding this comment.
QA Update ✅
I have verified this PR in the slash1andy:fix/square-292-null-guard-item-option-data branch, which has been fixed and is functioning as intended.
I tested the following on this branch:
Verified that the sync process completes successfully with a normal catalog without any regression
Testing Environment
Details
- WordPress: 6.9.4
- Theme: Storefront 4.6.2
- Theme: Twenty Twenty-Five 1.4
- WooCommerce - 10.6.2
- PHP: 8.0.30
- Web Server: Nginx 1.20.2
- Browser: Chrome
- OS: macOS 15.2
- Branch: smoke-testing
Steps to Test- As mentioned in the PR description.
Test Results - It is working as expected.
Functional Demo / Screencast -
Special Notes - Ready for UAT
Testing Document status:
Cases related to this Issue/PR are added to the Critical Flow Wiki pages:
- Yes
- Not Required/Applicable for this PR
Regression Test Report- QA Verified ✅Testing Environment -Details
Result:Verified all key flows, user flows related to this task/PR, no blocking or functional issues detected. Final Status:Marked as Ready for Merge 🚀 |
Summary
Three locations call
getItemOptionData()->getValues()on SquareCatalogObjectinstances without checking whethergetItemOptionData()returns null. The Square SDK types this return as?CatalogItemOption— explicitly nullable.If Square returns an
ITEM_OPTIONobject with nullitem_option_data:\Error, which is not caught bycatch (\Exception)inStepped_Job::do_next_step()Either way, the entire Action Scheduler job crashes with no recovery path.
Fix
Applied the same null guard pattern already used in
Product_Import.php(lines 789 and 894):Locations fixed
includes/API.phpretrieve_options_data()includes/API.phpcreate_options_and_values()includes/API.phpcreate_options_and_values()includes/Handlers/Product/Woo_SOR.phpupdate_catalog_variation()Test plan
item_option_data) without crashingFixes SQUARE-292.
Changelog entry