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

wp-graphql / wp-graphql-woocommerce / 7304543431

22 Dec 2023 11:06PM UTC coverage: 84.742% (+0.01%) from 84.731%
7304543431

push

github

web-flow
fix: Bug fixed in Product_Connection_Resolver::add_tax_query (#820)

* fix: Bug fixed in Product_Connection_Resolver::add_tax_query

* fix: some product connection resolver hooks restored

14 of 14 new or added lines in 1 file covered. (100.0%)

71 existing lines in 4 files now uncovered.

11047 of 13036 relevant lines covered (84.74%)

58.86 hits per line

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

92.73
/includes/mutation/class-update-session.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 - Update_Session
19
 */
20
class Update_Session {
21
        /**
22
         * Registers mutation
23
         *
24
         * @return void
25
         */
26
        public static function register_mutation() {
27
                register_graphql_mutation(
114✔
28
                        'updateSession',
114✔
29
                        [
114✔
30
                                'inputFields'         => self::get_input_fields(),
114✔
31
                                'outputFields'        => self::get_output_fields(),
114✔
32
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
114✔
33
                        ]
114✔
34
                );
114✔
35
        }
36

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

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

77
                                        return $session;
1✔
78
                                },
114✔
79
                        ],
114✔
80
                        'customer' => [
114✔
81
                                'type'    => 'Customer',
114✔
82
                                'resolve' => static function () {
114✔
83
                                        return new Customer( 'session' );
1✔
84
                                },
114✔
85
                        ],
114✔
86
                ];
114✔
87
        }
88

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

98
                        // Guard against missing input.
99
                        if ( empty( $input['sessionData'] ) ) {
1✔
UNCOV
100
                                throw new UserError( __( 'No session data provided', 'wp-graphql-woocommerce' ) );
×
101
                        }
102
                        $session_data_input = $input['sessionData'];
1✔
103

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

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

116
                        if ( is_a( $session, '\WC_Session_Handler' ) ) {
1✔
117
                                $session->save_data();
1✔
118
                        }
119

120
                        do_action( 'woographql_update_session', true );
1✔
121

122
                        // Process errors or return successful.
123
                        $notices = $session->get( 'wc_notices' );
1✔
124
                        if ( ! empty( $notices['error'] ) ) {
1✔
UNCOV
125
                                $error_messages = implode( ' ', array_column( $notices['error'], 'notice' ) );
×
UNCOV
126
                                \wc_clear_notices();
×
127
                                throw new UserError( $error_messages );
×
128
                        } else {
129
                                return [ 'status' => 'SUCCESS' ];
1✔
130
                        }
131
                };
114✔
132
        }
133
}
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