Skip to content

fix: add null guards for getItemOptionData()->getValues() calls#482

Open
slash1andy wants to merge 3 commits intowoocommerce:trunkfrom
slash1andy:fix/square-292-null-guard-item-option-data
Open

fix: add null guards for getItemOptionData()->getValues() calls#482
slash1andy wants to merge 3 commits intowoocommerce:trunkfrom
slash1andy:fix/square-292-null-guard-item-option-data

Conversation

@slash1andy
Copy link
Copy Markdown
Collaborator

@slash1andy slash1andy commented Apr 8, 2026

Summary

Three locations call getItemOptionData()->getValues() on Square CatalogObject instances without checking whether getItemOptionData() returns null. The Square SDK types this return as ?CatalogItemOption — explicitly nullable.

If Square returns an ITEM_OPTION object with null item_option_data:

  • PHP 7: uncatchable Fatal Error
  • PHP 8: throws \Error, which is not caught by catch (\Exception) in Stepped_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):

$option_values_object = $object->getItemOptionData() ? $object->getItemOptionData()->getValues() : array();

Locations fixed

File Method Line
includes/API.php retrieve_options_data() 644
includes/API.php create_options_and_values() 683
includes/API.php create_options_and_values() 729
includes/Handlers/Product/Woo_SOR.php update_catalog_variation() 385

Test plan

  • Verify sync completes successfully with a normal catalog (no regression)
  • Verify sync handles catalogs with malformed ITEM_OPTION objects (null item_option_data) without crashing
  • Verify the sync continues processing remaining objects after encountering a null option

Fixes SQUARE-292.

Changelog entry

Fix - Syncs no longer crash when encountering certain malformed items in your Square catalog.

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.
Copy link
Copy Markdown
Collaborator

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @slash1andy. Looks good to me.

Copy link
Copy Markdown
Collaborator

@qasumitbagthariya qasumitbagthariya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@iamdharmesh iamdharmesh added this to the 5.3.3 milestone May 7, 2026
@ankitguptaindia
Copy link
Copy Markdown
Collaborator

Regression Test Report- QA Verified ✅

Testing Environment -

Details
  • WordPress: 6.9.4
  • PHP: 8.4.18
  • Server: nginx/1.26.1
  • Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.4.18)
  • Browser: Chrome 147.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • Plugins:
    • WooCommerce 10.7.0
    • WooCommerce Square - Dev version

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 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants