-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Clear global_unique_id when restoring a product with an existing global_unique_id #50496
Conversation
Hi @octaedro, @mattsherman, @louwie17, @mdperez86, Apart from reviewing the code changes, please make sure to review the testing instructions and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. You can follow this guide to find out what good testing instructions should look like: |
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. |
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.
Tested and works as expected.
I think that the code should be made more robust by checking that the $product
exists before calling methods on it.
*/ | ||
private static function clear_global_unique_id_if_necessary( $id ) { | ||
$product = wc_get_product( $id ); | ||
if ( ! wc_product_has_global_unique_id( $id, $product->get_global_unique_id() ) ) { |
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.
There should be a check that $product
exists before attempting to call methods on it.
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.
Works as expected after re-testing with latest change. Nice job!
*/ | ||
private static function clear_global_unique_id_if_necessary( $id ) { | ||
$product = wc_get_product( $id ); | ||
if ( $product && ! wc_product_has_global_unique_id( $id, $product->get_global_unique_id() ) ) { |
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.
Thanks for updating this.
…al_unique_id (#50496) * Clear global_unique_id when restoring a product that doesn't have an unique id * Check if product exists before calling methods
* Clear global_unique_id when restoring a product with an existing global_unique_id (#50496) * Clear global_unique_id when restoring a product that doesn't have an unique id * Check if product exists before calling methods * Prep for cherry pick 50496 --------- Co-authored-by: Nathan Silveira <nsschneider1@gmail.com> Co-authored-by: WooCommerce Bot <no-reply@woocommerce.com>
…unique id
Submission Review Guidelines:
Changes proposed in this Pull Request:
Clear global_unique_id when restoring a product with an existing global_unique_id
Closes #50442 .
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
(copied from original issue)
012345678905
. The GTIN, UPC, EAN or ISBN field can be found in the Inventory tab of the product editor.012345678905
).Changelog entry
Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment