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

Can't add items to cart after reaching the payment checkout step #12

Open
tritao opened this issue Jun 16, 2022 · 5 comments
Open

Can't add items to cart after reaching the payment checkout step #12

tritao opened this issue Jun 16, 2022 · 5 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tritao
Copy link

tritao commented Jun 16, 2022

If you go through the checkout process, up to payment screen, then go back to the store, and try adding some more products to the cart, you get hit with Order contents may only be modified when in the "AddingItems" state.

I think this makes sense since Vendure has the order state machine, however this needs to be fixed for production usage.

All I can think of is special casing the code that deals with adding a product to the cart, checking the order state, and transitioning back out of the payment order state.

Does this solution make sense or do you have a better idea how to tackle this?

@michaelbromley
Copy link
Member

Yeah that's a good point. So there are 2 approaches we can take:

  1. Do not transition the order to ArrangingPayment until the very last moment, immediately before we make the addPaymentToOrder mutation.
  2. (your idea) Include a check for the current order state when going back from the payment page or adding an item and, if it is not AddingItems, then transition to that state.

I'm not sure whether one is clearly better than another. But I'd be happy with either.

@michaelbromley michaelbromley added help wanted Extra attention is needed good first issue Good for newcomers labels Jun 17, 2022
@kyunal
Copy link
Collaborator

kyunal commented Jun 17, 2022

I take issue with part of your follow-up to the second proposal, a check for when you are going back from the payment page is not sufficient as one might just close the tab or navigate elsewhere with a link. So just the idea of checking the order state upon adding more items or changing the cart in any way, shape or form would suffice.

Are there any potential side effects with either of the two approaches? The first has two consecutive API calls during payment as far as I understood, I'm not sure if that is a great way to handle things in such a crucial step. But that's just my intuition 😛

@michaelbromley
Copy link
Member

@kyunal yes you are totally correct in your assessment - an action taken on adding would be better.

Or - maybe even better: When executing addItemToOrder, if we get a result of type OrderModificationError, we can transparently handle it by transitioning to AddingItems and then repeating the add item mutation. This would avoid needing any checking logic before each call.

The two consecutive mutations as in option 1 is not necessarily a problem, but we'd need to make sure the first call to transitionOrderToState does not return an ErrorResult before making the second call.

@kyunal
Copy link
Collaborator

kyunal commented Nov 23, 2022

Is this issue still recent? I believe the payment mechanism in the storefront has been refined since the issue was created. Right now the active order is only set to ArrangingPayment shortly before the payment is added to the order. This at least applies to Stripe and the dummy payment. I think this eliminates the issue unless something goes wrong when attempting to add the payment to the order.

It might still be good to have a backup mechanism for this event but I think the primary issue has already been eliminated as I haven't been able to reproduce it anymore.

@michaelbromley
Copy link
Member

@kyunal yes I think the main issue is resolved, and what is left is something of a rarer edge case which indeed would be good to take care of if we want to be really solid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants