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

Prevent checking out if there are unavailable products in the cart (OCC-199) #375

Closed
sarahelsaig opened this issue Nov 9, 2023 · 4 comments · Fixed by #377
Closed

Prevent checking out if there are unavailable products in the cart (OCC-199) #375

sarahelsaig opened this issue Nov 9, 2023 · 4 comments · Fixed by #377
Assignees
Labels
bug Something isn't working

Comments

@sarahelsaig
Copy link
Contributor

sarahelsaig commented Nov 9, 2023

Describe the bug

Currently you can try to check out an order with "Inventory: 0" and it will only fail after the payment is already made.

To Reproduce

Steps to reproduce the behavior:

  1. Edit a product by setting its Inventory to 0.
  2. Try to check it out.
  3. See InvalidOperationException after the payment has been processed!

Expected behavior

  • The checkout button on the "Your Cart" screen should be greyed out when there is such a product in the cart.
  • An error notification of the inventory shortage should be displayed on the cart screen.
  • The checkout screen should redirect you back to the cart so this problem can't be bypassed by manually navigating to the ~/checkout url.

Screenshots

gif

Jira issue

@sarahelsaig sarahelsaig added the bug Something isn't working label Nov 9, 2023
@github-actions github-actions bot changed the title Prevent checking out if there are unavailable products in the cart Prevent checking out if there are unavailable products in the cart (OCC-199) Nov 9, 2023
@porgabi porgabi self-assigned this Nov 9, 2023
@porgabi
Copy link
Contributor

porgabi commented Nov 9, 2023

As far as I can see, the one way to reproduce this is to alter the product's inventory after it's been added to the cart because the "Add to cart" button's clickability is based on the product's inventory (i.e. if it cannot be bought, the button cannot be clicked and the product cannot appear in the cart). I'm fixing that; just wondering if you found other ways to repro the bug?

@porgabi
Copy link
Contributor

porgabi commented Nov 10, 2023

I added the part of the checkout prevention that's responsible for preventing manually navigating to the checkout page and for the redirection back to the cart in PaymentService, which requires PriceVariantsPart and IProductService. This was before I merged the solution changes from #373, after which it no longer works as these are not available in the Payment project and cannot be added due to circular dependency.
image

This was then used in PaymentController's Index() method to determine if checkout is possible.
image

373 is a bit of a monster PR to comprehend in one sitting, do you have any suggestions where I could place this logic instead, @sarahelsaig? Or perhaps moving PriceVariantsPart and IProductService to the Commerce.Abstractions project could work?

@sarahelsaig
Copy link
Contributor Author

At the start of IPaymentService.CreateCheckoutViewModelAsync() we call ICheckoutEvents.OrderCreatingAsync(). Similarly, you could add another method to ICheckoutEvents which would be called near the end of IPaymentService.CreateCheckoutViewModelAsync(). Such as ICheckoutEvents.ViewModelCreatedAsync(). Then you can create an appropriate event handler in OrchardCore.Commerce and move your processing logic into it.

@porgabi
Copy link
Contributor

porgabi commented Nov 11, 2023

That does the trick, thanks!

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
2 participants