Add date_created_gmt property to orders endpoint (https://github.com/woocommerce/woocommerce-admin/pull/2086)

* Add date_created_gmt property to orders enpoint

* Make date_created properties of type date-time and improve descriptions
This commit is contained in:
Albert Juhé Lluveras 2019-06-12 11:21:56 +02:00 committed by GitHub
parent 95d1a1d245
commit 8bc2261c8a
5 changed files with 42 additions and 30 deletions

View File

@ -157,55 +157,61 @@ class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Cont
'title' => 'report_orders',
'type' => 'object',
'properties' => array(
'order_id' => array(
'order_id' => array(
'description' => __( 'Order ID.', 'woocommerce-admin' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'order_number' => array(
'order_number' => array(
'description' => __( 'Order Number.', 'woocommerce-admin' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'date_created' => array(
'description' => __( 'Date the order was created.', 'woocommerce-admin' ),
'type' => 'string',
'date_created' => array(
'description' => __( "Date the order was created, in the site's timezone.", 'woocommerce-admin' ),
'type' => 'date-time',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'status' => array(
'date_created_gmt' => array(
'description' => __( 'Date the order was created, as GMT.', 'woocommerce-admin' ),
'type' => 'date-time',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'status' => array(
'description' => __( 'Order status.', 'woocommerce-admin' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'customer_id' => array(
'customer_id' => array(
'description' => __( 'Customer ID.', 'woocommerce-admin' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'num_items_sold' => array(
'num_items_sold' => array(
'description' => __( 'Number of items sold.', 'woocommerce-admin' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'net_total' => array(
'net_total' => array(
'description' => __( 'Net total revenue.', 'woocommerce-admin' ),
'type' => 'float',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'customer_type' => array(
'customer_type' => array(
'description' => __( 'Returning or new customer.', 'woocommerce-admin' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'extended_info' => array(
'extended_info' => array(
'products' => array(
'type' => 'array',
'readonly' => true,

View File

@ -94,6 +94,7 @@ class WC_Admin_Install {
order_id bigint(20) unsigned NOT NULL,
parent_id bigint(20) unsigned DEFAULT 0 NOT NULL,
date_created datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
date_created_gmt datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
num_items_sold int(11) DEFAULT 0 NOT NULL,
gross_total double DEFAULT 0 NOT NULL,
tax_total double DEFAULT 0 NOT NULL,

View File

@ -25,15 +25,16 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
* @var array
*/
protected $column_types = array(
'order_id' => 'intval',
'parent_id' => 'intval',
'date_created' => 'strval',
'status' => 'strval',
'customer_id' => 'intval',
'net_total' => 'floatval',
'gross_total' => 'floatval',
'num_items_sold' => 'intval',
'customer_type' => 'strval',
'order_id' => 'intval',
'parent_id' => 'intval',
'date_created' => 'strval',
'date_created_gmt' => 'strval',
'status' => 'strval',
'customer_id' => 'intval',
'net_total' => 'floatval',
'gross_total' => 'floatval',
'num_items_sold' => 'intval',
'customer_type' => 'strval',
);
/**
@ -51,15 +52,16 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
$table_name = $wpdb->prefix . self::TABLE_NAME;
// Avoid ambigious columns in SQL query.
$this->report_columns = array(
'order_id' => "{$table_name}.order_id",
'parent_id' => "{$table_name}.parent_id",
'date_created' => "{$table_name}.date_created",
'status' => "REPLACE({$table_name}.status, 'wc-', '') as status",
'customer_id' => "{$table_name}.customer_id",
'net_total' => "{$table_name}.net_total",
'gross_total' => "{$table_name}.gross_total",
'num_items_sold' => "{$table_name}.num_items_sold",
'customer_type' => "(CASE WHEN {$table_name}.returning_customer = 1 THEN 'returning' WHEN {$table_name}.returning_customer = 0 THEN 'new' ELSE '' END) as customer_type",
'order_id' => "{$table_name}.order_id",
'parent_id' => "{$table_name}.parent_id",
'date_created' => "{$table_name}.date_created",
'date_created_gmt' => "{$table_name}.date_created_gmt",
'status' => "REPLACE({$table_name}.status, 'wc-', '') as status",
'customer_id' => "{$table_name}.customer_id",
'net_total' => "{$table_name}.net_total",
'gross_total' => "{$table_name}.gross_total",
'num_items_sold' => "{$table_name}.num_items_sold",
'customer_type' => "(CASE WHEN {$table_name}.returning_customer = 1 THEN 'returning' WHEN {$table_name}.returning_customer = 0 THEN 'new' ELSE '' END) as customer_type",
);
}

View File

@ -410,6 +410,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
'order_id' => $order->get_id(),
'parent_id' => $order->get_parent_id(),
'date_created' => $order->get_date_created()->date( 'Y-m-d H:i:s' ),
'date_created_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created()->getTimestamp() ),
'num_items_sold' => self::get_num_items_sold( $order ),
'gross_total' => $order->get_total(),
'tax_total' => $order->get_total_tax(),
@ -423,6 +424,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
'%d',
'%d',
'%s',
'%s',
'%d',
'%f',
'%f',

View File

@ -114,7 +114,8 @@ class WC_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertEquals( 9, count( $properties ) );
$this->assertEquals( 10, count( $properties ) );
$this->assertArrayHasKey( 'date_created_gmt', $properties );
$this->assertArrayHasKey( 'order_id', $properties );
$this->assertArrayHasKey( 'order_number', $properties );
$this->assertArrayHasKey( 'date_created', $properties );