Update API endpoints
This commit is contained in:
parent
53962f1143
commit
61484ed711
|
@ -522,9 +522,9 @@ class WC_Meta_Box_Order_Data {
|
|||
|
||||
// Update date.
|
||||
if ( empty( $_POST['order_date'] ) ) {
|
||||
$date = current_time( 'timestamp' );
|
||||
$date = current_time( 'timestamp', true );
|
||||
} else {
|
||||
$date = strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' );
|
||||
$date = gmdate( 'Y-m-d H:i:s', strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' ) );
|
||||
}
|
||||
|
||||
$props['date_created'] = $date;
|
||||
|
|
|
@ -160,7 +160,9 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$data[ $key ] = $data[ $key ] ? wc_rest_prepare_date_response( get_gmt_from_date( date( 'Y-m-d H:i:s', $data[ $key ] ) ) ) : false;
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format line items.
|
||||
|
@ -331,7 +333,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the order refund was created, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( "The date the order refund was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
|
|
@ -194,7 +194,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$this->request = $request;
|
||||
$data = array_merge( array( 'id' => $object->get_id() ), $object->get_data() );
|
||||
$data = $object->get_data();
|
||||
$format_decimal = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
|
||||
$format_date = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
|
||||
$format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' );
|
||||
|
@ -206,7 +206,9 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$data[ $key ] = $data[ $key ] ? wc_rest_prepare_date_response( $data[ $key ] ) : null;
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format the order status.
|
||||
|
@ -227,6 +229,9 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
ksort( $data );
|
||||
|
||||
$data = array_merge( array( 'id' => $object->get_id() ), $data );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
@ -776,12 +781,24 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the order was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( "The date the order was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'discount_total' => array(
|
||||
'description' => __( 'Total discount amount for the order.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
@ -993,11 +1010,25 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_completed_gmt' => array(
|
||||
'description' => __( "The date the order was completed, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_paid' => array(
|
||||
'description' => __( "The date the order has been paid, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_paid_gmt' => array(
|
||||
'description' => __( "The date the order has been paid, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'cart_hash' => array(
|
||||
'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
|
||||
|
|
|
@ -158,8 +158,8 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'customer_user_agent' => $order->get_customer_user_agent(),
|
||||
'created_via' => $order->get_created_via(),
|
||||
'customer_note' => $order->get_customer_note(),
|
||||
'date_completed' => wc_rest_prepare_date_response( is_null( $order->get_date_completed() ) ? null : $order->get_date_completed()->getOffsetTimestamp() ), // v1 API used local time.
|
||||
'date_paid' => wc_rest_prepare_date_response( is_null( $order->get_date_paid() ) ? null : $order->get_date_paid()->getOffsetTimestamp() ), // v1 API used local time.
|
||||
'date_completed' => wc_rest_prepare_date_response( $order->get_date_completed(), false ), // v1 API used local time.
|
||||
'date_paid' => wc_rest_prepare_date_response( $order->get_date_paid(), false ), // v1 API used local time.
|
||||
'cart_hash' => $order->get_cart_hash(),
|
||||
'line_items' => array(),
|
||||
'tax_lines' => array(),
|
||||
|
@ -953,13 +953,13 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( "The date the order was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( "The date the order was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
|
|
@ -89,8 +89,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
|||
$id = $order->get_id();
|
||||
$order->set_props( array(
|
||||
'parent_id' => $post_object->post_parent,
|
||||
'date_created' => $post_object->post_date_gmt,
|
||||
'date_modified' => $post_object->post_modified_gmt,
|
||||
'date_created' => strtotime( $post_object->post_date_gmt ),
|
||||
'date_modified' => strtotime( $post_object->post_modified_gmt ),
|
||||
'status' => $post_object->post_status,
|
||||
) );
|
||||
|
||||
|
|
|
@ -20,22 +20,26 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* Required WP 4.4 or later.
|
||||
* See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @param string|null|WC_DateTime $date
|
||||
* @since 2.6.0
|
||||
* @param string|null|WC_DateTime $date
|
||||
* @param bool Send false to get local/offset time.
|
||||
* @return string|null ISO8601/RFC3339 formatted datetime.
|
||||
*/
|
||||
function wc_rest_prepare_date_response( $date ) {
|
||||
function wc_rest_prepare_date_response( $date, $utc = true ) {
|
||||
if ( is_numeric( $date ) ) {
|
||||
$date = new WC_DateTime( "@$date" );
|
||||
$date = new WC_DateTime( "@$date", new DateTimeZone( 'UTC' ) );
|
||||
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
} elseif ( is_string( $date ) ) {
|
||||
$date = new WC_DateTime( $date );
|
||||
$date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) );
|
||||
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
}
|
||||
|
||||
if ( ! is_a( $date, 'WC_DateTime' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $date->format( DATE_ATOM );
|
||||
// Get timestamp before changing timezone to UTC.
|
||||
return gmdate( 'Y-m-d\TH:i:s', $utc ? $date->getTimestamp() : $date->getOffsetTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue