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.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / API / Reports / Customers / Stats / Controller.php
woocommerce / src / Admin / API / Reports / Customers / Stats Last commit date
Controller.php 3 months ago DataStore.php 1 year ago Query.php 1 year ago
Controller.php
415 lines
1 <?php
2 /**
3 * REST API Reports customers stats controller
4 *
5 * Handles requests to the /reports/customers/stats endpoint.
6 */
7
8 namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats;
9
10 use Automattic\WooCommerce\Admin\API\Reports\Customers\Query;
11 use Automattic\WooCommerce\Admin\API\Reports\Customers\Controller as CustomersController;
12
13 defined( 'ABSPATH' ) || exit;
14
15 use Automattic\WooCommerce\Admin\API\Reports\TimeInterval;
16
17 /**
18 * REST API Reports customers stats controller class.
19 *
20 * @internal
21 * @extends WC_REST_Reports_Controller
22 */
23 class Controller extends \WC_REST_Reports_Controller {
24 /**
25 * Endpoint namespace.
26 *
27 * @var string
28 */
29 protected $namespace = 'wc-analytics';
30
31 /**
32 * Route base.
33 *
34 * @var string
35 */
36 protected $rest_base = 'reports/customers/stats';
37
38 /**
39 * Maps query arguments from the REST request.
40 *
41 * @param array $request Request array.
42 * @return array
43 */
44 protected function prepare_reports_query( $request ) {
45 $args = array();
46 $args['registered_before'] = $request['registered_before'];
47 $args['registered_after'] = $request['registered_after'];
48 $args['match'] = $request['match'];
49 $args['search'] = $request['search'];
50 $args['name_includes'] = $request['name_includes'];
51 $args['name_excludes'] = $request['name_excludes'];
52 $args['username_includes'] = $request['username_includes'];
53 $args['username_excludes'] = $request['username_excludes'];
54 $args['email_includes'] = $request['email_includes'];
55 $args['email_excludes'] = $request['email_excludes'];
56 $args['country_includes'] = $request['country_includes'];
57 $args['country_excludes'] = $request['country_excludes'];
58 $args['last_active_before'] = $request['last_active_before'];
59 $args['last_active_after'] = $request['last_active_after'];
60 $args['orders_count_min'] = $request['orders_count_min'];
61 $args['orders_count_max'] = $request['orders_count_max'];
62 $args['total_spend_min'] = $request['total_spend_min'];
63 $args['total_spend_max'] = $request['total_spend_max'];
64 $args['avg_order_value_min'] = $request['avg_order_value_min'];
65 $args['avg_order_value_max'] = $request['avg_order_value_max'];
66 $args['last_order_before'] = $request['last_order_before'];
67 $args['last_order_after'] = $request['last_order_after'];
68 $args['customers'] = $request['customers'];
69 $args['customers_exclude'] = $request['customers_exclude'];
70 $args['fields'] = $request['fields'];
71 $args['force_cache_refresh'] = $request['force_cache_refresh'];
72
73 $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' );
74 $normalized_params_numeric = TimeInterval::normalize_between_params( $request, $between_params_numeric, false );
75 $between_params_date = array( 'last_active', 'registered' );
76 $normalized_params_date = TimeInterval::normalize_between_params( $request, $between_params_date, true );
77 $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date );
78
79 $args = CustomersController::consolidate_customer_id_filters( $args );
80
81 return $args;
82 }
83
84 /**
85 * Get all reports.
86 *
87 * @param WP_REST_Request $request Request data.
88 * @return array|WP_Error
89 */
90 public function get_items( $request ) {
91 $query_args = $this->prepare_reports_query( $request );
92 $customers_query = new Query( $query_args, 'customers-stats' );
93 $report_data = $customers_query->get_data();
94 $out_data = array(
95 'totals' => $report_data,
96 );
97
98 return rest_ensure_response( $out_data );
99 }
100
101 /**
102 * Prepare a report data item for serialization.
103 *
104 * @param array $report Report data item as returned from Data Store.
105 * @param \WP_REST_Request $request Request object.
106 * @return \WP_REST_Response
107 */
108 public function prepare_item_for_response( $report, $request ) {
109 $data = $report;
110
111 $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
112 $data = $this->add_additional_fields_to_object( $data, $request );
113 $data = $this->filter_response_by_context( $data, $context );
114
115 // Wrap the data in a response object.
116 $response = rest_ensure_response( $data );
117
118 /**
119 * Filter a report returned from the API.
120 *
121 * Allows modification of the report data right before it is returned.
122 *
123 * @param WP_REST_Response $response The response object.
124 * @param object $report The original report object.
125 * @param WP_REST_Request $request Request used to generate the response.
126 */
127 return apply_filters( 'woocommerce_rest_prepare_report_customers_stats', $response, $report, $request );
128 }
129
130 /**
131 * Get the Report's schema, conforming to JSON Schema.
132 *
133 * @return array
134 */
135 public function get_item_schema() {
136 // @todo Should any of these be 'indicator's?
137 $totals = array(
138 'customers_count' => array(
139 'description' => __( 'Number of customers.', 'woocommerce' ),
140 'type' => 'integer',
141 'context' => array( 'view', 'edit' ),
142 'readonly' => true,
143 ),
144 'avg_orders_count' => array(
145 'description' => __( 'Average number of orders.', 'woocommerce' ),
146 'type' => 'integer',
147 'context' => array( 'view', 'edit' ),
148 'readonly' => true,
149 ),
150 'avg_total_spend' => array(
151 'description' => __( 'Average total spend per customer.', 'woocommerce' ),
152 'type' => 'number',
153 'context' => array( 'view', 'edit' ),
154 'readonly' => true,
155 'format' => 'currency',
156 ),
157 'avg_avg_order_value' => array(
158 'description' => __( 'Average AOV per customer.', 'woocommerce' ),
159 'type' => 'number',
160 'context' => array( 'view', 'edit' ),
161 'readonly' => true,
162 'format' => 'currency',
163 ),
164 );
165
166 $schema = array(
167 '$schema' => 'http://json-schema.org/draft-04/schema#',
168 'title' => 'report_customers_stats',
169 'type' => 'object',
170 'properties' => array(
171 'totals' => array(
172 'description' => __( 'Totals data.', 'woocommerce' ),
173 'type' => 'object',
174 'context' => array( 'view', 'edit' ),
175 'readonly' => true,
176 'properties' => $totals,
177 ),
178 ),
179 );
180
181 return $this->add_additional_fields_schema( $schema );
182 }
183
184 /**
185 * Get the query params for collections.
186 *
187 * @return array
188 */
189 public function get_collection_params() {
190 $params = array();
191 $params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
192 $params['registered_before'] = array(
193 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
194 'type' => 'string',
195 'format' => 'date-time',
196 'validate_callback' => 'rest_validate_request_arg',
197 );
198 $params['registered_after'] = array(
199 'description' => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
200 'type' => 'string',
201 'format' => 'date-time',
202 'validate_callback' => 'rest_validate_request_arg',
203 );
204 $params['match'] = array(
205 'description' => __( 'Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categories', 'woocommerce' ),
206 'type' => 'string',
207 'default' => 'all',
208 'enum' => array(
209 'all',
210 'any',
211 ),
212 'validate_callback' => 'rest_validate_request_arg',
213 );
214 $params['search'] = array(
215 'description' => __( 'Limit response to objects with a customer field containing the search term. Searches the field provided by `searchby`.', 'woocommerce' ),
216 'type' => 'string',
217 'validate_callback' => 'rest_validate_request_arg',
218 );
219 $params['searchby'] = array(
220 'description' => 'Limit results with `search` and `searchby` to specific fields containing the search term.',
221 'type' => 'string',
222 'default' => 'name',
223 'enum' => array(
224 'name',
225 'username',
226 'email',
227 'all',
228 ),
229 );
230 $params['name_includes'] = array(
231 'description' => __( 'Limit response to objects with specific names.', 'woocommerce' ),
232 'type' => 'string',
233 'validate_callback' => 'rest_validate_request_arg',
234 );
235 $params['name_excludes'] = array(
236 'description' => __( 'Limit response to objects excluding specific names.', 'woocommerce' ),
237 'type' => 'string',
238 'validate_callback' => 'rest_validate_request_arg',
239 );
240 $params['username_includes'] = array(
241 'description' => __( 'Limit response to objects with specific usernames.', 'woocommerce' ),
242 'type' => 'string',
243 'validate_callback' => 'rest_validate_request_arg',
244 );
245 $params['username_excludes'] = array(
246 'description' => __( 'Limit response to objects excluding specific usernames.', 'woocommerce' ),
247 'type' => 'string',
248 'validate_callback' => 'rest_validate_request_arg',
249 );
250 $params['email_includes'] = array(
251 'description' => __( 'Limit response to objects including emails.', 'woocommerce' ),
252 'type' => 'string',
253 'validate_callback' => 'rest_validate_request_arg',
254 );
255 $params['email_excludes'] = array(
256 'description' => __( 'Limit response to objects excluding emails.', 'woocommerce' ),
257 'type' => 'string',
258 'validate_callback' => 'rest_validate_request_arg',
259 );
260 $params['country_includes'] = array(
261 'description' => __( 'Limit response to objects with specific countries.', 'woocommerce' ),
262 'type' => 'string',
263 'validate_callback' => 'rest_validate_request_arg',
264 );
265 $params['country_excludes'] = array(
266 'description' => __( 'Limit response to objects excluding specific countries.', 'woocommerce' ),
267 'type' => 'string',
268 'validate_callback' => 'rest_validate_request_arg',
269 );
270 $params['last_active_before'] = array(
271 'description' => __( 'Limit response to objects last active before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
272 'type' => 'string',
273 'format' => 'date-time',
274 'validate_callback' => 'rest_validate_request_arg',
275 );
276 $params['last_active_after'] = array(
277 'description' => __( 'Limit response to objects last active after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
278 'type' => 'string',
279 'format' => 'date-time',
280 'validate_callback' => 'rest_validate_request_arg',
281 );
282 $params['last_active_between'] = array(
283 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ),
284 'type' => 'array',
285 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_date_arg' ),
286 'items' => array(
287 'type' => 'string',
288 ),
289 );
290 $params['registered_before'] = array(
291 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
292 'type' => 'string',
293 'format' => 'date-time',
294 'validate_callback' => 'rest_validate_request_arg',
295 );
296 $params['registered_after'] = array(
297 'description' => __( 'Limit response to objects registered after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
298 'type' => 'string',
299 'format' => 'date-time',
300 'validate_callback' => 'rest_validate_request_arg',
301 );
302 $params['registered_between'] = array(
303 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce' ),
304 'type' => 'array',
305 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_date_arg' ),
306 'items' => array(
307 'type' => 'string',
308 ),
309 );
310 $params['orders_count_min'] = array(
311 'description' => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce' ),
312 'type' => 'integer',
313 'sanitize_callback' => 'absint',
314 'validate_callback' => 'rest_validate_request_arg',
315 );
316 $params['orders_count_max'] = array(
317 'description' => __( 'Limit response to objects with an order count less than or equal to given integer.', 'woocommerce' ),
318 'type' => 'integer',
319 'sanitize_callback' => 'absint',
320 'validate_callback' => 'rest_validate_request_arg',
321 );
322 $params['orders_count_between'] = array(
323 'description' => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce' ),
324 'type' => 'array',
325 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ),
326 'items' => array(
327 'type' => 'integer',
328 ),
329 );
330 $params['total_spend_min'] = array(
331 'description' => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce' ),
332 'type' => 'number',
333 'validate_callback' => 'rest_validate_request_arg',
334 );
335 $params['total_spend_max'] = array(
336 'description' => __( 'Limit response to objects with a total order spend less than or equal to given number.', 'woocommerce' ),
337 'type' => 'number',
338 'validate_callback' => 'rest_validate_request_arg',
339 );
340 $params['total_spend_between'] = array(
341 'description' => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce' ),
342 'type' => 'array',
343 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ),
344 'items' => array(
345 'type' => 'integer',
346 ),
347 );
348 $params['avg_order_value_min'] = array(
349 'description' => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce' ),
350 'type' => 'number',
351 'validate_callback' => 'rest_validate_request_arg',
352 );
353 $params['avg_order_value_max'] = array(
354 'description' => __( 'Limit response to objects with an average order spend less than or equal to given number.', 'woocommerce' ),
355 'type' => 'number',
356 'validate_callback' => 'rest_validate_request_arg',
357 );
358 $params['avg_order_value_between'] = array(
359 'description' => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce' ),
360 'type' => 'array',
361 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ),
362 'items' => array(
363 'type' => 'integer',
364 ),
365 );
366 $params['last_order_before'] = array(
367 'description' => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
368 'type' => 'string',
369 'format' => 'date-time',
370 'validate_callback' => 'rest_validate_request_arg',
371 );
372 $params['last_order_after'] = array(
373 'description' => __( 'Limit response to objects with last order after (or at) a given ISO8601 compliant datetime.', 'woocommerce' ),
374 'type' => 'string',
375 'format' => 'date-time',
376 'validate_callback' => 'rest_validate_request_arg',
377 );
378 $params['customers'] = array(
379 'description' => __( 'Limit result to items with specified customer ids.', 'woocommerce' ),
380 'type' => 'array',
381 'sanitize_callback' => 'wp_parse_id_list',
382 'validate_callback' => 'rest_validate_request_arg',
383 'items' => array(
384 'type' => 'integer',
385 ),
386 );
387 $params['customers_exclude'] = array(
388 'description' => __( 'Limit result to exclude items with specified customer ids.', 'woocommerce' ),
389 'type' => 'array',
390 'sanitize_callback' => 'wp_parse_id_list',
391 'validate_callback' => 'rest_validate_request_arg',
392 'items' => array(
393 'type' => 'integer',
394 ),
395 );
396 $params['fields'] = array(
397 'description' => __( 'Limit stats fields to the specified items.', 'woocommerce' ),
398 'type' => 'array',
399 'sanitize_callback' => 'wp_parse_slug_list',
400 'validate_callback' => 'rest_validate_request_arg',
401 'items' => array(
402 'type' => 'string',
403 ),
404 );
405 $params['force_cache_refresh'] = array(
406 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ),
407 'type' => 'boolean',
408 'sanitize_callback' => 'wp_validate_boolean',
409 'validate_callback' => 'rest_validate_request_arg',
410 );
411
412 return $params;
413 }
414 }
415