Encoding Parameters on a Receipt Notification Email

Encoding Parameters on a Receipt Notification Email

Often merchants want to provide a link to an external survey system on their receipt email. The problem is that the typical tokens that are available on the receipt do not properly URL encode the value leading to improper URLs. For example if we wanted to pass along the order id plus a value from the custom field to another script the custom field will not properly be URL encoded. For example:

http://www.survey.com/takesurvey.jsp?id=[orderid]&param2=[customfield1]

To solve this problem we need to change from using the simple bracket tokens to Velocity code within the receipt. The order object provides methods to expose the details of the order and the formatHelper object provides a method to URL encode the value. So the proper URL syntax would look like:

http://www.survey.com/takesurvey.jsp?id=${formatHelper.urlEncode($order.getOrderId())}&param2=${formatHelper.urlEncode($order.getCustomField1())}

If you have further questions about using velocity code within your receipt, please contact UltraCart Support