API tweaks from feedback
This commit is contained in:
parent
6fffb10e47
commit
bbfea35cf0
|
@ -152,33 +152,33 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
}
|
||||
|
||||
return array (
|
||||
'id' => $object->get_id(),
|
||||
'code' => $data['code'],
|
||||
'amount' => $data['amount'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'discount_type' => $data['discount_type'],
|
||||
'description' => $data['description'],
|
||||
'date_expires' => $data['date_expires'],
|
||||
'date_expires_gmt' => $data['date_expires_gmt'],
|
||||
'usage_count' => $data['usage_count'],
|
||||
'individual_use' => $data['individual_use'],
|
||||
'product_ids' => $data['product_ids'],
|
||||
'excluded_product_ids' => $data['excluded_product_ids'],
|
||||
'usage_limit' => $data['usage_limit'],
|
||||
'usage_limit_per_user' => $data['usage_limit_per_user'],
|
||||
'limit_usage_to_x_items' => $data['limit_usage_to_x_items'],
|
||||
'free_shipping' => $data['free_shipping'],
|
||||
'product_categories' => $data['product_categories'],
|
||||
'excluded_product_categories' => $data['excluded_product_categories'],
|
||||
'exclude_sale_items' => $data['exclude_sale_items'],
|
||||
'minimum_amount' => $data['minimum_amount'],
|
||||
'maximum_amount' => $data['maximum_amount'],
|
||||
'email_restrictions' => $data['email_restrictions'],
|
||||
'used_by' => $data['used_by'],
|
||||
'meta_data' => $data['meta_data'],
|
||||
'id' => $object->get_id(),
|
||||
'code' => $data['code'],
|
||||
'amount' => $data['amount'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'discount_type' => $data['discount_type'],
|
||||
'description' => $data['description'],
|
||||
'date_expires' => $data['date_expires'],
|
||||
'date_expires_gmt' => $data['date_expires_gmt'],
|
||||
'usage_count' => $data['usage_count'],
|
||||
'individual_use' => $data['individual_use'],
|
||||
'product_ids' => $data['product_ids'],
|
||||
'excluded_product_ids' => $data['excluded_product_ids'],
|
||||
'usage_limit' => $data['usage_limit'],
|
||||
'usage_limit_per_user' => $data['usage_limit_per_user'],
|
||||
'limit_usage_to_x_items' => $data['limit_usage_to_x_items'],
|
||||
'free_shipping' => $data['free_shipping'],
|
||||
'product_categories' => $data['product_categories'],
|
||||
'excluded_product_categories' => $data['excluded_product_categories'],
|
||||
'exclude_sale_items' => $data['exclude_sale_items'],
|
||||
'minimum_amount' => $data['minimum_amount'],
|
||||
'maximum_amount' => $data['maximum_amount'],
|
||||
'email_restrictions' => $data['email_restrictions'],
|
||||
'used_by' => $data['used_by'],
|
||||
'meta_data' => $data['meta_data'],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -373,12 +373,12 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_expires' => array(
|
||||
'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ),
|
||||
'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_expires_gmt' => array(
|
||||
'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ),
|
||||
'description' => __( "The date the coupon expires, as GMT.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
|
|
|
@ -283,7 +283,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
update_post_meta( $id, 'limit_usage_to_x_items', absint( $coupon_data['limit_usage_to_x_items'] ) );
|
||||
update_post_meta( $id, 'usage_count', absint( $coupon_data['usage_count'] ) );
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'expiry_date_utc', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'free_shipping', ( true === $coupon_data['enable_free_shipping'] ) ? 'yes' : 'no' );
|
||||
update_post_meta( $id, 'product_categories', array_filter( array_map( 'intval', $coupon_data['product_category_ids'] ) ) );
|
||||
update_post_meta( $id, 'exclude_product_categories', array_filter( array_map( 'intval', $coupon_data['exclude_product_category_ids'] ) ) );
|
||||
|
@ -394,7 +394,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
|
||||
if ( isset( $data['expiry_date'] ) ) {
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'expiry_date_utc', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ), true ) );
|
||||
}
|
||||
|
||||
if ( isset( $data['enable_free_shipping'] ) ) {
|
||||
|
|
|
@ -283,7 +283,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
update_post_meta( $id, 'limit_usage_to_x_items', absint( $coupon_data['limit_usage_to_x_items'] ) );
|
||||
update_post_meta( $id, 'usage_count', absint( $coupon_data['usage_count'] ) );
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'expiry_date_utc', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'free_shipping', ( true === $coupon_data['enable_free_shipping'] ) ? 'yes' : 'no' );
|
||||
update_post_meta( $id, 'product_categories', array_filter( array_map( 'intval', $coupon_data['product_category_ids'] ) ) );
|
||||
update_post_meta( $id, 'exclude_product_categories', array_filter( array_map( 'intval', $coupon_data['exclude_product_category_ids'] ) ) );
|
||||
|
@ -394,7 +394,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
|
||||
if ( isset( $data['expiry_date'] ) ) {
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'expiry_date_utc', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ), true ) );
|
||||
}
|
||||
|
||||
if ( isset( $data['enable_free_shipping'] ) ) {
|
||||
|
|
|
@ -150,9 +150,10 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
|
|||
$coupon = new WC_Coupon( (int) $post->ID );
|
||||
$_data = $coupon->get_data();
|
||||
|
||||
$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
|
||||
$format_date = array( 'date_created', 'date_modified', 'date_expires' );
|
||||
$format_null = array( 'usage_limit', 'usage_limit_per_user' );
|
||||
$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
|
||||
$format_date = array( 'date_created', 'date_modified' );
|
||||
$format_date_utc = array( 'date_expires' );
|
||||
$format_null = array( 'usage_limit', 'usage_limit_per_user' );
|
||||
|
||||
// Format decimal values.
|
||||
foreach ( $format_decimal as $key ) {
|
||||
|
@ -161,6 +162,9 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
|
|||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ], false ) : null;
|
||||
}
|
||||
foreach( $format_date_utc as $key ) {
|
||||
$_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null;
|
||||
}
|
||||
|
||||
|
@ -419,13 +423,13 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the coupon was created, as GMT.", 'woocommerce' ),
|
||||
'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the coupon was last modified, as GMT.", 'woocommerce' ),
|
||||
'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
@ -449,7 +453,7 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
|
|||
),
|
||||
'expiry_date' => array(
|
||||
'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'usage_count' => array(
|
||||
|
|
Loading…
Reference in New Issue