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

How to handle already sold products which are still in the cart? #842

Closed
duncanmcclean opened this issue Mar 3, 2023 Discussed in #841 · 5 comments · Fixed by #847
Closed

How to handle already sold products which are still in the cart? #842

duncanmcclean opened this issue Mar 3, 2023 Discussed in #841 · 5 comments · Fixed by #847
Labels

Comments

@duncanmcclean
Copy link
Owner

duncanmcclean commented Mar 3, 2023

Discussed in #841

Originally posted by itsmesaskovic March 3, 2023
We are selling used books via our Simple Commerce setup.
Now we have had an issue where a user placed an order, paid for it, but it never got flagged as paid.

Looking back in the logs, I found out that the cart was filled with a number of books for the February 10 date. However, on February 10, another visitor also added some of the selected books to the cart and fulfilled the order.
Because they were already in our first customers shopping cart, they could place an order with these books on February 22. However, upon confirmation, the order could not be processed automatically, as the books were already out of stock.

What would the best practice be to handle this before order submission / payment?

Solution

Simple Commerce should be checking the stock of products in the cart before redirecting the user to off-site gateways.

This won't be an issue if you're using an on-site gateway because the stock is checked before collecting payment.

duncanmcclean added a commit that referenced this issue Mar 4, 2023
duncanmcclean added a commit that referenced this issue Mar 4, 2023
* Split up checkout pipeline

There's some stuff we need to do before the payment and there's other stuff we need to do after the payment has happened.

* Add a full stop

* Remove old import

* Split up tests

* Adjust CheckoutController tests

The stock events are only dispatched when updating the stock count on the product.

So if it doesn't get that far (for example, if it fails stock validation), then the events won't be dispatched because nothing's actually changed.

* Do checkout validation just before payment

* Don't listen specially for stock exception

Instead have the stock exception extend the PreventCheckout exception.

* wip

* Ensure #842 has been fixed
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

Released as part of v4.5.6.

@itsmesaskovic
Copy link

After this release the following happens when testing:

  1. User A adds product X to the basket and sees it in domain.org/shop/cart
  2. User A continues shopping.
  3. User B adds product X to the basket and sees it in domain.org/shop/cart
  4. User B continues to checkout (domaing.org/shop/checkout/information)
  5. User B fulfills the order and pays via Mollie.
  6. User B is redirected (callback) to the success screen.
  7. User A continues to checkout (domaing.org/shop/checkout/information)
  8. User A clicks on submit order
  9. SimpleCommerce checks stock and invalidates the specific product from the cart
  10. User A is redirected to the checkout (information) screen where no product is available
  11. SimpleCommerce (?) redirects the user to an unknown cart screen (/cart instead of /shop/cart?)

image

We have interrupted the default SimpleCommerce process, if I'm correct, since we handle everything on the checkout screen.
Is there something additional we need to do to support this new (no stock) flow?

@duncanmcclean
Copy link
Owner Author

Simple Commerce should redirect the user back to whatever URL they were on previously (previous to being redirected to the off-site checkout page which should be the /shop/checkout/information page)

Then on that page, if you do {{ session:errors | dump }}, you should see an error which Simple Commerce throws that you can catch and put somewhere for the user to see.

Let me if any of that isn't working as explained and I'll see what I can do to help.

@itsmesaskovic
Copy link

That's correct Duncan. The page redirected to is /shop/checkout/information. I just found the issue on our side.
We have this code on the information page:

{{ if {sc:cart:count} === 0 }}
{{ redirect to="/cart" }}
{{ /if }}

Since the cart is emptied the user is automatically redirected to the (wrong) cart.
So we should stay on the information page, but with the message that the cart items have change.

Thanks!

@duncanmcclean
Copy link
Owner Author

Ah okay, that makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants