Copied to clipboard

Flag this post as spam?

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


  • Vold Hooker 15 posts 35 karma points
    Mar 09, 2012 @ 07:51
    Vold Hooker
    0

    Add orderline event args?

    We have a scenario where we need to make a check through an external system to verify that the product being added is in stock in a sufficient amount. If it's not in stock, a number of things could happen depending on stock levels.

    Hooking up through the

    WebshopEvents.OrderLineChanged
    

     is  easy. Unfortunately, I have been unable to find a good, clean way of:

    Cancelling the add to stock. There is no way of telling the system that the orderline should not be added.
    Signalling the error to the user. Various order data is returned through JSON but it seems I cannot return a status or message and therefore not react to it in the UI.

    I've resorted to raising an exception and reacting to that in the TeaCommerce.addOrderLine javascript method. This however is a very ugly hack and my question is what is the proper way of doing things?

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 09, 2012 @ 08:05
    Rune Grønkjær
    0

    Hi Vold,

    The solution is as simple as it's fast to implement. You simply set the quanity of the orderline to either zero or to whatever number the stock allowes. You then COULD throw an error, to be caught by the javascript and then handled appropriately in the client.

    How does that sound?

    /Rune

  • Vold Hooker 15 posts 35 karma points
    Mar 09, 2012 @ 09:55
    Vold Hooker
    0

    Hi Rune,

    That is what I do - I set it to the maximum allowable. However, what I'd like to do is to inform the user of this. I might also require some other actions. Potentially I could find a need to prevent the orderline from being added altogether or something of this nature.

    Also, since the previous value is not provided I cannot set the orderline quantity to what it was before - I am forced to set it to either the maximum allowable or an arbitrary value.

    In short, I would like to do some server side logic and depending on the outcome be able to manipulate the orderline/order and provide user feedback. Currently I can't find a smooth way of doing this other than throwing an exception, handling the exception in javascript to provide user feedback and some database stuff to for instance get previous orderline quantity.

    I can work around it for sure - I'm just curious whether I've missed something and whether you consider workarounds an acceptable way of addressing the issue.

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 09, 2012 @ 10:00
    Rune Grønkjær
    0

    Ok, then you have a few more posibilities. First of all (Just to make sure), remember to save the order when you have changed anything on it. That means both order lines og whatever.

    The status message could be added to the order properties, which is available for the javascript. Just make a "clientmessage" (or whatever you want to call it) property and add it to the order. The message can then be displayed to the user. If you need more messages, just create more properties.

    You can do the same for the individual order line by adding properties to that as well.

    /Rune

  • Vold Hooker 15 posts 35 karma points
    Mar 09, 2012 @ 10:56
    Vold Hooker
    0

    Alright. The extra orderline properties gets persisted to the database though, right?

    I'd prefer not to persist any info that is strictly info for one request in the UI and not used anywhere else but I can work with that approach.

     

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 09, 2012 @ 11:01
    Rune Grønkjær
    0

    Yes, it will be persisted. But you can just clean it up later in the process. It's how I would do it.

    Alternatively you could create your own base method "GetStockInformation" and call that before and after the addOrderLine call. But the other one is cleaner and uses the tools at hand.

    /Rune

  • Vold Hooker 15 posts 35 karma points
    Mar 09, 2012 @ 11:22
    Vold Hooker
    0

    Alright, sounds good, this is the approach I will take.

    Thank you for your swift answer. I'm really happy with the Teacommerce tests I've done so far.

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 09, 2012 @ 11:24
    Rune Grønkjær
    0

    No problem. Just happy to help. Feel free to ask again some other time.

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft