Added segmentby to schema, query arguments and allows parameters in the controller for taxes/stats.

This commit is contained in:
Peter Fabian 2019-01-30 12:16:37 +01:00
parent 6efef57cba
commit 0d95552157
1 changed files with 60 additions and 21 deletions

View File

@ -77,6 +77,7 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr
$args['orderby'] = $request['orderby'];
$args['order'] = $request['order'];
$args['taxes'] = (array) $request['taxes'];
$args['segmentby'] = $request['segmentby'];
return $args;
}
@ -161,7 +162,7 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr
* @return array
*/
public function get_item_schema() {
$totals = array(
$data_values = array(
'total_tax' => array(
'description' => __( 'Total tax.', 'wc-admin' ),
'type' => 'number',
@ -200,6 +201,36 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr
),
);
$segments = array(
'segments' => array(
'description' => __( 'Reports data grouped by segment condition.', 'wc-admin' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'items' => array(
'type' => 'object',
'properties' => array(
'segment_id' => array(
'description' => __( 'Segment identificator.', 'wc-admin' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'enum' => array( 'day', 'week', 'month', 'year' ),
),
'subtotals' => array(
'description' => __( 'Interval subtotals.', 'wc-admin' ),
'type' => 'object',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'properties' => $data_values,
),
),
),
),
);
$totals = array_merge( $data_values, $segments );
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'report_taxes_stats',
@ -347,6 +378,14 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr
'type' => 'integer',
),
);
$params['segmentby'] = array(
'description' => __( 'Segment the response by additional constraint.', 'wc-admin' ),
'type' => 'string',
'enum' => array(
'tax_code',
),
'validate_callback' => 'rest_validate_request_arg',
);
return $params;
}