Commit b588a43cb61 for woocommerce

commit b588a43cb6127608e66bd143b8e625f54703f793
Author: Lucio Giannotta <lucio.giannotta@a8c.com>
Date:   Thu Mar 26 20:56:01 2026 +0800

    Add missing WC class imports to V4 Products controller (#63852)

    Add missing WC class imports to namespaced V4 Products controller

    The controller was moved into the `Automattic\WooCommerce` namespace but
    several global `WC_*` classes were left without use statements. Add imports
    for `WC_Product_Simple`, `WC_REST_Exception`, `WC_Data_Store` and `WC_Product_Attribute`.

diff --git a/plugins/woocommerce/changelog/woo6-60-codex-review-namespaced-v4-products-controller-lacks-wc b/plugins/woocommerce/changelog/woo6-60-codex-review-namespaced-v4-products-controller-lacks-wc
new file mode 100644
index 00000000000..944020a5f84
--- /dev/null
+++ b/plugins/woocommerce/changelog/woo6-60-codex-review-namespaced-v4-products-controller-lacks-wc
@@ -0,0 +1,5 @@
+Significance: patch
+Type: fix
+Comment: Add missing use statements for WC_Product_Simple, WC_REST_Exception, and WC_Product_Attribute in the namespaced V4 Products controller.
+
+
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index a6cfa0d0613..3566c30f31f 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -68454,48 +68454,12 @@ parameters:
 			count: 2
 			path: src/Internal/RestApi/Routes/V4/Products/Controller.php

-		-
-			message: '#^Call to method set_id\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute\.$#'
-			identifier: class.notFound
-			count: 1
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
 		-
 			message: '#^Call to method set_image_id\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product\.$#'
 			identifier: class.notFound
 			count: 2
 			path: src/Internal/RestApi/Routes/V4/Products/Controller.php

-		-
-			message: '#^Call to method set_name\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
-		-
-			message: '#^Call to method set_options\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
-		-
-			message: '#^Call to method set_position\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
-		-
-			message: '#^Call to method set_variation\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
-		-
-			message: '#^Call to method set_visible\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
 		-
 			message: '#^Call to method single_add_to_cart_text\(\) on an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Data\.$#'
 			identifier: class.notFound
@@ -68610,24 +68574,6 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/Products/Controller.php

-		-
-			message: '#^Instantiated class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Attribute not found\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
-		-
-			message: '#^Instantiated class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_Product_Simple not found\.$#'
-			identifier: class.notFound
-			count: 1
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
-		-
-			message: '#^Instantiated class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_REST_Exception not found\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
 		-
 			message: '#^Method Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\Controller\:\:create_item\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
 			identifier: missingType.generics
@@ -68700,12 +68646,6 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/Products/Controller.php

-		-
-			message: '#^PHPDoc tag @throws with type Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_REST_Exception is not subtype of Throwable$#'
-			identifier: throws.notThrowable
-			count: 1
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
 		-
 			message: '#^Parameter \#1 \$amount of function wc_stock_amount expects float\|int, int\|null given\.$#'
 			identifier: argument.type
@@ -68814,6 +68754,30 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/Products/Controller.php

+		-
+			message: '#^Parameter \#1 \$value of method WC_Product_Attribute\:\:set_name\(\) expects string, array\|string given\.$#'
+			identifier: argument.type
+			count: 2
+			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
+
+		-
+			message: '#^Parameter \#1 \$value of method WC_Product_Attribute\:\:set_position\(\) expects int, string given\.$#'
+			identifier: argument.type
+			count: 2
+			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
+
+		-
+			message: '#^Parameter \#1 \$value of method WC_Product_Attribute\:\:set_variation\(\) expects bool, int given\.$#'
+			identifier: argument.type
+			count: 2
+			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
+
+		-
+			message: '#^Parameter \#1 \$value of method WC_Product_Attribute\:\:set_visible\(\) expects bool, int given\.$#'
+			identifier: argument.type
+			count: 2
+			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
+
 		-
 			message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(string\)\: bool\)\|null, ''strlen'' given\.$#'
 			identifier: argument.type
@@ -68898,12 +68862,6 @@ parameters:
 			count: 1
 			path: src/Internal/RestApi/Routes/V4/Products/Controller.php

-		-
-			message: '#^Throwing object of an unknown class Automattic\\WooCommerce\\Internal\\RestApi\\Routes\\V4\\Products\\WC_REST_Exception\.$#'
-			identifier: class.notFound
-			count: 2
-			path: src/Internal/RestApi/Routes/V4/Products/Controller.php
-
 		-
 			message: '#^Cannot access property \$max_num_pages on array\|object\.$#'
 			identifier: property.nonObject
diff --git a/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php b/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php
index 0654d0888f5..c5f06a6aaff 100644
--- a/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php
+++ b/plugins/woocommerce/src/Internal/RestApi/Routes/V4/Products/Controller.php
@@ -26,7 +26,11 @@ use WP_REST_Response;
 use WP_Error;
 use WC_Admin_Duplicate_Product;
 use WC_REST_CRUD_Controller;
+use WC_Data_Store;
+use WC_Product_Attribute;
 use WC_Product_Factory;
+use WC_Product_Simple;
+use WC_REST_Exception;


 defined( 'ABSPATH' ) || exit;
@@ -2230,7 +2234,7 @@ class Controller extends WC_REST_Products_V2_Controller {
 		$exclude_ids = $request->get_param( 'exclude' );
 		$limit       = $request->get_param( 'limit' ) ? $request->get_param( 'limit' ) : 5;

-		$data_store = \WC_Data_Store::load( 'product' );
+		$data_store = WC_Data_Store::load( 'product' );
 		// @phpstan-ignore-next-line method.notFound
 		$this->suggested_products_ids = $data_store->get_related_products(
 			$categories,