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

@ -170,8 +170,14 @@ class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Cont
'readonly' => true,
),
'date_created' => array(
'description' => __( 'Date the order was created.', 'woocommerce-admin' ),
'type' => 'string',
'description' => __( "Date the order was created, in the site's timezone.", 'woocommerce-admin' ),
'type' => 'date-time',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'date_created_gmt' => array(
'description' => __( 'Date the order was created, as GMT.', 'woocommerce-admin' ),
'type' => 'date-time',
'context' => array( 'view', 'edit' ),
'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

@ -28,6 +28,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
'order_id' => 'intval',
'parent_id' => 'intval',
'date_created' => 'strval',
'date_created_gmt' => 'strval',
'status' => 'strval',
'customer_id' => 'intval',
'net_total' => 'floatval',
@ -54,6 +55,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
'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",

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 );