Proposed fix for api coupon recalculating
This commit is contained in:
parent
70455b79a3
commit
1c8dd6acbb
|
@ -430,7 +430,6 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
case 'line_items' :
|
||||
case 'shipping_lines' :
|
||||
case 'fee_lines' :
|
||||
case 'coupon_lines' :
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $item ) {
|
||||
if ( is_array( $item ) ) {
|
||||
|
@ -443,6 +442,28 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case 'coupon_lines' :
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $item ) {
|
||||
if ( is_array( $item ) ) {
|
||||
if ( $this->item_is_null( $item ) ) {
|
||||
$item = $order->get_item( $item['id'] );
|
||||
if ( $item && method_exists( $item, 'get_code' ) ) {
|
||||
$order->remove_coupon( $item->get_code() );
|
||||
} else {
|
||||
$order->remove_item( $item['id'] );
|
||||
}
|
||||
} else {
|
||||
if ( ! empty( $item['code'] ) ) {
|
||||
$order->apply_coupon( $item['code'] );
|
||||
} else {
|
||||
$this->set_item( $order, $key, $item );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'meta_data' :
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $meta ) {
|
||||
|
|
|
@ -338,6 +338,9 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
|
|||
public function test_update_order_add_coupons() {
|
||||
wp_set_current_user( $this->user );
|
||||
$order = WC_Helper_Order::create_order();
|
||||
$coupon = WC_Helper_Coupon::create_coupon( 'fake-coupon' );
|
||||
$coupon->set_amount( 5 );
|
||||
$coupon->save();
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() );
|
||||
$request->set_body_params( array(
|
||||
|
|
Loading…
Reference in New Issue