* Add the order status column to lookup table

* Fix order status filter for order stats

* Fix normalize order status and make static function
This commit is contained in:
Joshua T Flowers 2019-01-08 09:16:10 +08:00 committed by GitHub
parent 6ca0c628b2
commit f3346e9298
3 changed files with 7 additions and 5 deletions

View File

@ -404,6 +404,7 @@ class WC_Admin_Api_Init {
shipping_total double DEFAULT 0 NOT NULL,
net_total double DEFAULT 0 NOT NULL,
returning_customer boolean DEFAULT 0 NOT NULL,
status varchar(200) NOT NULL,
PRIMARY KEY (order_id),
KEY date_created (date_created)
) $collate;

View File

@ -410,7 +410,7 @@ class WC_Admin_Reports_Data_Store {
* @param string $status Order status.
* @return string
*/
protected function normalize_order_status( $status ) {
protected static function normalize_order_status( $status ) {
$status = trim( $status );
return 'wc-' . $status;
}
@ -773,14 +773,14 @@ class WC_Admin_Reports_Data_Store {
if ( isset( $query_args['status_is'] ) && is_array( $query_args['status_is'] ) && count( $query_args['status_is'] ) > 0 ) {
$allowed_statuses = array_map( array( $this, 'normalize_order_status' ), $query_args['status_is'] );
if ( $allowed_statuses ) {
$subqueries[] = "{$wpdb->prefix}posts.post_status IN ( '" . implode( "','", $allowed_statuses ) . "' )";
$subqueries[] = "{$wpdb->prefix}wc_order_stats.status IN ( '" . implode( "','", $allowed_statuses ) . "' )";
}
}
if ( isset( $query_args['status_is_not'] ) && is_array( $query_args['status_is_not'] ) && count( $query_args['status_is_not'] ) > 0 ) {
$forbidden_statuses = array_map( array( $this, 'normalize_order_status' ), $query_args['status_is_not'] );
if ( $forbidden_statuses ) {
$subqueries[] = "{$wpdb->prefix}posts.post_status NOT IN ( '" . implode( "','", $forbidden_statuses ) . "' )";
$subqueries[] = "{$wpdb->prefix}wc_order_stats.status NOT IN ( '" . implode( "','", $forbidden_statuses ) . "' )";
}
}

View File

@ -170,10 +170,8 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
)";
}
// TODO: move order status to wc_order_stats so that JOIN is not necessary.
$order_status_filter = $this->get_status_subquery( $query_args, $operator );
if ( $order_status_filter ) {
$from_clause .= " JOIN {$wpdb->prefix}posts ON {$orders_stats_table}.order_id = {$wpdb->prefix}posts.ID";
$where_filters[] = $order_status_filter;
}
@ -460,6 +458,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
'shipping_total' => $order->get_shipping_total(),
'net_total' => (float) $order->get_total() - (float) $order->get_total_tax() - (float) $order->get_shipping_total(),
'returning_customer' => self::is_returning_customer( $order ),
'status' => self::normalize_order_status( $order->get_status() ),
);
// Update or add the information to the DB.
@ -476,6 +475,8 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
'%f',
'%f',
'%f',
'%d',
'%s',
)
);
}