From 2ee563d4b0da3aac7db45e7cec4b9aba6727dbeb Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 5 Jul 2019 17:40:38 -0400 Subject: [PATCH] "forceDelete" input field added for choosing between deletion and recycling. --- .../data/mutation/class-order-mutation.php | 9 ++++----- includes/mutation/class-order-delete.php | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/includes/data/mutation/class-order-mutation.php b/includes/data/mutation/class-order-mutation.php index c7a22759..78b48251 100644 --- a/includes/data/mutation/class-order-mutation.php +++ b/includes/data/mutation/class-order-mutation.php @@ -337,16 +337,15 @@ class Order_Mutation { /** * Purge object when creating. * - * @param WC_Order|Order $order Object data. - * @param AppContext $context AppContext instance. - * @param ResolveInfo $info ResolveInfo instance. + * @param WC_Order|Order $order Object data. + * @param boolean $force_delete Delete or put in trash. * * @return bool * @throws UserError Failed to delete order. */ - public static function purge( $order, $context, $info ) { + public static function purge( $order, $force_delete = true ) { if ( is_callable( array( $order, 'delete' ) ) ) { - return $order->delete( true ); + return $order->delete( $force_delete ); } return false; diff --git a/includes/mutation/class-order-delete.php b/includes/mutation/class-order-delete.php index 2a597267..787c3a4c 100644 --- a/includes/mutation/class-order-delete.php +++ b/includes/mutation/class-order-delete.php @@ -43,14 +43,18 @@ class Order_Delete { public static function get_input_fields() { $input_fields = array_merge( array( - 'id' => array( + 'id' => array( 'type' => 'ID', 'description' => __( 'Order global ID', 'wp-graphql-woocommerce' ), ), - 'orderId' => array( + 'orderId' => array( 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), ), + 'forceDelete' => array( + 'type' => 'Boolean', + 'description' => __( 'Delete or simply place in trash.', 'wp-graphql-woocommerce' ), + ), ) ); @@ -100,6 +104,11 @@ class Order_Delete { throw new UserError( __( 'No order ID provided.', 'wp-graphql-woocommerce' ) ); } + $force_delete = false; + if ( ! empty( $input['forceDelete'] ) ) { + $force_delete = $input['forceDelete']; + } + // Get Order model instance for output. $order = new Order( $order_id ); @@ -124,11 +133,7 @@ class Order_Delete { do_action( 'woocommerce_graphql_before_order_delete', $order, $context, $info ); // Delete order. - $success = Order_Mutation::purge( - \WC_Order_Factory::get_order( $order->ID ), - $context, - $info - ); + $success = Order_Mutation::purge( \WC_Order_Factory::get_order( $order->ID ), $force_delete ); if ( ! $success ) { throw new UserError(