Skip to content

Commit b0d8df0

Browse files
authored
Merge pull request #398 from kidunot89/bugfix/cart-mutation-transaction-queue
Cart transaction queue refactored
2 parents 48d5072 + effd712 commit b0d8df0

File tree

15 files changed

+699
-209
lines changed

15 files changed

+699
-209
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
],
2929
"require": {
3030
"php": ">=7.1.0",
31-
"firebase/php-jwt": "^5.0"
31+
"firebase/php-jwt": "^5.0",
32+
"webonyx/graphql-php": "^14.4.0"
3233
},
3334
"require-dev": {
3435
"composer/installers": "^1.9",

includes/class-jwt-auth-schema-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static function add_customer_to_login_payload() {
105105
'type' => 'String',
106106
'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ),
107107
'resolve' => function( $payload ) {
108-
return apply_filters( 'graphql_customer_session_token', null );
108+
return apply_filters( 'graphql_customer_session_token', \WC()->session->build_token() );
109109
},
110110
),
111111
)

includes/data/mutation/class-cart-mutation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,7 @@ public static function check_session_token() {
172172
if ( $token_invalid ) {
173173
throw new UserError( $token_invalid );
174174
}
175+
176+
\WC()->cart->get_cart_from_session();
175177
}
176178
}

includes/type/object/class-customer-type.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function register() {
113113
'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ),
114114
'resolve' => function( $source ) {
115115
if ( \get_current_user_id() === $source->ID ) {
116-
return apply_filters( 'graphql_customer_session_token', null );
116+
return apply_filters( 'graphql_customer_session_token', \WC()->session->build_token() );
117117
}
118118

119119
return null;
@@ -128,13 +128,13 @@ public static function register() {
128128
*/
129129
register_graphql_field(
130130
'User',
131-
'sessionToken',
131+
'wooSessionToken',
132132
array(
133133
'type' => 'String',
134134
'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ),
135135
'resolve' => function( $source ) {
136-
if ( \get_current_user_id() === $source->ID ) {
137-
return apply_filters( 'graphql_customer_session_token', null );
136+
if ( \get_current_user_id() === $source->userId ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
137+
return apply_filters( 'graphql_customer_session_token', \WC()->session->build_token() );
138138
}
139139

140140
return null;

0 commit comments

Comments
 (0)