From d5c0fab66fa8137fbcb90ddddd9f33e197dde921 Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:29:49 -0700 Subject: [PATCH] Stats: Add "all" searchby param to Customer report endpoints Makes it possible to do a partial match search for customers across name, username, and email, instead of having to choose one of those fields. Refs #33383 --- .../woocommerce/src/Admin/API/Reports/Customers/Controller.php | 1 + .../woocommerce/src/Admin/API/Reports/Customers/DataStore.php | 3 +++ .../src/Admin/API/Reports/Customers/Stats/Controller.php | 1 + 3 files changed, 5 insertions(+) diff --git a/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php index 5809fc67986..41144bc2421 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php @@ -354,6 +354,7 @@ class Controller extends GenericController implements ExportableInterface { 'name', 'username', 'email', + 'all', ), ); $params['name_includes'] = array( diff --git a/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php b/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php index 4452b99b0b6..8520c5ac461 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php @@ -297,6 +297,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'name', 'username', 'email', + 'all', ); if ( ! empty( $query_args['search'] ) ) { @@ -304,6 +305,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { if ( empty( $query_args['searchby'] ) || 'name' === $query_args['searchby'] || ! in_array( $query_args['searchby'], $search_params, true ) ) { $searchby = "CONCAT_WS( ' ', first_name, last_name )"; + } elseif ( 'all' === $query_args['searchby'] ) { + $searchby = "CONCAT_WS( ' ', first_name, last_name, username, email )"; } else { $searchby = $query_args['searchby']; } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Customers/Stats/Controller.php b/plugins/woocommerce/src/Admin/API/Reports/Customers/Stats/Controller.php index 0f4d75206aa..95496f7ae30 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Customers/Stats/Controller.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Customers/Stats/Controller.php @@ -218,6 +218,7 @@ class Controller extends \WC_REST_Reports_Controller { 'name', 'username', 'email', + 'all', ), ); $params['name_includes'] = array(