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.
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.
Validate Current Order Before Checkout
Hi,
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) andOrderLineQuantityValidationHandler
(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?
Thanks
Hi Nalysa,
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 thePaymentStatus
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
Matt
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.