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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 / Variations / Controller.php
woocommerce / src / Admin / API / Reports / Variations Last commit date
Stats 4 weeks ago Controller.php 3 months ago DataStore.php 10 months ago Query.php 1 year ago
Controller.php
448 lines
1 <?php
2 /**
3 * REST API Reports products controller
4 *
5 * Handles requests to the /reports/products endpoint.
6 */
7
8 namespace Automattic\WooCommerce\Admin\API\Reports\Variations;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Automattic\WooCommerce\Admin\API\Reports\ExportableInterface;
13 use Automattic\WooCommerce\Admin\API\Reports\ExportableTraits;
14 use Automattic\WooCommerce\Admin\API\Reports\GenericController;
15 use Automattic\WooCommerce\Admin\API\Reports\GenericQuery;
16 use Automattic\WooCommerce\Admin\API\Reports\OrderAwareControllerTrait;
17
18
19 /**
20 * REST API Reports products controller class.
21 *
22 * @internal
23 * @extends GenericController
24 */
25 class Controller extends GenericController implements ExportableInterface {
26
27 // The controller does not use this trait. It's here for API backward compatibility.
28 use OrderAwareControllerTrait;
29
30 /**
31 * Exportable traits.
32 */
33 use ExportableTraits;
34
35 /**
36 * Route base.
37 *
38 * @var string
39 */
40 protected $rest_base = 'reports/variations';
41
42 /**
43 * Mapping between external parameter name and name used in query class.
44 *
45 * @var array
46 */
47 protected $param_mapping = array(
48 'variations' => 'variation_includes',
49 'products' => 'product_includes',
50 );
51
52 /**
53 * Get data from `'variations'` GenericQuery.
54 *
55 * @override GenericController::get_datastore_data()
56 *
57 * @param array $query_args Query arguments.
58 * @return mixed Results from the data store.
59 */
60 protected function get_datastore_data( $query_args = array() ) {
61 $query = new GenericQuery( $query_args, 'variations' );
62 return $query->get_data();
63 }
64
65 /**
66 * Prepare a report data item for serialization.
67 *
68 * @param array $report Report data item as returned from Data Store.
69 * @param WP_REST_Request $request Request object.
70 * @return WP_REST_Response
71 */
72 public function prepare_item_for_response( $report, $request ) {
73 // Wrap the data in a response object.
74 $response = parent::prepare_item_for_response( $report, $request );
75
76 $response->add_links( $this->prepare_links( $report ) );
77
78 /**
79 * Filter a report returned from the API.
80 *
81 * Allows modification of the report data right before it is returned.
82 *
83 * @since 6.5.0
84 *
85 * @param WP_REST_Response $response The response object.
86 * @param object $report The original report object.
87 * @param WP_REST_Request $request Request used to generate the response.
88 */
89 return apply_filters( 'woocommerce_rest_prepare_report_variations', $response, $report, $request );
90 }
91
92 /**
93 * Maps query arguments from the REST request.
94 *
95 * @param array $request Request array.
96 * @return array
97 */
98 protected function prepare_reports_query( $request ) {
99 $args = array();
100 /**
101 * Experimental: Filter the list of parameters provided when querying data from the data store.
102 *
103 * @ignore
104 *
105 * @param array $collection_params List of parameters.
106 *
107 * @since 6.5.0
108 */
109 $collection_params = apply_filters(
110 'experimental_woocommerce_analytics_variations_collection_params',
111 $this->get_collection_params()
112 );
113 $registered = array_keys( $collection_params );
114 foreach ( $registered as $param_name ) {
115 if ( isset( $request[ $param_name ] ) ) {
116 if ( isset( $this->param_mapping[ $param_name ] ) ) {
117 $args[ $this->param_mapping[ $param_name ] ] = $request[ $param_name ];
118 } else {
119 $args[ $param_name ] = $request[ $param_name ];
120 }
121 }
122 }
123 return $args;
124 }
125
126 /**
127 * Prepare links for the request.
128 *
129 * @param array $object Object data.
130 * @return array Links for the given post.
131 */
132 protected function prepare_links( $object ) {
133 $links = array(
134 'product' => array(
135 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, 'products', $object['product_id'] ) ),
136 ),
137 'variation' => array(
138 'href' => rest_url( sprintf( '/%s/%s/%d/%s/%d', $this->namespace, 'products', $object['product_id'], 'variation', $object['variation_id'] ) ),
139 ),
140 );
141
142 return $links;
143 }
144
145 /**
146 * Get the Report's schema, conforming to JSON Schema.
147 *
148 * @return array
149 */
150 public function get_item_schema() {
151 $schema = array(
152 '$schema' => 'http://json-schema.org/draft-04/schema#',
153 'title' => 'report_varitations',
154 'type' => 'object',
155 'properties' => array(
156 'product_id' => array(
157 'type' => 'integer',
158 'readonly' => true,
159 'context' => array( 'view', 'edit' ),
160 'description' => __( 'Product ID.', 'woocommerce' ),
161 ),
162 'variation_id' => array(
163 'type' => 'integer',
164 'readonly' => true,
165 'context' => array( 'view', 'edit' ),
166 'description' => __( 'Product ID.', 'woocommerce' ),
167 ),
168 'items_sold' => array(
169 'type' => 'integer',
170 'readonly' => true,
171 'context' => array( 'view', 'edit' ),
172 'description' => __( 'Number of items sold.', 'woocommerce' ),
173 ),
174 'net_revenue' => array(
175 'type' => 'number',
176 'readonly' => true,
177 'context' => array( 'view', 'edit' ),
178 'description' => __( 'Total Net sales of all items sold.', 'woocommerce' ),
179 ),
180 'orders_count' => array(
181 'type' => 'integer',
182 'readonly' => true,
183 'context' => array( 'view', 'edit' ),
184 'description' => __( 'Number of orders product appeared in.', 'woocommerce' ),
185 ),
186 'extended_info' => array(
187 'name' => array(
188 'type' => 'string',
189 'readonly' => true,
190 'context' => array( 'view', 'edit' ),
191 'description' => __( 'Product name.', 'woocommerce' ),
192 ),
193 'price' => array(
194 'type' => 'number',
195 'readonly' => true,
196 'context' => array( 'view', 'edit' ),
197 'description' => __( 'Product price.', 'woocommerce' ),
198 ),
199 'image' => array(
200 'type' => 'string',
201 'readonly' => true,
202 'context' => array( 'view', 'edit' ),
203 'description' => __( 'Product image.', 'woocommerce' ),
204 ),
205 'permalink' => array(
206 'type' => 'string',
207 'readonly' => true,
208 'context' => array( 'view', 'edit' ),
209 'description' => __( 'Product link.', 'woocommerce' ),
210 ),
211 'attributes' => array(
212 'type' => 'array',
213 'readonly' => true,
214 'context' => array( 'view', 'edit' ),
215 'description' => __( 'Product attributes.', 'woocommerce' ),
216 ),
217 'stock_status' => array(
218 'type' => 'string',
219 'readonly' => true,
220 'context' => array( 'view', 'edit' ),
221 'description' => __( 'Product inventory status.', 'woocommerce' ),
222 ),
223 'stock_quantity' => array(
224 'type' => 'integer',
225 'readonly' => true,
226 'context' => array( 'view', 'edit' ),
227 'description' => __( 'Product inventory quantity.', 'woocommerce' ),
228 ),
229 'low_stock_amount' => array(
230 'type' => 'integer',
231 'readonly' => true,
232 'context' => array( 'view', 'edit' ),
233 'description' => __( 'Product inventory threshold for low stock.', 'woocommerce' ),
234 ),
235 ),
236 ),
237 );
238
239 return $this->add_additional_fields_schema( $schema );
240 }
241
242 /**
243 * Get the query params for collections.
244 *
245 * @return array
246 */
247 public function get_collection_params() {
248 $params = parent::get_collection_params();
249 $params['orderby']['enum'] = $this->apply_custom_orderby_filters(
250 array(
251 'date',
252 'net_revenue',
253 'orders_count',
254 'items_sold',
255 'sku',
256 )
257 );
258 $params['match'] = array(
259 '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' ),
260 'type' => 'string',
261 'default' => 'all',
262 'enum' => array(
263 'all',
264 'any',
265 ),
266 'validate_callback' => 'rest_validate_request_arg',
267 );
268 $params['product_includes'] = array(
269 'description' => __( 'Limit result set to items that have the specified parent product(s).', 'woocommerce' ),
270 'type' => 'array',
271 'items' => array(
272 'type' => 'integer',
273 ),
274 'default' => array(),
275 'sanitize_callback' => 'wp_parse_id_list',
276 'validate_callback' => 'rest_validate_request_arg',
277 );
278 $params['product_excludes'] = array(
279 'description' => __( 'Limit result set to items that don\'t have the specified parent product(s).', 'woocommerce' ),
280 'type' => 'array',
281 'items' => array(
282 'type' => 'integer',
283 ),
284 'default' => array(),
285 'validate_callback' => 'rest_validate_request_arg',
286 'sanitize_callback' => 'wp_parse_id_list',
287 );
288 $params['variations'] = array(
289 'description' => __( 'Limit result to items with specified variation ids.', 'woocommerce' ),
290 'type' => 'array',
291 'sanitize_callback' => 'wp_parse_id_list',
292 'validate_callback' => 'rest_validate_request_arg',
293 'items' => array(
294 'type' => 'integer',
295 ),
296 );
297 $params['extended_info'] = array(
298 'description' => __( 'Add additional piece of info about each variation to the report.', 'woocommerce' ),
299 'type' => 'boolean',
300 'default' => false,
301 'sanitize_callback' => 'wc_string_to_bool',
302 'validate_callback' => 'rest_validate_request_arg',
303 );
304 $params['attribute_is'] = array(
305 'description' => __( 'Limit result set to variations that include the specified attributes.', 'woocommerce' ),
306 'type' => 'array',
307 'items' => array(
308 'type' => 'array',
309 ),
310 'default' => array(),
311 'validate_callback' => 'rest_validate_request_arg',
312 );
313 $params['attribute_is_not'] = array(
314 'description' => __( 'Limit result set to variations that don\'t include the specified attributes.', 'woocommerce' ),
315 'type' => 'array',
316 'items' => array(
317 'type' => 'array',
318 ),
319 'default' => array(),
320 'validate_callback' => 'rest_validate_request_arg',
321 );
322 $params['category_includes'] = array(
323 'description' => __( 'Limit result set to variations in the specified categories.', 'woocommerce' ),
324 'type' => 'array',
325 'sanitize_callback' => 'wp_parse_id_list',
326 'validate_callback' => 'rest_validate_request_arg',
327 'items' => array(
328 'type' => 'integer',
329 ),
330 );
331 $params['category_excludes'] = array(
332 'description' => __( 'Limit result set to variations not in the specified categories.', 'woocommerce' ),
333 'type' => 'array',
334 'sanitize_callback' => 'wp_parse_id_list',
335 'validate_callback' => 'rest_validate_request_arg',
336 'items' => array(
337 'type' => 'integer',
338 ),
339 );
340 $params['products'] = array(
341 'description' => __( 'Limit result to items with specified product ids.', 'woocommerce' ),
342 'type' => 'array',
343 'sanitize_callback' => 'wp_parse_id_list',
344 'validate_callback' => 'rest_validate_request_arg',
345 'items' => array(
346 'type' => 'integer',
347 ),
348 );
349
350 return $params;
351 }
352
353 /**
354 * Get stock status column export value.
355 *
356 * @param array $status Stock status from report row.
357 * @return string
358 */
359 protected function get_stock_status( $status ) {
360 $statuses = wc_get_product_stock_status_options();
361
362 return isset( $statuses[ $status ] ) ? $statuses[ $status ] : '';
363 }
364
365 /**
366 * Get the column names for export.
367 *
368 * @return array Key value pair of Column ID => Label.
369 */
370 public function get_export_columns() {
371 $export_columns = array(
372 'product_name' => __( 'Product / Variation title', 'woocommerce' ),
373 'sku' => __( 'SKU', 'woocommerce' ),
374 'items_sold' => __( 'Items sold', 'woocommerce' ),
375 'net_revenue' => __( 'N. Revenue', 'woocommerce' ),
376 'orders_count' => __( 'Orders', 'woocommerce' ),
377 );
378
379 if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
380 $export_columns['stock_status'] = __( 'Status', 'woocommerce' );
381 $export_columns['stock'] = __( 'Stock', 'woocommerce' );
382 }
383
384 /**
385 * Filter to add or remove column names from the variations report for
386 * export.
387 *
388 * @since 10.7.0
389 * @param array $export_columns Key value pair of column ID and label.
390 */
391 return apply_filters( 'woocommerce_report_variations_export_columns', $export_columns );
392 }
393
394 /**
395 * Get the column values for export.
396 *
397 * @param array $item Single report item/row.
398 * @return array Key value pair of Column ID => Row Value.
399 */
400 public function prepare_item_for_export( $item ) {
401 $product_name = $item['extended_info']['name'];
402 /**
403 * Filter the separator used in the product variation title.
404 *
405 * @since 10.2.0
406 * @param string $separator The separator.
407 * @param \WC_Product $product The product object.
408 * @return string The separator.
409 */
410 $separator = apply_filters( 'woocommerce_product_variation_title_attributes_separator', ' - ', new \WC_Product() );
411 if ( ! empty( $item['extended_info']['attributes'] ) && strpos( $product_name, $separator ) === false ) {
412 $attributes = array();
413 foreach ( $item['extended_info']['attributes'] as $attribute ) {
414 if ( empty( $attribute['option'] ) ) {
415 // translators: %s: the attribute name.
416 $attributes[] = sprintf( __( 'Any %s', 'woocommerce' ), ucfirst( $attribute['name'] ) );
417 } else {
418 $attributes[] = $attribute['option'];
419 }
420 }
421 $product_name .= $separator . implode( ', ', $attributes );
422 }
423
424 $export_item = array(
425 'product_name' => $product_name,
426 'sku' => $item['extended_info']['sku'],
427 'items_sold' => $item['items_sold'],
428 'net_revenue' => self::csv_number_format( $item['net_revenue'] ),
429 'orders_count' => $item['orders_count'],
430 );
431
432 if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
433 $export_item['stock_status'] = $this->get_stock_status( $item['extended_info']['stock_status'] );
434 $export_item['stock'] = $item['extended_info']['stock_quantity'];
435 }
436
437 /**
438 * Filter to prepare extra columns in the export item for the variations
439 * report.
440 *
441 * @since 10.7.0
442 * @param array $export_item Key value pair of column ID and row value.
443 * @param array $item The original report item.
444 */
445 return apply_filters( 'woocommerce_report_variations_prepare_export_item', $export_item, $item );
446 }
447 }
448