@@ -60,7 +60,8 @@ public function __construct( &$session_handler ) {
6060 $ this ->session_handler = $ session_handler ;
6161
6262 add_action ( 'graphql_before_resolve_field ' , [ $ this , 'update_transaction_queue ' ], 10 , 4 );
63- add_action ( 'graphql_process_http_request_response ' , [ $ this , 'pop_transaction_id ' ], 20 );
63+ add_action ( 'graphql_mutation_response ' , [ $ this , 'pop_transaction_id ' ], 20 , 6 );
64+ add_action ( 'woographql_session_transaction_complete ' , [ $ this ->session_handler , 'save_if_dirty ' ], 10 );
6465 }
6566
6667 /**
@@ -202,16 +203,28 @@ public function get_transaction_queue() {
202203 /**
203204 * Pop transaction ID off the top of the queue, ending the transaction.
204205 *
206+ * @param array $payload The Payload returned from the mutation.
207+ * @param array $input The mutation input args, after being filtered by 'graphql_mutation_input'.
208+ * @param array $unfiltered_input The unfiltered input args of the mutation
209+ * @param \WPGraphQL\AppContext $context The AppContext object.
210+ * @param \GraphQL\Type\Definition\ResolveInfo $info The ResolveInfo object.
211+ * @param string $mutation The name of the mutation field.
212+ *
205213 * @throws \GraphQL\Error\UserError If transaction ID is not on the top of the queue.
206214 *
207215 * @return void
208216 */
209- public function pop_transaction_id () {
217+ public function pop_transaction_id ( $ payload , $ input , $ unfiltered_input , $ context , $ info , $ mutation ) {
210218 // Bail if transaction not started.
211219 if ( is_null ( $ this ->transaction_id ) ) {
212220 return ;
213221 }
214222
223+ // Bail if not the expected mutation.
224+ if ( str_starts_with ( $ this ->transaction_id , "wooSession_ {$ mutation }_ " ) ) {
225+ return ;
226+ }
227+
215228 // Get transaction queue.
216229 $ transaction_queue = get_transient ( "woo_session_transactions_queue_ {$ this ->session_handler ->get_customer_id ()}" );
217230
@@ -223,6 +236,16 @@ public function pop_transaction_id() {
223236 // Remove Transaction ID and update queue.
224237 array_shift ( $ transaction_queue );
225238 $ this ->save_transaction_queue ( $ transaction_queue );
239+
240+ /**
241+ * Mark transaction completion
242+ *
243+ * @param string|null $transition_id Removed transaction ID.
244+ * @param array $transaction_queue Transaction Queue.
245+ */
246+ do_action ( 'woographql_session_transaction_complete ' , $ this ->transaction_id , $ transaction_queue );
247+
248+ // Clear transaction ID.
226249 $ this ->transaction_id = null ;
227250 }
228251 }
0 commit comments