can you point me to right direction I’ have followed the tutorial and managed to impalement Automatic Delivery charge. I’m having minor issue with the Show message action, basically the distance message only appears when product is added to the ticket. I have missed something in the rules and can not pinpoint (I’m still learning).
A quick look at the Tutorial indicates that the Entity Data and Distance is set when the Event for Order Added to Ticket is triggered, so it is operating as designed.
You could possibly change that Rule to fire on the Event of Entity Selected and/or Ticket Entity Changed, however, since the Delivery Charge is based on a Percentage of the Ticket Total, it would not know how to calculate that when no Orders are on the Ticket.
So instead of chaning the Rule, maybe just add another Rule or Rules for Entity Selected and/or Ticket Entity Changed and fire the Show Message action in those Rules to display the Distance.
BEFORE YOU DO THAT … I see you have 2 Actions in your Rule which you named Delivery Message and Delivery Charge. What do they do? Show the Action for Delivery Message. You need to use a [:variable] in that Action for the parameter so you can feed a value into the Action from the Rule. Like this:
You cannot do that. The Action (Show Message) cannot directly retrieve the value you have supplied. You need to supply the value from the Rule. So you must use a [:variable] in the Action “Message” Parameter and then feed the values into the Action from the Rules as I have shown in my previous post.
You will need to remove the Action from the Rule, then Save the Rule, then open the Rule and add the Action back in. Then supply your calculated value expression to the Action via the Rule.
Trying to implement this, and this does work with ‘Order Added to Ticket’ event and updates the distance field.
Having trouble trying to get this rule to fire when ‘Ticket Entity Changed’, as checking after every order item is going to flood google with API requests.
Or is there a way to get the distance field to populate on the ‘new customer’ screen?
You probably would not want to do that. Anytime it would read that field it would run the script. It would be better to run it once and store it then feed the stored value in the Custom Data Field.
You can do that with Entity Updated event maybe? Execute an update program setting and store it in the database.
I understand, I will have a play about - its trying to find an event that the rule can use that is well before order added to ticket - I’ll keep trying! Thanks
Yes you need an event that is not repetitive a single time event. THen store the result in a program setting and you can reference that program setting so it doesnt have to run the API every singe time. You could also store it as a task.
Try the ticket entity changed event but use that event to update a program setting instead of the entity itself. Use the program setting in the Custom Data Field.
I have no idea I’ll have a break and come back to it with fresh eyes later, just frustrating that the script is working but is not updating the entity when I need it to
@JTRTech i did think this could have been an option and is probably what I need to use (so that Distance could be mapped then as $5, at same time as street name etc) I have attempted to do this a couple of times but I’m not up to speed with scripting so struggling to pull the distance data.
You already have both scrips so should be easy.
Add distance script as another function and call that function from postcode lookup script as your distance in return.
Paste scripts.