Copied to clipboard

Flag this post as spam?

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


  • Bo Kingo Damgaard 157 posts 456 karma points
    Mar 06, 2013 @ 11:39
    Bo Kingo Damgaard
    0

    Can't overwrite an orderline property server side

    Hi

    I'm implementing a coupon system for my TC solution.
    On the client side I have a input field for each orderline where I can input a coupon code. When validating the coupons, I call TeaCommerce.updateOrderLineProperty from the client with a 'couponCode' property, and on the server I hook into WebshopEvents.OrderLinePropertiesUpdated to check for a valid coupon code.
    If the coupon is not valid for that orderline, I need to signal that to the client. The only way I can find to do this is but setting 'couponCode' property on the passed in orderlineproperties and call order.save().
    On the client I then check for OderLinePropertiesUpdated[0].Value for empty and display a message accordingly.

    This approach only work the first time. I the customer types it wrongly, I can notify them, but on the second call to TeaCommerce.updateOrderLineProperty I'm not able to set the property to empty on the server and the client gets the entered value back, and hence it's valid. I've  notised a difference between then first and the following calls: The ID of the property that gets returnered the client is different from 0 on the first call, but allways 0 on the following calls.

    I run Umbraco 4.7.0 and TC 1.4.1.2

    The serverside code is:

    void WebshopEvents_OrderLinePropertiesUpdated(Order order, OrderLine orderLine, IEnumerable<OrderLineProperty> orderLineProperties)
    {
        var discount = orderLineProperties.Where(p => p.Alias == "couponCode")
      .FirstOrDefault();
        if (discount != null)
        {
            if (orderLine.IsValidCoupon(discount.Value))
            {
                var coupon = DocumentLibrary.GetCoupon(discount.Value);
                orderLine.UnitPriceWithoutVAT = 
            orderLine.OriginalUnitPriceWithoutVAT * (1-coupon.Discount/100);
                order.Save();
            }
            else
            {
                discount.Value = "";
                order.Save();
            }
        }
    }
    

    1. Is this a TeaCommece error?
    2. Is there a better way to signal the client?

    Kind regards

    Bo

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 06, 2013 @ 11:47
    Rune Grønkjær
    0

    Hi Bo,

    There shouldn't be a problem doing that. Have you tried debugging the code on your local IIS? If you can't do that, use the umbraco Log to log what happens.

    I would check that:
    Are your .net event being fired the second time?
    Does it run the else part of your script?

    /Rune

  • Bo Kingo Damgaard 157 posts 456 karma points
    Mar 06, 2013 @ 12:01
    Bo Kingo Damgaard
    0

    Hi Rune

    Thanks for the quick reply

    I'm debugging on my local PC, and yes the event is called twice, which I don't understand why. The ELSE part is also executed.
    As I mentioned, in the returned data to client to property only has a valid ID on the first call. Could it be that I can't overwrite an already defined property?

    /Bo

  • Bo Kingo Damgaard 157 posts 456 karma points
    Mar 06, 2013 @ 13:19
    Bo Kingo Damgaard
    0

    Hi again

    I just realized I misread your post a bit. the .NET event is fired every time I call the TeaCommerce.updateOrderLineProperty, however the event is call twice every time - maybe because of order.save()

    /Bo

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 06, 2013 @ 13:49
    Rune Grønkjær
    0

    Hi Bo,

    Yes. When you save the order the event will be fired again, as you have changed the property.

    An already defined property can always be changed on the server. So no problems there.

    Could you check that the the order property is also change on the order? I mean debug the order, find the orderline and the property and see if it's changed there as well.

    Is it just the JavaScript that gets wrong data? In the JavaScript call the TeaCommerce.getOrder() method and check the values there as well.

    /Rune

  • Bo Kingo Damgaard 157 posts 456 karma points
    Mar 06, 2013 @ 14:33
    Bo Kingo Damgaard
    0

    Hi Rune

    The property is changed on the order and the order object that is returned along with the OrderLinePropertiesUpdated object contains the updated couponCode. I now just have to find the right Property on the right Orderline in the Order object. I have the orderline ID and Property alias stored but I'm uncertain on how to find the property in JS. Do you have a suggestion?

    /Bo

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 06, 2013 @ 14:36
    Rune Grønkjær
    100

    Hi Bo,

    Use the browser console to call TeaCommerce.getOrder()

    The object returned can be inspected and you can see all information currently on the order.

    /Rune

  • Bo Kingo Damgaard 157 posts 456 karma points
    Mar 06, 2013 @ 16:07
    Bo Kingo Damgaard
    0

    Hi Rune

    I got it working by looping all orderline and all properties :)

    Thanks for the help

    /Bo

  • Rune Grønkjær 1372 posts 3103 karma points
    Mar 06, 2013 @ 16:27
    Rune Grønkjær
    0

    Cool. Glad I could help.

    BTW Tea Commerce 2 is much better when doing stuff like that. So look out for our release.

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft