Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Nalysa 25 posts 165 karma points
    Sep 18, 2020 @ 10:37

    Validate Current Order Before Checkout


    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?


  • Matt Brailsford 2814 posts 14379 karma points MVP 7x c-trib
    Sep 18, 2020 @ 12:50
    Matt Brailsford

    Hi Nalysa,

    Good question. It is possible to create your own Validation event handlers which you can find some info on here and a list of available events here

    The best I could think to hook into is maybe the UmbracoOrderTransactionUpdate event 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


Please Sign in or register to post replies

Write your reply to: