1) First and foremost, make sure your XML or JSON output follows these basic rules:
- Enclose the whole thing with <items> (for XML) or "items" (for JSON).
- Enclose every individual item with <item> (for XML) or "item" (for JSON).
- You can have as many <item> sets as you need, with each one containing their own parameters, but you can't add another nesting level inside each <item> set.
This XML example will bring it all together. It displays two items plus their individual information (name, link, date, image, description and price):
<items>
<item>
<title>Product 1</title>
<link>//www.mystore.com/product1</link>
<date>16-11-2015</date>
<image>//www.mystore.com/product1.jpg</image>
<description>My first item</description>
<price>10</price>
</item>
<item>
<title>Product 2</title>
<link>//www.mystore.com/product2</link>
<date>16-11-2015</date>
<image>//www.mystore.com/product2.jpg</image>
<description>My second item</description>
<price>10</price>
</item>
</items>
Fancy JSON instead? Just follow this example:
{ "items": { "item": [{ "title": " Product 1", "link": "//www.mystore.com/product1", "date": "16-11-2015", "image": "//www.mystore.com/product1.jpg", "description": "My first item", "price": "10" }, { "title": "Product 2", "link": "//www.mystore.com/product2", "date": "16-11-2015", "image": "//www.mystore.com/product2.jpg", "description": "My second item", "price": "10" }] } }
2) Now set up a URL for your online store which dinamically generates an XML or JSON output according to the above format. (eg http://www.mystore.com/JSON/ if you go for JSON).
How can I plug the output into my email?
1) Create your email using our Email Builder editor. While editing it, drag the "HTML" widget from the left-hand panel to where you want the store's output to appear in your email.2) An HTML block will come up. Head over to the right-hand panel and replace its whole content with the code snippet below:
{{EXTERNALBLOCK:http://www.mystore.com/JSON/}}{{EXTERNALFORMAT:json}}{{EXTERNALITEMS:count=2}} <table style="width: 100%;"> <tr> <td style="width: 50%; text-align: left;"> <img src="{{EXTERNALITEM:image_thumbnail}}" alt="{{EXTERNALITEM:image_thumbnail}}" border="0" style="border: 0px none; outline: none; text-decoration: none; vertical-align: bottom;" /> </td> <td style="width: 50%; color: #9D9D9D; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; font-size: 13px; line-height: 22px; text-align: left;"> <span style="font-family: Arial,Helvetica Neue,Helvetica,sans-serif; font-size:16px; font-weight: normal; margin: 0px;"> {{EXTERNALITEM:title}}</span> <br /><br /> <br /> <span style="font-size:20px;">{{EXTERNALITEM:price}}</span> </td> </tr> </table> {{ENDEXTERNALITEMS}}{{ENDEXTERNALFORMAT}}{{ENDEXTERNALBLOCK}}
- The EXTERNALBLOCK variable sets content to load from the URL you entered. The EXTERNALFORMAT variable states whether your output is JSON or XML. EXTERNALITEMS:count specifies how many items to display (in case your URL's output contains a large number of items).
- The HTML code will display each item's image, title and price.
- The ENDEXTERNALITEMS, ENDEXTERNALFORMAT and ENDEXTERNALBLOCK variables close off the dynamic content block.
That's basically it! When you send out your email using E-goi, the above variables will be turned into the name, image and price of the items in your JSON or XML output, fetched over straight from your store.
How can I use the above to have my email displaying the items my customers have in their cart?
The first thing you should do is set up E-goi's Track & Engage across your online shop so we can track the items each customer adds to their cart. Then use our !current_cart_products merge code to plug into your email the item IDs of the products the customer added. To do that, the URL in the code example above ( http://www.minhaloja.com/JSON/ ) should be changed to:
{{EXTERNALBLOCK:http://www.mystore.com/JSON/!current_cart_products}}
This will pull the product info based on the product ID Track & Engage assigned to the specific item the customer added to their cart.