Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
In our case, we have some products with limited stock and the other products don't care about the stock. We added a new property (boolean) to the product to check whether the product needs to check its stock or not. We managed to validate this by using ProductAddValidationHandler (add product to cart) and OrderLineQuantityValidationHandler (update cart).
Now we face an issue. For example: Product A's stock is 10.
There are 2 users (user X and user Y) that have this same product in their own cart, both have 10 items. Lets say, user X has checkout his cart. The current product stock will be 0. At this moment, user Y shouldn't be able to checkout his cart because now the product is out of stock.
The problem is, currently user Y is still able to checkout his cart because there is no validation to the current order (to check the availability of all products on current order) before the checkout process starts.
What is the best practice to do this validation?
Good question. It is possible to create your own Validation event handlers which you can find some info on here https://vendr.net/docs/core/1-3-0/key-concepts/events/ and a list of available events here https://vendr.net/docs/core/1-3-0/reference/vendr-core-events/#vendrcoreeventsvalidation-namespace
The best I could think to hook into is maybe the UmbracoOrderTransactionUpdate event https://vendr.net/docs/core/1-3-0/reference/vendr-core-events/validateordertransactionupdate/ and listen for the PaymentStatus changing to the initialized state, which generally happens on the review step of the checkout. You could add validation logic there to then check the order for any items that need a stock check and perform the check and fail if stock is now gone.
You might want to set an orderline property to state whether the product that was added requires a stock check as that could save you some resources looking up the node if you don't need to.
Hope this helps
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted