Copied to clipboard

Flag this post as spam?

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


  • Mark 122 posts 255 karma points
    Jan 23, 2015 @ 16:53
    Mark
    0

    Javascript api, prevent form post

    Is it at all possible to cancel a form post (ajaxForm) for AddOrUpdateOrderLine to prevent lines being added to an order?

    Basically, I want to limit the max quantity of items in a basket, and max quantity of individual order lines in a basket. I'm thinking if it is possible, then to do it from 

    TC.bind('beforeAddOrUpdateOrderLine', function (data, jQForm) {});

    but I'm not convinced it will be possible..

    If not, then not to worry, I am working on a way to reverse the AddOrUpdate.. based on current order totals, but that does mean 2 calls to AddOrUpdate.. which seems a little messy.

    Any thoughts would be appreciated!

    Mark

  • Kim Pilgaard 10 posts 96 karma points
    Jan 29, 2015 @ 10:21
    Kim Pilgaard
    0

    If it is a formpost then you could probabilly add your own submit function to handle the logic, returning 0 from a formpost function will ensure that the form is not posted to Tea Commerce. This logic could ensure that you only call AddOrUpdate if there is something to add or update, however it will not catch sneaky users who use the javascript api directly on your website. So this approach wouldn't be good if this is a concern.

    If it where me I would use the .net api to hook into the Tea Commerce events. For example "OnOrderLinesAdding" and "OnOrderLinesUpdating" events to enforce orderline quantity limitations.

  • Mark 122 posts 255 karma points
    Jan 29, 2015 @ 10:49
    Mark
    0

    Hey Kim,

    I was actually going to update this in a bit to say that's what I've ended up doing. I ended up setting a custom order property to echo back the the customer that a limit had been reached. To add confusion, of course when I saved the order having updated quantities etc, it fires the even again, clearing my message. So I had to set an orderline property on submit so that it would only clear my client message on a basket update initiated by the user.

    Javascript was then able to read the order property and echo it back to the user. Easy in the end, took a while working out all my logic though for various limits and messages and when to clear them!

    Thanks for the pointer though :-)

    Mark

Please Sign in or register to post replies

Write your reply to:

Draft