Added tests for advanced filters of orders report.
This commit is contained in:
parent
688b47aa7c
commit
a765a6df97
|
@ -31,6 +31,15 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
|
||||||
*/
|
*/
|
||||||
protected $rest_base = 'reports/products';
|
protected $rest_base = 'reports/products';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapping between external parameter name and name used in query class.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $param_mapping = array(
|
||||||
|
'products' => 'product_includes',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get items.
|
* Get items.
|
||||||
*
|
*
|
||||||
|
@ -43,9 +52,13 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
|
||||||
$registered = array_keys( $this->get_collection_params() );
|
$registered = array_keys( $this->get_collection_params() );
|
||||||
foreach ( $registered as $param_name ) {
|
foreach ( $registered as $param_name ) {
|
||||||
if ( isset( $request[ $param_name ] ) ) {
|
if ( isset( $request[ $param_name ] ) ) {
|
||||||
|
if ( isset( $this->param_mapping[ $param_name ] ) ) {
|
||||||
|
$args[ $this->param_mapping[ $param_name ] ] = $request[ $param_name ];
|
||||||
|
} else {
|
||||||
$args[ $param_name ] = $request[ $param_name ];
|
$args[ $param_name ] = $request[ $param_name ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$reports = new WC_Admin_Reports_Products_Query( $args );
|
$reports = new WC_Admin_Reports_Products_Query( $args );
|
||||||
$products_data = $reports->get_data();
|
$products_data = $reports->get_data();
|
||||||
|
@ -243,45 +256,16 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
|
||||||
),
|
),
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
);
|
);
|
||||||
$params['status_is'] = array(
|
$params['products'] = array(
|
||||||
'description' => __( 'Limit result set to items that have the specified order status.', 'wc-admin' ),
|
'description' => __( 'Limit result to items with specified product ids.', 'wc-admin' ),
|
||||||
'type' => 'array',
|
'type' => 'array',
|
||||||
'sanitize_callback' => 'wp_parse_slug_list',
|
'sanitize_callback' => 'wp_parse_id_list',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
'items' => array(
|
|
||||||
'enum' => $this->get_order_statuses(),
|
|
||||||
'type' => 'string',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
$params['status_is_not'] = array(
|
|
||||||
'description' => __( 'Limit result set to items that don\'t have the specified order status.', 'wc-admin' ),
|
|
||||||
'type' => 'array',
|
|
||||||
'sanitize_callback' => 'wp_parse_slug_list',
|
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
'items' => array(
|
|
||||||
'enum' => $this->get_order_statuses(),
|
|
||||||
'type' => 'string',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
$params['product_includes'] = array(
|
|
||||||
'description' => __( 'Limit result set to items that have the specified product(s) assigned.', 'wc-admin' ),
|
|
||||||
'type' => 'array',
|
|
||||||
'items' => array(
|
'items' => array(
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
),
|
),
|
||||||
'default' => array(),
|
|
||||||
'sanitize_callback' => 'wp_parse_id_list',
|
|
||||||
|
|
||||||
);
|
);
|
||||||
$params['product_excludes'] = array(
|
|
||||||
'description' => __( 'Limit result set to items that don\'t have the specified product(s) assigned.', 'wc-admin' ),
|
|
||||||
'type' => 'array',
|
|
||||||
'items' => array(
|
|
||||||
'type' => 'integer',
|
|
||||||
),
|
|
||||||
'default' => array(),
|
|
||||||
'sanitize_callback' => 'wp_parse_id_list',
|
|
||||||
);
|
|
||||||
$params['extended_product_info'] = array(
|
$params['extended_product_info'] = array(
|
||||||
'description' => __( 'Add additional piece of info about each product to the report.', 'wc-admin' ),
|
'description' => __( 'Add additional piece of info about each product to the report.', 'wc-admin' ),
|
||||||
'type' => 'boolean',
|
'type' => 'boolean',
|
||||||
|
@ -292,19 +276,4 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get order statuses without prefixes.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function get_order_statuses() {
|
|
||||||
$order_statuses = array();
|
|
||||||
|
|
||||||
foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
|
|
||||||
$order_statuses[] = str_replace( 'wc-', '', $status );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $order_statuses;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue