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.
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?
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?
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()
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.
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?
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:
1. Is this a TeaCommece error?
2. Is there a better way to signal the client?
Kind regards
Bo
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
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
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
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
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
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
Hi Rune
I got it working by looping all orderline and all properties :)
Thanks for the help
/Bo
Cool. Glad I could help.
BTW Tea Commerce 2 is much better when doing stuff like that. So look out for our release.
/Rune
is working on a reply...