Copied to clipboard

Flag this post as spam?

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


  • Tom Steer 161 posts 596 karma points
    Feb 11, 2019 @ 18:49
    Tom Steer
    0

    Stock Validation

    Hey,

    I'm currently in the process of building a TeaCommerce website that tracks stock for its products. I have everything setup in the backoffice but I'm struggling to find the best way to manage stock validation on the frontend.

    For example when adding/updating a product to the basket, where and how should I validate the stock of that product during that workflow?

    The only way I could see this working is using the OrderLineUpdating/Adding events to check the stock there and altering the user's quantity to ensure it's within the stock level. This however, doesn't seem like the best way as it's hard to inform the user of this automatic change. Alternatively, in some scenarios you might not want to alter their quantity, instead show an error message but I don't think it's possible to cancel the TC events from what I can tell?

    Would be great to hear how others have managed this in the past with TC.

    Cheers, Tom

  • Matt Brailsford 2246 posts 10979 karma points MVP 6x c-trib
    Feb 12, 2019 @ 12:24
    Matt Brailsford
    0

    Hi Tom,

    You are right that currently the pre-action events aren't cancelable so it's not currently possible to stop an order bring processed to do some checks. The only options I can think of are

    1) Implement some javascript to intercept the "make payment" form button press and have that call an API controller which checks stock levels and if all good, allow the submit button to continue, otherwise display an error.

    or

    2) (I'm not sure entirely how to hook this one up) On the final checkout page before payment, instead of rendering the TC checkout form, render out an action to go to your own controller and do a similar stock validation check. If successful redirect to the actual TC form (this might have to render to the page, but then use a bit of javascript to auto submit it). And again, if the validation check fails, return to the checkout page to show errors.

    I appreciate neither of these are ideal, but I'm just trying to outline a couple of possibilities based on the current codebase.

    I hope this helps

    Matt

  • Matt Brailsford 2246 posts 10979 karma points MVP 6x c-trib
    Feb 12, 2019 @ 12:26
    Matt Brailsford
    0

    PS For either of these approaches, there is at least an API for checking product stock levels https://docs.teacommerce.net/3.3.0/api/product/#getstock

Please Sign in or register to post replies

Write your reply to:

Draft