• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 27452430870

13 Jun 2026 01:26AM UTC coverage: 91.8%. Remained the same
27452430870

Pull #1019

github

web-flow
Merge f03617ca3 into 2ce9424e1
Pull Request #1019: fix: address WordPress.org plugin review (rename + prefixing + headers)

1330 of 1587 new or added lines in 201 files covered. (83.81%)

1 existing line in 1 file now uncovered.

18528 of 20183 relevant lines covered (91.8%)

152.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.25
/includes/mutation/class-session-update.php
1
<?php
2
/**
3
 * Mutation - updateSession
4
 *
5
 * Registers mutation for updating session meta data.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 0.12.5
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use GraphQL\Error\UserError;
14
use WPGraphQL\WooCommerce\Data\Mutation\Cart_Mutation;
15
use WPGraphQL\WooCommerce\Model\Customer;
16

17
/**
18
 * Class - Session_Update
19
 */
20
class Session_Update {
21
        /**
22
         * Registers mutation
23
         *
24
         * @return void
25
         */
26
        public static function register_mutation() {
27
                register_graphql_mutation(
298✔
28
                        'updateSession',
298✔
29
                        [
298✔
30
                                'inputFields'         => self::get_input_fields(),
298✔
31
                                'outputFields'        => self::get_output_fields(),
298✔
32
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
298✔
33
                        ]
298✔
34
                );
298✔
35
        }
36

37
        /**
38
         * Defines the mutation input field configuration
39
         *
40
         * @return array
41
         */
42
        public static function get_input_fields() {
43
                return [
298✔
44
                        'sessionData' => [
298✔
45
                                'type'        => [ 'list_of' => 'MetaDataInput' ],
298✔
46
                                'description' => static function () {
298✔
47
                                        return __( 'Data to be persisted in the session.', 'graphql-for-ecommerce' );
2✔
48
                                },
298✔
49
                        ],
298✔
50
                ];
298✔
51
        }
52

53
        /**
54
         * Defines the mutation output field configuration
55
         *
56
         * @return array
57
         */
58
        public static function get_output_fields() {
59
                return [
298✔
60
                        'session'  => [
298✔
61
                                'type'    => [ 'list_of' => 'MetaData' ],
298✔
62
                                'resolve' => static function () {
298✔
63
                                        /**
64
                                         * Session handler.
65
                                         *
66
                                         * @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session
67
                                         */
68
                                        $session      = \WC()->session;
2✔
69
                                        $session_data = $session->get_session_data();
2✔
70
                                        $session      = [];
2✔
71
                                        foreach ( $session_data as $key => $value ) {
2✔
72
                                                $meta        = new \stdClass();
2✔
73
                                                $meta->id    = null;
2✔
74
                                                $meta->key   = $key;
2✔
75
                                                $meta->value = maybe_unserialize( $value );
2✔
76
                                                $session[]   = $meta;
2✔
77
                                        }
78

79
                                        return $session;
2✔
80
                                },
298✔
81
                        ],
298✔
82
                        'customer' => [
298✔
83
                                'type'    => 'Customer',
298✔
84
                                'resolve' => static function () {
298✔
85
                                        return new Customer( 'session' );
3✔
86
                                },
298✔
87
                        ],
298✔
88
                ];
298✔
89
        }
90

91
        /**
92
         * Defines the mutation data modification closure.
93
         *
94
         * @return callable
95
         */
96
        public static function mutate_and_get_payload() {
97
                return static function ( $input ) {
298✔
98
                        Cart_Mutation::check_session_token();
4✔
99

100
                        // Guard against missing input.
101
                        if ( empty( $input['sessionData'] ) ) {
4✔
NEW
102
                                throw new UserError( __( 'No session data provided', 'graphql-for-ecommerce' ) );
×
103
                        }
104
                        $session_data_input = $input['sessionData'];
4✔
105

106
                        /**
107
                         * Session handler.
108
                         *
109
                         * @var \WPGraphQL\WooCommerce\Utils\QL_Session_Handler $session
110
                         */
111
                        $session = \WC()->session;
4✔
112

113
                        // Save session data input.
114
                        foreach ( $session_data_input as $meta ) {
4✔
115
                                $session->set( $meta['key'], $meta['value'] );
4✔
116
                        }
117

118
                        if ( is_a( $session, '\WC_Session_Handler' ) ) {
4✔
119
                                $session->save_data();
4✔
120
                        }
121

122
                        do_action( 'woographql_update_session', true );
4✔
123

124
                        // Process errors or return successful.
125
                        $notices = $session->get( 'wc_notices' );
4✔
126
                        if ( ! empty( $notices['error'] ) ) {
4✔
127
                                $error_messages = implode( ' ', array_column( $notices['error'], 'notice' ) );
1✔
128
                                \wc_clear_notices();
1✔
129
                                throw new UserError( $error_messages );
1✔
130
                        } else {
131
                                return [ 'status' => 'SUCCESS' ];
3✔
132
                        }
133
                };
298✔
134
        }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc