Skip to content

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

Open
slash1andy wants to merge 2 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 2 commits intowoocommerce:trunkfrom
slash1andy:fix/square-292-null-guard-item-option-data

Conversation

@slash1andy
Copy link
Copy Markdown
Collaborator

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.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants