Made data match schema

This commit is contained in:
Mike Jolley 2016-08-26 15:20:44 +01:00
parent 210763e536
commit ed01282340
10 changed files with 156 additions and 121 deletions

View File

@ -75,7 +75,7 @@ class WC_Meta_Box_Coupon_Data {
woocommerce_wp_checkbox( array( 'id' => 'free_shipping', 'label' => __( 'Allow free shipping', 'woocommerce' ), 'description' => sprintf( __( 'Check this box if the coupon grants free shipping. A <a href="%s">free shipping method</a> must be enabled in your shipping zone and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce' ), 'https://docs.woocommerce.com/document/free-shipping/' ) ) );
// Expiry date
woocommerce_wp_text_input( array( 'id' => 'expiry_date', 'value' => date( 'Y-m-d', $coupon->get_expiry_date() ), 'label' => __( 'Coupon expiry date', 'woocommerce' ), 'placeholder' => _x( 'YYYY-MM-DD', 'placeholder', 'woocommerce' ), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array( 'pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ) ) );
woocommerce_wp_text_input( array( 'id' => 'expiry_date', 'value' => date( 'Y-m-d', $coupon->get_date_expires() ), 'label' => __( 'Coupon expiry date', 'woocommerce' ), 'placeholder' => _x( 'YYYY-MM-DD', 'placeholder', 'woocommerce' ), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array( 'pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ) ) );
do_action( 'woocommerce_coupon_options' );
@ -276,7 +276,7 @@ class WC_Meta_Box_Coupon_Data {
'code' => $post->post_title,
'discount_type' => wc_clean( $_POST['discount_type'] ),
'amount' => wc_format_decimal( $_POST['coupon_amount'] ),
'expiry_date' => wc_clean( $_POST['expiry_date'] ),
'date_expires' => wc_clean( $_POST['expiry_date'] ),
'individual_use' => isset( $_POST['individual_use'] ),
'product_ids' => array_filter( array_map( 'intval', explode( ',', $_POST['product_ids'] ) ) ),
'excluded_product_ids' => array_filter( array_map( 'intval', explode( ',', $_POST['exclude_product_ids'] ) ) ),

View File

@ -126,7 +126,6 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
if ( ! empty( $request['code'] ) ) {
$id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish'", $request['code'] ) );
$args['post__in'] = array( $id );
}
@ -141,44 +140,26 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
* @return WP_REST_Response $data
*/
public function prepare_item_for_response( $post, $request ) {
// Get the coupon code.
$code = wc_get_coupon_code_by_id( $post->ID );
$code = wc_get_coupon_code_by_id( $post->ID );
$coupon = new WC_Coupon( $code );
$data = $coupon->get_data();
$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
$format_date = array( 'date_created', 'date_modified', 'date_expires' );
$coupon = new WC_Coupon( $code );
// Format decimal values.
foreach ( $format_decimal as $key ) {
$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
}
$data = array(
'id' => $coupon->get_id(),
'code' => $coupon->get_code(),
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt ),
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
'discount_type' => $coupon->get_discount_type(),
'description' => $coupon->get_description(),
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
'expiry_date' => $coupon->get_expiry_date() ? wc_rest_prepare_date_response( $coupon->get_expiry_date() ) : null,
'usage_count' => (int) $coupon->get_usage_count(),
'individual_use' => $coupon->get_individual_use(),
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),
'exclude_product_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_ids() ),
'usage_limit' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : null,
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
'free_shipping' => $coupon->get_free_shipping(),
'product_categories' => array_map( 'absint', (array) $coupon->get_product_categories() ),
'excluded_product_categories' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),
'exclude_sale_items' => $coupon->get_exclude_sale_items(),
'minimum_amount' => wc_format_decimal( $coupon->get_minimum_amount(), 2 ),
'maximum_amount' => wc_format_decimal( $coupon->get_maximum_amount(), 2 ),
'email_restrictions' => $coupon->get_email_restrictions(),
'used_by' => $coupon->get_used_by(),
);
// 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;
}
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
// Wrap the data in a response object.
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
$response = rest_ensure_response( $data );
$response->add_links( $this->prepare_links( $post ) );
/**
@ -305,33 +286,38 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
* @return WP_Error|WP_REST_Response
*/
public function update_item( $request ) {
$post_id = (int) $request['id'];
try {
$post_id = (int) $request['id'];
if ( empty( $post_id ) || $this->post_type !== get_post_type( $post_id ) ) {
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
if ( empty( $post_id ) || $this->post_type !== get_post_type( $post_id ) ) {
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
}
$coupon_id = $this->save_coupon( $request );
if ( is_wp_error( $coupon_id ) ) {
return $coupon_id;
}
$post = get_post( $coupon_id );
$this->update_additional_fields_for_object( $post, $request );
$this->update_post_meta_fields( $post, $request );
/**
* Fires after a single item is created or updated via the REST API.
*
* @param object $post Inserted object (not a WP_Post object).
* @param WP_REST_Request $request Request object.
* @param boolean $creating True when creating item, false when updating.
*/
do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false );
$request->set_param( 'context', 'edit' );
$response = $this->prepare_item_for_response( $post, $request );
return rest_ensure_response( $response );
} catch ( Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
$coupon_id = $this->save_coupon( $request );
if ( is_wp_error( $coupon_id ) ) {
return $coupon_id;
}
$post = get_post( $coupon_id );
$this->update_additional_fields_for_object( $post, $request );
$this->update_post_meta_fields( $post, $request );
/**
* Fires after a single item is created or updated via the REST API.
*
* @param object $post Inserted object (not a WP_Post object).
* @param WP_REST_Request $request Request object.
* @param boolean $creating True when creating item, false when updating.
*/
do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false );
$request->set_param( 'context', 'edit' );
$response = $this->prepare_item_for_response( $post, $request );
return rest_ensure_response( $response );
}
/**
@ -402,7 +388,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
$coupon->set_usage_limit_per_user( $data['usage_limit_per_user'] );
$coupon->set_limit_usage_to_x_items( $data['limit_usage_to_x_items'] );
$coupon->set_usage_count( $data['usage_count'] );
$coupon->set_expiry_date( $data['expiry_date'] );
$coupon->set_date_expires(( $data['expiry_date'] );
$coupon->set_free_shipping( $data['free_shipping'] );
$coupon->set_product_categories( $data['product_categories'] );
$coupon->set_excluded_product_categories( $data['excluded_product_categories'] );
@ -424,7 +410,6 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
* @return bool|WP_Error
*/
protected function update_post_meta_fields( $post, $request ) {
$coupon = new WC_Coupon( $post->post_title );
if ( isset( $request['amount'] ) ) {
@ -460,7 +445,11 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
}
if ( isset( $request['expiry_date'] ) ) {
$coupon->set_expiry_date( $request['expiry_date'] );
$coupon->set_date_expires(( $request['expiry_date'] );
}
if ( isset( $request['date_expires'] ) ) {
$coupon->set_date_expires(( $request['date_expires'] );
}
if ( isset( $request['free_shipping'] ) ) {
@ -548,7 +537,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'expiry_date' => array(
'date_expires' => array(
'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),

View File

@ -125,7 +125,7 @@ class WC_API_Coupons extends WC_API_Resource {
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
'usage_count' => (int) $coupon->get_usage_count(),
'expiry_date' => $this->server->format_datetime( $coupon->get_expiry_date() ),
'expiry_date' => $this->server->format_datetime( $coupon->get_date_expires() ),
'enable_free_shipping' => $coupon->get_free_shipping(),
'product_category_ids' => array_map( 'absint', (array) $coupon->get_product_categories() ),
'exclude_product_category_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),

View File

@ -134,7 +134,7 @@ class WC_API_Coupons extends WC_API_Resource {
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
'usage_count' => (int) $coupon->get_usage_count(),
'expiry_date' => $coupon->get_expiry_date() ? $this->server->format_datetime( $coupon->get_expiry_date() ) : null,
'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime( $coupon->get_date_expires() ) : null,
'enable_free_shipping' => $coupon->get_free_shipping(),
'product_category_ids' => array_map( 'absint', (array) $coupon->get_product_categories() ),
'exclude_product_category_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),

View File

@ -134,7 +134,7 @@ class WC_API_Coupons extends WC_API_Resource {
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
'usage_count' => (int) $coupon->get_usage_count(),
'expiry_date' => $coupon->get_expiry_date() ? $this->server->format_datetime( $coupon->get_expiry_date() ) : null,
'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime( $coupon->get_date_expires() ) : null,
'enable_free_shipping' => $coupon->get_free_shipping(),
'product_category_ids' => array_map( 'absint', (array) $coupon->get_product_categories() ),
'exclude_product_category_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),

View File

@ -24,27 +24,29 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @var array
*/
protected $_data = array(
'id' => 0,
'code' => '',
'description' => '',
'discount_type' => 'fixed_cart',
'amount' => 0,
'expiry_date' => '',
'usage_count' => 0,
'used_by' => '',
'individual_use' => false,
'product_ids' => array(),
'exclude_product_ids' => array(),
'usage_limit' => 0,
'usage_limit_per_user' => 0,
'limit_usage_to_x_items' => 0,
'free_shipping' => false,
'product_categories' => array(),
'exclude_product_categories' => array(),
'exclude_sale_items' => false,
'minimum_amount' => '',
'maximum_amount' => '',
'customer_email' => array(),
'id' => 0,
'code' => '',
'description' => '',
'discount_type' => 'fixed_cart',
'amount' => 0,
'date_expires' => '',
'date_created' => '',
'date_modified' => '',
'usage_count' => 0,
'used_by' => '',
'individual_use' => false,
'product_ids' => array(),
'excluded_product_ids' => array(),
'usage_limit' => 0,
'usage_limit_per_user' => 0,
'limit_usage_to_x_items' => 0,
'free_shipping' => false,
'product_categories' => array(),
'excluded_product_categories' => array(),
'exclude_sale_items' => false,
'minimum_amount' => '',
'maximum_amount' => '',
'email_restrictions' => array(),
);
// Coupon message codes
@ -172,10 +174,28 @@ class WC_Coupon extends WC_Legacy_Coupon {
/**
* Get coupon expiration date.
* @since 2.7.0
* @return string
* @return int
*/
public function get_expiry_date() {
return $this->_data['expiry_date'] && ! is_numeric( $this->_data['expiry_date'] ) ? strtotime( $this->_data['expiry_date'] ) : $this->_data['expiry_date'];
public function get_date_expires() {
return $this->_data['date_expires'];
}
/**
* Get date_created
* @since 2.7.0
* @return int
*/
public function get_date_created() {
return $this->_data['date_created'];
}
/**
* Get date_modified
* @since 2.7.0
* @return int
*/
public function get_date_modified() {
return $this->_data['date_modified'];
}
/**
@ -211,7 +231,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @return array
*/
public function get_excluded_product_ids() {
return $this->_data['exclude_product_ids'];
return $this->_data['excluded_product_ids'];
}
/**
@ -265,7 +285,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @return array
*/
public function get_excluded_product_categories() {
return $this->_data['exclude_product_categories'];
return $this->_data['excluded_product_categories'];
}
/**
@ -300,7 +320,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @return array
*/
public function get_email_restrictions() {
return $this->_data['customer_email'];
return $this->_data['email_restrictions'];
}
/**
@ -459,15 +479,31 @@ class WC_Coupon extends WC_Legacy_Coupon {
/**
* Set expiration date.
* @since 2.7.0
* @param string $date
* @param string $timestamp Timestamp
* @throws WC_Data_Exception
*/
public function set_expiry_date( $date ) {
if ( ! is_numeric( $date ) ) {
$this->_data['expiry_date'] = strtotime( $date );
} else {
$this->_data['expiry_date'] = $date;
}
public function set_date_expires( $timestamp ) {
$this->_data['date_expires'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
}
/**
* Set date_created
* @since 2.7.0
* @param string $timestamp Timestamp
* @throws WC_Data_Exception
*/
public function set_date_created( $timestamp ) {
$this->_data['date_created'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
}
/**
* Set date_modified
* @since 2.7.0
* @param string $timestamp
* @throws WC_Data_Exception
*/
public function set_date_modified( $timestamp ) {
$this->_data['date_modified'] = is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp );
}
/**
@ -507,7 +543,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @throws WC_Data_Exception
*/
public function set_excluded_product_ids( $excluded_product_ids ) {
$this->_data['exclude_product_ids'] = (array) $excluded_product_ids;
$this->_data['excluded_product_ids'] = (array) $excluded_product_ids;
}
/**
@ -567,7 +603,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @throws WC_Data_Exception
*/
public function set_excluded_product_categories( $excluded_product_categories ) {
$this->_data['exclude_product_categories'] = (array) $excluded_product_categories;
$this->_data['excluded_product_categories'] = (array) $excluded_product_categories;
}
/**
@ -613,7 +649,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
$this->error( 'coupon_invalid_email_address', __( 'Invalid email address restriction', 'woocommerce' ) );
}
}
$this->_data['customer_email'] = $emails;
$this->_data['email_restrictions'] = $emails;
}
/**
@ -660,9 +696,11 @@ class WC_Coupon extends WC_Legacy_Coupon {
'id' => $coupon_id,
'code' => $post_object->post_title,
'description' => $post_object->post_excerpt,
'date_created' => $post_object->post_date,
'date_modified' => $post_object->post_modified,
'date_expires' => get_post_meta( $coupon_id, 'expiry_date', true ),
'discount_type' => get_post_meta( $coupon_id, 'discount_type', true ),
'amount' => get_post_meta( $coupon_id, 'coupon_amount', true ),
'expiry_date' => get_post_meta( $coupon_id, 'expiry_date', true ),
'usage_count' => get_post_meta( $coupon_id, 'usage_count', true ),
'individual_use' => 'yes' === get_post_meta( $coupon_id, 'individual_use', true ),
'product_ids' => array_filter( (array) explode( ',', get_post_meta( $coupon_id, 'product_ids', true ) ) ),
@ -689,13 +727,17 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @since 2.7.0
*/
public function create() {
$this->set_date_created( current_time( 'timestamp' ) );
$coupon_id = wp_insert_post( apply_filters( 'woocommerce_new_coupon_data', array(
'post_type' => 'shop_coupon',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_title' => $this->get_code(),
'post_content' => '',
'post_excerpt' => $this->get_description(),
'post_type' => 'shop_coupon',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_title' => $this->get_code(),
'post_content' => '',
'post_excerpt' => $this->get_description(),
'post_date' => date( 'Y-m-d H:i:s', $this->get_date_created() ),
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $this->get_date_created() ) ),
) ), true );
if ( $coupon_id ) {
@ -714,7 +756,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
$coupon_id = $this->get_id();
$post_data = array(
'ID' => $coupon_id,
'ID' => $coupon_id,
'post_title' => $this->get_code(),
'post_excerpt' => $this->get_description(),
);
@ -761,7 +803,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
update_post_meta( $coupon_id, 'usage_limit_per_user', $this->get_usage_limit_per_user() );
update_post_meta( $coupon_id, 'limit_usage_to_x_items', $this->get_limit_usage_to_x_items() );
update_post_meta( $coupon_id, 'usage_count', $this->get_usage_count() );
update_post_meta( $coupon_id, 'expiry_date', $this->get_expiry_date() );
update_post_meta( $coupon_id, 'expiry_date', $this->get_date_expires() );
update_post_meta( $coupon_id, 'free_shipping', ( true === $this->get_free_shipping() ) ? 'yes' : 'no' );
update_post_meta( $coupon_id, 'product_categories', array_filter( array_map( 'intval', $this->get_product_categories() ) ) );
update_post_meta( $coupon_id, 'exclude_product_categories', array_filter( array_map( 'intval', $this->get_excluded_product_categories() ) ) );
@ -796,6 +838,10 @@ class WC_Coupon extends WC_Legacy_Coupon {
}
}
// expiry_date to date_expires
$coupon[ 'date_expires' ] = isset( $coupon[ 'date_expires' ] ) ? $coupon[ 'date_expires' ] : '';
$coupon[ 'date_expires' ] = isset( $coupon[ 'expiry_date' ] ) ? $coupon[ 'expiry_date' ] : $coupon[ 'date_expires' ];
$this->set_code( $code );
$this->set_props( $coupon );
}
@ -913,7 +959,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @throws Exception
*/
private function validate_expiry_date() {
if ( $this->get_expiry_date() && current_time( 'timestamp' ) > $this->get_expiry_date() ) {
if ( $this->get_date_expires() && current_time( 'timestamp' ) > $this->get_date_expires() ) {
throw new Exception( $error_code = self::E_WC_COUPON_EXPIRED );
}
}

View File

@ -256,7 +256,7 @@ class WC_CLI_Coupon extends WC_CLI_Command {
'usage_limit_per_user' => ( ! empty( $coupon->get_usage_limit_per_user() ) ) ? $coupon->get_usage_limit_per_user() : null,
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
'usage_count' => (int) $coupon->get_usage_count(),
'expiry_date' => ( ! empty( $coupon->get_expiry_date() ) ) ? $this->format_datetime( $coupon->get_expiry_date() ) : null,
'expiry_date' => ( ! empty( $coupon->get_date_expires() ) ) ? $this->format_datetime( $coupon->get_date_expires() ) : null,
'enable_free_shipping' => $coupon->get_free_shipping(),
'product_category_ids' => implode( ', ', $coupon->get_product_categories() ),
'exclude_product_category_ids' => implode( ', ', $coupon->get_excluded_product_categories() ),
@ -591,7 +591,7 @@ class WC_CLI_Coupon extends WC_CLI_Command {
'usage_limit_per_user' => ( ! empty( $coupon->get_usage_limit_per_user() ) ) ? $coupon->get_usage_limit_per_user() : null,
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
'usage_count' => (int) $coupon->get_usage_count(),
'expiry_date' => ( ! empty( $coupon->get_expiry_date() ) ) ? $this->format_datetime( $coupon->get_expiry_date() ) : null,
'expiry_date' => ( ! empty( $coupon->get_date_expires() ) ) ? $this->format_datetime( $coupon->get_date_expires() ) : null,
'free_shipping' => $coupon->get_free_shipping(),
'product_category_ids' => implode( ', ', is_array( $coupon->get_product_categories() ) ? $coupon->get_product_categories() : array() ),
'exclude_product_category_ids' => implode( ', ', is_array( $coupon->get_excluded_product_categories() ) ? $coupon->get_excluded_product_categories() : array() ),

View File

@ -93,7 +93,7 @@ abstract class WC_Legacy_Coupon extends WC_Data {
$value = $this->get_usage_count();
break;
case 'expiry_date' :
$value = $this->get_expiry_date();
$value = $this->get_date_expires();
break;
case 'product_categories' :
$value = $this->get_product_categories();

View File

@ -38,7 +38,7 @@ class WC_Tests_API_Legacy_Coupons extends WC_API_Unit_Test_Case {
$this->assertEquals( (int) $coupon->get_usage_limit_per_user(), $response['usage_limit_per_user'] );
$this->assertEquals( (int) $coupon->get_limit_usage_to_x_items(), $response['limit_usage_to_x_items'] );
$this->assertEquals( (int) $coupon->get_usage_count(), $response['usage_count'] );
$this->assertEquals( $coupon->get_expiry_date(), $response['expiry_date'] );
$this->assertEquals( $coupon->get_date_expires(), $response['expiry_date'] );
$this->assertEquals( $coupon->get_free_shipping(), $response['enable_free_shipping'] );
$this->assertEquals( $coupon->get_product_categories(), $response['product_category_ids'] );
$this->assertEquals( $coupon->get_excluded_product_categories(), $response['exclude_product_category_ids'] );

View File

@ -144,7 +144,7 @@ class WC_Tests_CouponCRUD extends WC_Unit_Test_Case {
$this->assertEquals( $coupon->get_usage_limit_per_user(), $coupon->usage_limit_per_user );
$this->assertEquals( $coupon->get_limit_usage_to_x_items(), $coupon->limit_usage_to_x_items );
$this->assertEquals( $coupon->get_usage_count(), $coupon->usage_count );
$this->assertEquals( $coupon->get_expiry_date(), $coupon->expiry_date );
$this->assertEquals( $coupon->get_date_expires(), $coupon->expiry_date );
$this->assertEquals( $coupon->get_product_categories(), $coupon->product_categories );
$this->assertEquals( $coupon->get_excluded_product_categories(), $coupon->exclude_product_categories );
$this->assertEquals( $coupon->get_minimum_amount(), $coupon->minimum_amount );