1212
1313use GraphQL \Error \UserError ;
1414use GraphQL \Type \Definition \ResolveInfo ;
15- use GraphQLRelay \Relay ;
1615use WC_Order_Factory ;
1716use WPGraphQL \AppContext ;
1817use WPGraphQL \WooCommerce \Data \Mutation \Order_Mutation ;
1918use WPGraphQL \WooCommerce \Model \Order ;
19+ use WPGraphQL \Utils \Utils ;
2020
2121/**
2222 * Class Order_Update
@@ -49,15 +49,16 @@ public static function get_input_fields() {
4949 [
5050 'id ' => [
5151 'type ' => 'ID ' ,
52- 'description ' => __ ( 'Order global ID ' , 'wp-graphql-woocommerce ' ),
52+ 'description ' => __ ( 'Database ID or global ID of the order ' , 'wp-graphql-woocommerce ' ),
5353 ],
54- 'orderId ' => [
55- 'type ' => 'Int ' ,
56- 'description ' => __ ( 'Order WP ID ' , 'wp-graphql-woocommerce ' ),
54+ 'orderId ' => [
55+ 'type ' => 'Int ' ,
56+ 'description ' => __ ( 'Order WP ID ' , 'wp-graphql-woocommerce ' ),
57+ 'deprecationReason ' => __ ( 'Use "id" field instead. ' , 'wp-graphql-woocommerce ' ),
5758 ],
5859 'customerId ' => [
59- 'type ' => 'Int ' ,
60- 'description ' => __ ( 'Order customer ID ' , 'wp-graphql-woocommerce ' ),
60+ 'type ' => 'ID ' ,
61+ 'description ' => __ ( 'Database ID or global ID of the customer for the order ' , 'wp-graphql-woocommerce ' ),
6162 ],
6263 ]
6364 );
@@ -89,17 +90,13 @@ public static function mutate_and_get_payload() {
8990 // Retrieve order ID.
9091 $ order_id = null ;
9192 if ( ! empty ( $ input ['id ' ] ) ) {
92- $ id_components = Relay::fromGlobalId ( $ input ['id ' ] );
93- if ( empty ( $ id_components ['id ' ] ) || empty ( $ id_components ['type ' ] ) ) {
94- throw new UserError ( __ ( 'The "id" provided is invalid ' , 'wp-graphql-woocommerce ' ) );
95- }
96- $ order_id = absint ( $ id_components ['id ' ] );
93+ $ order_id = Utils::get_database_id_from_id ( $ input ['id ' ] );
9794 } elseif ( ! empty ( $ input ['orderId ' ] ) ) {
9895 $ order_id = absint ( $ input ['orderId ' ] );
9996 } else {
100- throw new UserError ( __ ( 'No order ID provided. ' , 'wp-graphql-woocommerce ' ) );
97+ throw new UserError ( __ ( 'Order ID provided is missing or invalid. Please check input and try again . ' , 'wp-graphql-woocommerce ' ) );
10198 }
102-
99+
103100 // Check if authorized to update this order.
104101 if ( ! Order_Mutation::authorized ( $ input , $ context , $ info , 'update ' , $ order_id ) ) {
105102 throw new UserError ( __ ( 'User does not have the capabilities necessary to update an order. ' , 'wp-graphql-woocommerce ' ) );
@@ -133,7 +130,7 @@ public static function mutate_and_get_payload() {
133130 \WC ()->payment_gateways ();
134131
135132 // Validate customer ID.
136- if ( ! empty ( $ input ['customerId ' ] ) && ! Order_Mutation::validate_customer ( $ input ) ) {
133+ if ( ! empty ( $ input ['customerId ' ] ) && ! Order_Mutation::validate_customer ( $ input[ ' customerId ' ] ) ) {
137134 throw new UserError ( __ ( 'New customer ID is invalid. ' , 'wp-graphql-woocommerce ' ) );
138135 }
139136
@@ -147,7 +144,7 @@ public static function mutate_and_get_payload() {
147144 }
148145
149146 // Actions for after the order is saved.
150- if ( true === $ input ['isPaid ' ] ) {
147+ if ( isset ( $ input [ ' isPaid ' ] ) && true === $ input ['isPaid ' ] ) {
151148 $ order ->payment_complete (
152149 ! empty ( $ input ['transactionId ' ] )
153150 ? $ input ['transactionId ' ]
0 commit comments