Copied to clipboard

Flag this post as spam?

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


  • Nalysa 48 posts 269 karma points
    Sep 18, 2020 @ 10:37
    Nalysa
    0

    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) 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?

    Thanks

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 18, 2020 @ 12:50
    Matt Brailsford
    100

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

    Matt

  • Edgar Rasquin 326 posts 925 karma points
    May 11, 2022 @ 11:50
    Edgar Rasquin
    0

    Hi Nalysa,

    have you, in the end, managed to build the validation? If so, would you mind sharing the code?

    @Matt Has there been any new features in the latest version of Vendr or are there any plans to build in functionality?

    Thanks

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 11, 2022 @ 13:39
    Matt Brailsford
    0

    Hey Edgar

    It’s a tricky one to decide on the best implementation

    A simpler implementation might be on the final stage of checkout, rather than render Vendr’s payment form at that point, go to an interim page of your own which validates the order and if everything is ok, render the payment form and have it auto submit so you are then sent to the payment gateway. If it didn’t validate, then redirect back to the checkout with a message on why it failed validation. There is a slight risk here though that during the few seconds/minutes it takes to pay at the payment gateway the item could go out of stock.

    So, a more complex option might be to use a payment provider that supports “Authorised” payments (ie, approve the payment but don’t capture it yet) and allow customers through the entire checkout flow but only authorise the transaction then on the confirmation page you perform the final validation and if everything is ok, trigger a capture of the authorised payment or otherwise cancel the transaction. The only issue here is that even a canceled transaction is a final state for an order so you’d potentially need to recreate the order to let the customer try again.

    There may be some other things that need to be thought about too but I’m not sure off the top of my head. If you can live with a small degree of error then the simpler option might suffice, but if you need absolute certainty, something along the lines of the second option might be needed.

Please Sign in or register to post replies

Write your reply to:

Draft