Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddToCart in parallel doesn't work #844

Closed
Shazamepool opened this issue Apr 12, 2024 · 2 comments · Fixed by #852
Closed

AddToCart in parallel doesn't work #844

Shazamepool opened this issue Apr 12, 2024 · 2 comments · Fixed by #852
Labels
bug Something isn't working
Milestone

Comments

@Shazamepool
Copy link

Describe the bug
When I make several addToCart in parallel, only the products added by the last addToCart launched will appear in my cart.

To Reproduce
0 - It's easier to reproduce on a slow site
1 - Quickly launch 3 addToCart for different products in parallel with the same woocommerce-session header.
2 - Note in their returns that the cart contains only the product just added.
3 - Send a getCart with the same header and see that only the last product added appears in the cart.

 mutation addToCart($productId: Int!, $quantity: Int) {
    addToCart(input: {productId: $productId, quantity: $quantity}) {
        cart {
            contents {
                nodes {
                    quantity
                }
            }
           total
       }
   }
}

Expected behavior
All added products should appear in the cart

Plugin Versions

  • WooGraphQL Version: 0.19.0
  • WPGraphQL Version: 1.23.0
  • WordPress Version: 6.5.2
  • WooCommerce Version: 7.9.0

Additional context
The bug was caused by changing the graphql_process_http_request_response action to graphql_mutation_response when upgrading to version 0.19.0 of the plugin.

@Shazamepool
Copy link
Author

I solved this problem by modifying the code of the pop_transaction_id function:

  • I added a negation to the "str_starts_with" condition. This will execute the rest of the code if the mutation seems to be correctly formed.

  • In the case where the transaction is not at the top of the transactionQueue I've added these 2 lines of code:

        $this->save_transaction_queue( null );
        $this->transaction_id = null;

To avoid keeping an invalid transactionQueue.

@kidunot89 kidunot89 added the bug Something isn't working label Apr 30, 2024
@kidunot89 kidunot89 added this to the v0.19.1 milestone Apr 30, 2024
@kidunot89
Copy link
Member

@Shazamepool Damn good catch, bro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants