The first time through, only the first "AddOrUpdateOrderProperty" line seems to work, as later in the page, the values are used to populate text fields. E.g. :
value="@order.Properties[ "firstName" ]"
If I then press F5 to refresh the page, all textboxes are populated.
It is only the first line that works, if I change the order, then whichever line is first gets populated - in terms of showing in the textfield on the page.
Am I missing some code, do I need to reload the order after creating the order properties?
One thing you could try to get it working could be to call TC.AddOrUpdateOrderProperties instead which should set all the properties in one go. But I'd still like to try and understand what is happening here.
It is a new order process. A user has added items to the basket and have gone to the first checkout step (enter your name and details).
On their way, they can login if they are an existing customer (which is when the issue is presenting itself). If they do login, the code above gets their current details and populates the form with their details.
Only the first item gets set on the current "order" variable. Above, I have the surname first, originally it was forename.
I have added the line:
order = TC.GetCurrentOrder(storeId, false);
at the end of the "if" statement and now the form populates completely - but why does the first property work without reloading the order?
Looking at the set order property method though, each one of those calls sets a property and then saves the order so unless these are all happening too quickly, I'm not sure why.
There is some logic in the process that says if the current order has started the payment process, then it actually clones the order leaving the original as is so I wasn't sure if that was playing a part, but I don't think it would here.
I'll have to try and dig a little deeper, but in the mean time I would suggest you switch to using TC.AddOrUpdateOrderProperties at least as this will set all the properties at once and only trigger a single Save() request, saving on DB hits.
Interesting. I've got a feeling it is something to do with each request causing a save, so that is a lot of things happening so maybe it just struggles.
Good to know the TC.AddOrUpdateOrderProperties resolves it for you though 👍
Custom Property problem
I have a strange (or possibly not!) issue with the code below:
The first time through, only the first "AddOrUpdateOrderProperty" line seems to work, as later in the page, the values are used to populate text fields. E.g. :
If I then press F5 to refresh the page, all textboxes are populated.
It is only the first line that works, if I change the order, then whichever line is first gets populated - in terms of showing in the textfield on the page.
Am I missing some code, do I need to reload the order after creating the order properties?
Does an order exist before you hit this code? Or more specifically, at what point in the checkout process do you hit this code?
One thing you could try to get it working could be to call
TC.AddOrUpdateOrderProperties
instead which should set all the properties in one go. But I'd still like to try and understand what is happening here.It is a new order process. A user has added items to the basket and have gone to the first checkout step (enter your name and details).
On their way, they can login if they are an existing customer (which is when the issue is presenting itself). If they do login, the code above gets their current details and populates the form with their details.
Only the first item gets set on the current "order" variable. Above, I have the surname first, originally it was forename.
I have added the line:
at the end of the "if" statement and now the form populates completely - but why does the first property work without reloading the order?
Quick answer, I'm not entirely sure 😁
Looking at the set order property method though, each one of those calls sets a property and then saves the order so unless these are all happening too quickly, I'm not sure why.
There is some logic in the process that says if the current order has started the payment process, then it actually clones the order leaving the original as is so I wasn't sure if that was playing a part, but I don't think it would here.
I'll have to try and dig a little deeper, but in the mean time I would suggest you switch to using
TC.AddOrUpdateOrderProperties
at least as this will set all the properties at once and only trigger a singleSave()
request, saving on DB hits.Subject to more testing - using
TC.AddOrUpdateOrderProperties
seems to have fixed it.By the way, I also removed the
order = TC.GetCurrentOrder(storeId, false)
line too.Interesting. I've got a feeling it is something to do with each request causing a save, so that is a lot of things happening so maybe it just struggles.
Good to know the
TC.AddOrUpdateOrderProperties
resolves it for you though 👍is working on a reply...