fix: Resolve route conflict - OrdersController was hijacking /products endpoint
ROOT CAUSE FOUND! OrdersController registered /products BEFORE ProductsController: - OrdersController::init() called first (line 25 in Routes.php) - ProductsController::register_routes() called later (line 95) - WordPress uses FIRST matching route - OrdersController /products was winning! This explains EVERYTHING: ✅ Route registered: SUCCESS ✅ Callback is_callable: YES ✅ Permissions: ALLOWED ✅ Request goes to /woonoow/v1/products ❌ But OrdersController::products() was handling it! Solution: 1. Changed OrdersController route from /products to /products/search 2. Updated ProductsApi.search() to use /products/search 3. Now /products is free for ProductsController! Result: - /products → ProductsController::get_products() (full product list) - /products/search → OrdersController::products() (lightweight search for orders) This will finally make ProductsController work!
This commit is contained in:
@@ -96,7 +96,7 @@ export const OrdersApi = {
|
||||
};
|
||||
|
||||
export const ProductsApi = {
|
||||
search: (search: string, limit = 10) => api.get('/products', { search, limit }),
|
||||
search: (search: string, limit = 10) => api.get('/products/search', { search, limit }),
|
||||
};
|
||||
|
||||
export const CustomersApi = {
|
||||
|
||||
@@ -75,7 +75,8 @@ class OrdersController {
|
||||
]);
|
||||
|
||||
// Lightweight product search to help build orders from admin UI
|
||||
register_rest_route('woonoow/v1', '/products', [
|
||||
// Changed from /products to /products/search to avoid conflict with ProductsController
|
||||
register_rest_route('woonoow/v1', '/products/search', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [__CLASS__, 'products'],
|
||||
'permission_callback' => function () { return current_user_can('manage_woocommerce'); },
|
||||
|
||||
Reference in New Issue
Block a user