Cherry pick 50496 into release/9.2 (#50645)

* 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>
This commit is contained in:
github-actions[bot] 2024-08-13 18:28:54 +01:00 committed by GitHub
parent 8bd10b29ea
commit 79d293a127
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -405,6 +405,7 @@ class WC_Post_Data {
$data_store->untrash_variations( $id );
wc_product_force_unique_sku( $id );
self::clear_global_unique_id_if_necessary( $id );
wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_changed( $id );
} elseif ( 'product_variation' === $post_type ) {
@ -412,6 +413,19 @@ class WC_Post_Data {
}
}
/**
* Clear global unique id if it's not unique.
*
* @param mixed $id Post ID.
*/
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() ) ) {
$product->set_global_unique_id( '' );
$product->save();
}
}
/**
* Get the post type for a given post.
*

View File

@ -291,6 +291,7 @@ WooCommerce comes with some sample data you can use to see how products look; im
* Add - Expose __experimentalRegisterProductCollection in @woocommerce/blocks-registry Package [#48141](https://github.com/woocommerce/woocommerce/pull/48141)
* Add - Improvements in the handling of feature compatibility for plugins [#48169](https://github.com/woocommerce/woocommerce/pull/48169)
* Add - Product Collection: Rename "Sync with current query" option to "Use page context" and make it working in non-archive context as well [#49627](https://github.com/woocommerce/woocommerce/pull/49627)
* Update - Clear global_unique_id when restoring a product that doesn't have an unique id [#50496](https://github.com/woocommerce/woocommerce/pull/50496)
* Update - Use admin password reset on admin login screen [#50200](https://github.com/woocommerce/woocommerce/pull/50200)
* Update - Prevent creation of password-protected coupons. [#50236](https://github.com/woocommerce/woocommerce/pull/50236)
* Update - Add a link to the Theming docs from the blockified templates README.md file [#48538](https://github.com/woocommerce/woocommerce/pull/48538)