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

Cart token is not refreshed even when invalid #2592

Closed
pkarw opened this issue Mar 14, 2019 · 8 comments
Closed

Cart token is not refreshed even when invalid #2592

pkarw opened this issue Mar 14, 2019 · 8 comments
Labels
5: Complex bug Bug reports P2: Important Priority mark - still high ;)
Milestone

Comments

@pkarw
Copy link
Collaborator

pkarw commented Mar 14, 2019

Current behavior

Screenshot 2019-03-14 09 17 10

There are some certain situation where the current shopping cart (stored in the localStorage shop/carts/current-cart-token) is no longer valid. For example, the quote has been closed server side.

In this case the shipping-methods and payment-methods, totals all subsequent calls return an issue like {"code":500,"result":"No such entity with cartId = null"}

In this situation the solution is to clear the local storage - as after that the new shopping cart id will be retrieved.

We should re-create shopping cart (to get new token/id automatically).

An example on how can we recreate the cart:
https://github.com/pkarw/vue-storefront/blob/f90f64de9cb3ce02e0f5c92d6ceba51014a066ca/core/modules/cart/store/actions.ts#L662

Expected behavior

Steps to reproduce the issue

This issue is not occurring all the time - to be honest, it's pretty hard to recreate it. I used to have when I've logged in as a user after 5-6months of inactivity. The user account has some quote id assigned (like 5561) which has been no longer valid.

We can probably reproduce this issue by manually setting the localStorage key shop/carts/current-cart-token to random value and testing the subsequent cart synchronization logic

@pkarw
Copy link
Collaborator Author

pkarw commented Mar 14, 2019

Moreover we need to fix cart/actions.ts:411 to better handle the issue (as on screenshot)

@pkarw pkarw added bug Bug reports 5: Complex P2: Important Priority mark - still high ;) labels Mar 14, 2019
@pkarw pkarw modified the milestones: 1.9.0, 1.10.0, 1.10.0-rc.1 Mar 18, 2019
@pkarw pkarw modified the milestones: 1.10.0-rc.1, Feature waitinglist Apr 4, 2019
@michhy
Copy link

michhy commented Apr 26, 2019

Hi Piotr
I found the way to recreate this issue:
just remake order > clear cart > remake order again for a few times
it also leads to shipping method and payment method loading errors.

*** strange thing is, once it happened and push you back to homepage, then you try to remake order again, it succeeded.

螢幕截圖 2019-04-26 下午12 23 46

@michhy
Copy link

michhy commented Apr 26, 2019

I found out the way to fix it:

in core/modules/cart/store/action.ts,
in the function "clear (context)"
remove the line
context.commit(types.CART_LOAD_CART_SERVER_TOKEN, null)
add this line instead
context.commit(types.CART_SAVE, [])

this basically avoid the token error (originally it turn the cart token to null, and 'remake order' won't generate the new token for the cart, leads to the error 'no such entity with cartID = null');
and the added line will remove all the cart items in server side instead of just cart (
without this added line, after 'remove cart' and if you click 'back' from the browser, the cart will load again as the server didn't know you have removed the cart items.

@pkarw
Copy link
Collaborator Author

pkarw commented Apr 26, 2019

@michhy with the proposed fix it might happen that we'll clear the server side cart BEFORE order was being transferred to Magento and being placed -> Risky.

Shouldn't we instead call cart/serverCreate in here to make sure cart token isn't empty? Probably we need

@michhy
Copy link

michhy commented Apr 26, 2019

@pkarw Yea, you are right.
now I edit the function code like this:
at the bottom of clear(context) function, after the if {}
else { rootStore.dispatch('cart/serverCreate', { guestCart: true }, { root: true }) }

and it seems fine, fixed the cartID token issue and also clear the cart item from server.

@pkarw
Copy link
Collaborator Author

pkarw commented Apr 26, 2019

OK, cool - could You propose a PR with this fix please?

@michhy
Copy link

michhy commented Apr 26, 2019

@pkarw it might sounds ridiculous, this is my first time working on github projects, I even donno how to fork my project and merge the updates, I did it all by copy and paste (compare my old code and embed the updates).... :'(
Do you have any github tutorial that I can follow the steps?

Thanks :P

@pkarw
Copy link
Collaborator Author

pkarw commented Apr 26, 2019

I think this one could be helpfull: https://help.github.com/en/articles/creating-a-pull-request

@pkarw pkarw closed this as completed Apr 27, 2019
pkarw added a commit that referenced this issue Apr 27, 2019
pkarw added a commit that referenced this issue May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5: Complex bug Bug reports P2: Important Priority mark - still high ;)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants