From 8039a96735bd04ed5b89181821bf921a0b67a644 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:39:17 -0300 Subject: [PATCH] Cherry pick 50685 into release/9.2 (#50705) * Remove global_unique_id from interface and add warning in case it is not implemented (#50685) * Prep for cherry pick 50685 * Cherry-pick 50702 into this cherry-pick :) * Update changelog --------- Co-authored-by: Nathan Silveira Co-authored-by: WooCommerce Bot Co-authored-by: Jorge Torres --- .../class-wc-product-data-store-interface.php | 16 ---------------- .../includes/wc-product-functions.php | 19 +++++++++++++++---- plugins/woocommerce/readme.txt | 1 + 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php b/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php index e1e8150ac5e..ed9244ae56a 100644 --- a/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php +++ b/plugins/woocommerce/includes/interfaces/class-wc-product-data-store-interface.php @@ -41,15 +41,6 @@ interface WC_Product_Data_Store_Interface { */ public function is_existing_sku( $product_id, $sku ); - /** - * Check if product unique ID is found for any other product IDs. - * - * @param int $product_id Product ID. - * @param string $global_unique_id Unique ID. - * @return bool - */ - public function is_existing_global_unique_id( $product_id, $global_unique_id ); - /** * Return product ID based on SKU. * @@ -58,13 +49,6 @@ interface WC_Product_Data_Store_Interface { */ public function get_product_id_by_sku( $sku ); - /** - * Return product ID based on Unique ID. - * - * @param string $global_unique_id Unique ID. - * @return int - */ - public function get_product_id_by_global_unique_id( $global_unique_id ); /** * Returns an array of IDs of products that have sales starting soon. diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php index 9e49568115e..7232ef7ccc7 100644 --- a/plugins/woocommerce/includes/wc-product-functions.php +++ b/plugins/woocommerce/includes/wc-product-functions.php @@ -662,8 +662,13 @@ function wc_product_has_global_unique_id( $product_id, $global_unique_id ) { return boolval( $has_global_unique_id ); } - $data_store = WC_Data_Store::load( 'product' ); - $global_unique_id_found = $data_store->is_existing_global_unique_id( $product_id, $global_unique_id ); + $data_store = WC_Data_Store::load( 'product' ); + if ( $data_store->has_callable( 'is_existing_global_unique_id' ) ) { + $global_unique_id_found = $data_store->is_existing_global_unique_id( $product_id, $global_unique_id ); + } else { + $logger = wc_get_logger(); + $logger->error( 'The method is_existing_global_unique_id is not implemented in the data store.', array( 'source' => 'wc_product_has_global_unique_id' ) ); + } /** * Gives plugins an opportunity to verify Unique ID uniqueness themselves. * @@ -738,11 +743,17 @@ function wc_get_product_id_by_sku( $sku ) { * * @since 9.1.0 * @param string $global_unique_id Product Unique ID. - * @return int + * @return int|null */ function wc_get_product_id_by_global_unique_id( $global_unique_id ) { $data_store = WC_Data_Store::load( 'product' ); - return $data_store->get_product_id_by_global_unique_id( $global_unique_id ); + if ( $data_store->has_callable( 'get_product_id_by_global_unique_id' ) ) { + return $data_store->get_product_id_by_global_unique_id( $global_unique_id ); + } else { + $logger = wc_get_logger(); + $logger->error( 'The method get_product_id_by_global_unique_id is not implemented in the data store.', array( 'source' => 'wc_get_product_id_by_global_unique_id' ) ); + } + return null; } /** diff --git a/plugins/woocommerce/readme.txt b/plugins/woocommerce/readme.txt index 15d3f9729ed..58303417997 100644 --- a/plugins/woocommerce/readme.txt +++ b/plugins/woocommerce/readme.txt @@ -173,6 +173,7 @@ WooCommerce comes with some sample data you can use to see how products look; im **WooCommerce** +* Fix - Remove global_unique_id from interface and add warning in case it is not implemented [#50685](https://github.com/woocommerce/woocommerce/pull/50685) * Fix - CYS: avoid to enqueue Jetpack scripts [#50679](https://github.com/woocommerce/woocommerce/pull/50679) * Fix - Clear product unique ID (`global_unique_id`) when duplicating products. [#50629](https://github.com/woocommerce/woocommerce/pull/50629) * Fix - Resolved an issue that caused the page title and content text to display in the incorrect order on the Order Confirmation page. [#50592](https://github.com/woocommerce/woocommerce/pull/50592)