Add order date filter to customers data store (https://github.com/woocommerce/woocommerce-admin/pull/2094)
* Add before and after params to customers controller * Map before and after order params to order creation date filter * Hook up customer date filter params in leaderboards controller
This commit is contained in:
parent
bdc94320f4
commit
8bc3d8622e
|
@ -206,9 +206,11 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller {
|
|||
$customers_data_store = new WC_Admin_Reports_Customers_Data_Store();
|
||||
$customers_data = $per_page > 0 ? $customers_data_store->get_data(
|
||||
array(
|
||||
'orderby' => 'total_spend',
|
||||
'order' => 'desc',
|
||||
'per_page' => $per_page,
|
||||
'orderby' => 'total_spend',
|
||||
'order' => 'desc',
|
||||
'order_after' => $after,
|
||||
'order_before' => $before,
|
||||
'per_page' => $per_page,
|
||||
)
|
||||
)->data : array();
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Control
|
|||
$args = array();
|
||||
$args['registered_before'] = $request['registered_before'];
|
||||
$args['registered_after'] = $request['registered_after'];
|
||||
$args['order_before'] = $request['before'];
|
||||
$args['order_after'] = $request['after'];
|
||||
$args['page'] = $request['page'];
|
||||
$args['per_page'] = $request['per_page'];
|
||||
$args['order'] = $request['order'];
|
||||
|
@ -288,6 +290,18 @@ class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Control
|
|||
'format' => 'date-time',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
);
|
||||
$params['after'] = array(
|
||||
'description' => __( 'Limit response to resources with orders published after a given ISO8601 compliant date.', 'woocommerce-admin' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
);
|
||||
$params['before'] = array(
|
||||
'description' => __( 'Limit response to resources with orders published before a given ISO8601 compliant date.', 'woocommerce-admin' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
);
|
||||
$params['page'] = array(
|
||||
'description' => __( 'Current page of the collection.', 'woocommerce-admin' ),
|
||||
'type' => 'integer',
|
||||
|
|
|
@ -144,6 +144,10 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
|
|||
'clause' => 'where',
|
||||
'column' => $table_name . '.date_registered',
|
||||
),
|
||||
'order' => array(
|
||||
'clause' => 'where',
|
||||
'column' => $wpdb->prefix . 'wc_order_stats.date_created',
|
||||
),
|
||||
'last_active' => array(
|
||||
'clause' => 'where',
|
||||
'column' => $table_name . '.date_last_active',
|
||||
|
@ -338,11 +342,13 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
|
|||
|
||||
// These defaults are only partially applied when used via REST API, as that has its own defaults.
|
||||
$defaults = array(
|
||||
'per_page' => get_option( 'posts_per_page' ),
|
||||
'page' => 1,
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'date_registered',
|
||||
'fields' => '*',
|
||||
'per_page' => get_option( 'posts_per_page' ),
|
||||
'page' => 1,
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'date_registered',
|
||||
'order_before' => WC_Admin_Reports_Interval::default_before(),
|
||||
'order_after' => WC_Admin_Reports_Interval::default_after(),
|
||||
'fields' => '*',
|
||||
);
|
||||
$query_args = wp_parse_args( $query_args, $defaults );
|
||||
$this->normalize_timezones( $query_args, $defaults );
|
||||
|
|
Loading…
Reference in New Issue