{"id":1195,"date":"2015-02-11T08:52:00","date_gmt":"2015-02-11T08:52:00","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=1195"},"modified":"2015-10-07T10:45:05","modified_gmt":"2015-10-07T10:45:05","slug":"shopping-in-email-add-to-cart","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/shopping-in-email-add-to-cart\/","title":{"rendered":"Interactive Shopping Widget for Email"},"content":{"rendered":"<p><b>Update 10\/7\/2015: <\/b> <i>Based on Assu&#8217;s comment below I did another check and sure enough AOL Mail now supports forms.<\/i><\/p>\n<p>This example shows how you can create an interactive carousel in email that leverages the power of form support to add products to a shopping cart.<\/p>\n<p>We leverage the concepts in the <a href=\"https:\/\/freshinbox.com\/blog\/interactive-tabs-for-email\/\" title=\"Interactive Tabs for Email\">Tabs for Email<\/a> post and this example works with the native iOS and Android mail clients as well as the Webmail versions of Yahoo! Mail and Gmail. Like the Tab example, this one doesn&#8217;t work with Outlook.com either so users on Outlook.com will see fallback content.<BR><BR><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/assets\/examples\/add-to-cart\/add-to-cart-overview.gif\" alt=\"Interactive Email Carousel With Add To Cart\" width=\"400\" class=\"aligncenter size-full wp-image-1136\" \/><BR><\/p>\n<div id=\"email-me\">\n  <input type=email id=\"email-me-email\" placeholder=\"Email address\"> <input id=\"email-me-btn\" type=button value=\"See Example In Your Inbox\" style=\"-webkit-appearance: none;\">\n<\/div>\n<p><BR><\/p>\n<h4>Using Amazon.com&#8217;s Add To Cart<\/h4>\n<p>For this example, we will use <a href=\"https:\/\/affiliate-program.amazon.com\/gp\/associates\/help\/t1\/a10\" target=\"_blank\">Amazon.com&#8217;s affiliate add to cart<\/a> feature. I chose to use this so that you don&#8217;t have to write the &#8220;backend code&#8221; to try out this example.<\/p>\n<p>The format of a form to add a product to an Amazon.com shopping cart looks like this:<\/p>\n<pre class=\"lang:default decode:true \" >&lt;form method=\"GET\" action=\"https:\/\/www.amazon.com\/gp\/aws\/cart\/add.html target=_new \"&gt; \r\n&lt;input type=\"hidden\" name=\"AssociateTag\" value=\"storeid-20\"\/&gt; \r\n&lt;input type=\"hidden\" name=\"SubscriptionId\" value=\"[AWSAccessKeyId]\"\/&gt; \r\n&lt;input type=\"hidden\" name=\"ASIN.1\" value=\"B00003CWT6\"\/&gt;\r\n&lt;input type=\"hidden\" name=\"Quantity.1\" value=\"1\"\/&gt;\r\n&lt;input type=\"image\" name=\"add\" value=\"Buy from Amazon.com\" border=\"0\" alt=\"Buy from Amazon.com\" src=\"http:\/\/images.amazon.com\/images\/G\/01\/associates\/add-to-cart.gif\"&gt; \r\n&lt;\/form&gt; <\/pre>\n<p>For this example we want the user to be able to select a few colors of an <a href=\"http:\/\/www.amazon.com\/dp\/B00MUQ9E7C\" target=\"_blank\">iPhone 6 case<\/a>. To start off we will have to get the ASIN of the products:<\/p>\n<p>Blue: <a href=\"http:\/\/www.amazon.com\/dp\/B00MUQ9E7C\" target=\"_blank\">B00MUQ9E7C<\/a><br \/>\nPink: <a href=\"http:\/\/www.amazon.com\/dp\/B00MUQ9DVO\" target=\"_blank\">B00MUQ9DVO<\/a><br \/>\nBlack: <a href=\"http:\/\/www.amazon.com\/dp\/B00MUQ9DLO\" target=\"_blank\">B00MUQ9DLO<\/a><\/p>\n<p>Then we create the carousel using the same technique that we used to create <a href=\"https:\/\/freshinbox.com\/blog\/interactive-tabs-for-email\/\" title=\"Interactive Tabs for Email\">Interactive Tabs for Email<\/a>. For this example instead of tabs we use colored boxes.<BR><BR><\/p>\n<div style=\"max-width:400px;margin:20px auto;padding:10px;border:2px solid #AC88AC;text-align:center;border-radius:3px;\">\nCan&#8217;t wait to get started with interactive email?<br \/>\n<a href=\"https:\/\/freshinbox.com\/resources\/tools\/carousel\/\">Try out the Image Carousel for Email Builder<\/a>.\n<\/div>\n<p><BR><BR><\/p>\n<h4>Filling the Form Values<\/h4>\n<p>From the Tabs example you learned that the Tabs are driven using radio inputs. For the example instead of assigning the radio input a random name, we use ASIN.1 as the name and the ASIN tied to the different colors as values.<\/p>\n<p> <span class=\"lang:default decode:true  crayon-inline \" >&lt;input type=radio name=&#8221;ASIN.1&#8243; value=&#8221;B00MUQ9E7C&#8221;&gt;<br \/>\n<\/span> <\/p>\n<p>We use a select input to allow the recipient to select the number of cases to put into the cart.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;select name=\"Quantity.1\"&gt;\r\n&lt;option value=\"1\"&gt;1&lt;\/option&gt;\r\n&lt;option value=\"2\"&gt;2&lt;\/option&gt;\r\n&lt;option value=\"3\"&gt;3&lt;\/option&gt;\r\n&lt;\/select&gt;\r\n<\/pre>\n<p>The rest of the fields we&#8217;ll just use hidden fields as they are required by Amazon but not relevant to our example.<BR><BR><\/p>\n<h4>Capability Detection and Fallback<\/h4>\n<p><b>Update:<\/b> <i>Previously AOL Mail did not support the form tag, however that has since changed. In order to get forms to work in AOL Mail the submissions must go to a https link and the &#8220;target&#8221; attribute of the form must be set.<\/i><\/p>\n<p>As usual we need to provide fallback for clients that don&#8217;t support forms as well as good ol Outlook 2007-2013. <\/p>\n<p>In the Tabs example, we moved the content of Tab 1 outside the Tab container so that unsupported clients will still see the content of Tab 1. In this example we&#8217;ll simply hide the whole unit for unsupported clients and display a separate block for fallback content.<\/p>\n<p>The unsupported clients this time are: Outlook and Outlook.com.<\/p>\n<p>Expanding on the capability detection technique in the Tabs example, we add a further test for the presence of forms in addition to checking for the support of the :checked pseudo class before displaying the form contents.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;style&gt;\r\nform.formcheck .tabcheck:checked + .container{\r\n{\r\n  display:block !important;\r\n  max-height: none !important;\r\n  height: auto !important;\r\n}\r\n\/* Gmail lang trick *\/\r\n* form[lang=\"x-formcheck\"] [lang=\"x-tabcheck\"]:checked + [lang=\"x-container\"]\r\n{\r\n  display:block !important;\r\n  max-height: none !important;\r\n  height: auto !important;\r\n}\r\n&lt;\/style&gt;\r\n \r\n&lt;form class=\"formcheck\" lang=\"x-formcheck\" method=\"GET\" action=\"https:\/\/www.amazon.com\/gp\/aws\/cart\/add.html\" target=_new &gt;\r\n&lt;input type=radio class=\"tabcheck\" lang=\"x-tabcheck\" style=\"display:none !important;\" checked&gt;\r\n&lt;div class=\"container\" lang=\"x-container\" style=\"display:none;height:0px;max-height:0px;overflow:hidden;\"&gt;\r\nFORM CONTENT\r\n&lt;\/div&gt;\r\n&lt;\/form&gt;<\/pre>\n<p>To display an alternative block of content for unsupported clients, we reverse the logic and show the alternative content by default and hiding it if support for forms and the :checked pseudo-class is detected.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/assets\/examples\/add-to-cart\/add-cart-unsupported.png\" alt=\"Unsupported Content\" width=\"225\" class=\"aligncenter size-full wp-image-1136\" \/><\/p>\n<pre class=\"lang:default decode:true \" >&lt;style&gt;\r\nform.formcheck .tabcheck:checked + .fallback{\r\n  display:none !important;\r\n  display:none;\r\n  max-height: 0px;\r\n  height: 0px;\r\n  overflow: hidden;\r\n}\r\n\/* Gmail lang trick *\/\r\n* form[lang=\"x-formcheck\"] [lang=\"x-tabcheck\"]:checked + [lang=\"x-fallback\"]\r\n{\r\n  max-height: 0px;\r\n  height: 0px;\r\n  overflow: hidden;\r\n}\r\n&lt;\/style&gt;\r\n \r\n&lt;form class=\"formcheck\" lang=\"x-formcheck\"&gt;\r\n&lt;input type=radio class=\"tabcheck\" lang=\"x-tabcheck\" style=\"display:none !important;\" checked&gt;\r\n&lt;div class=\"fallback\" lang=\"x-fallback\"&gt;\r\n  &lt;table &gt;&lt;tr&gt;&lt;td width=\"200\" height=\"100\" align=\"center\" valign=\"center\" style=\"border: 2px dotted blue;\"&gt;\r\n  Fallback Content for Unsupported Clients\r\n  &lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;\r\n&lt;\/div&gt;\r\n&lt;\/form&gt;<\/pre>\n<p>Here&#8217;s what the fallback content will look like for our example:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/02\/add2cart-alt.gif\" alt=\"add2cart-alt\" width=\"216\" height=\"238\" class=\"aligncenter size-full wp-image-1462\" \/><BR><BR><\/p>\n<h4>Final Code<\/h4>\n<p>Below is the final HTML\/CSS (<a href=\"http:\/\/codepen.io\/freshinbox\/pen\/xbpWzW\">link<\/a>) incorporating the fallback content. (Version with <a href=\"http:\/\/codepen.io\/freshinbox\/pen\/zxWabO\" target=\"_blank\">fade in effect<\/a>).<\/p>\n<p data-height=\"439\" data-theme-id=\"12191\" data-slug-hash=\"xbpWzW\" data-default-tab=\"result\" data-user=\"freshinbox\" class='codepen'>See the Pen <a href='http:\/\/codepen.io\/freshinbox\/pen\/xbpWzW\/'>xbpWzW<\/a> by FreshInbox (<a href='http:\/\/codepen.io\/freshinbox'>@freshinbox<\/a>) on <a href='http:\/\/codepen.io'>CodePen<\/a>.<\/p>\n<p><script async src=\"\/\/assets.codepen.io\/assets\/embed\/ei.js\"><\/script><\/p>\n<div id=\"email-me\">\n  <input type=email id=\"email-me-email2\" placeholder=\"Email address\"> <input id=\"email-me-btn2\" type=button value=\"See Example In Your Inbox\" style=\"-webkit-appearance: none;\">\n<\/div>\n<p><BR><BR><\/p>\n<h4>Integrating This For Your Own Site<\/h4>\n<p>What you&#8217;ve seen is the ability to use a shopping widget in email to add a product to a shopping cart using the Amazon.com affiliate form code. But what if you want to implement it on your own e-commerce store? Many e-commerce engines may have similar &#8220;add to cart&#8221; API&#8217;s that you can leverage.<\/p>\n<p>However, the folks over at <a href=\"http:\/\/rebelmail.com\" target=_blank>RebelMail<\/a> has taken it one step further.  They&#8217;ve created a complete solution that not only generates interactive widgets from items in your store, the widgets allow customers to select a product, select payment and address options and perform a checkout <a href=\"http:\/\/rebelmail.com\" target=\"_blank\">directly in the email itself!<\/a>.<\/p>\n<p>Just like <a href=\"https:\/\/freshinbox.com\/blog\/compose-interactive-emails-in-gmail-with-mixmax\/\">MixMax<\/a>, RebelMail is pushing the envelope of email and I hope many more will do the same!<BR><BR><\/p>\n<div style=\"padding:10px; border: 2px solid #99C731;background-color:#FFF8DC;border-radius:5px;\">\n<form action=\"https:\/\/freshinbox1.createsend.com\/t\/i\/s\/adrmi\/\" method=\"post\" id=\"subForm\">\n<span class=\"fisub_header\" style=\"font-weight:bold;\">Subscribe to the #EmailGeeks Newsletter<\/span>\n<p><input id=\"fieldEmail\" name=\"cm-adrmi-adrmi\" type=\"email\" style=\"width:90%\" required placeholder=\"Your Email Address\" \/><\/p>\n<p><button type=\"submit\">Subscribe<\/button><\/p>\n<\/form>\n<\/div>\n<style>\n#email-me-email,#email-me-email2 {\n  width:170px;\n  height:20px;\n  margin-bottom: 5px;\n  background-color: #FAFCEF;\n  font-size: 14px;\n  padding: 3px 5px;\n  display:inline-block;\n  border-radius:3px;\n  margin-left:20px;\n}\n#email-me-btn,#email-me-btn2 {\n  cursor: pointer;\n  font-size: 14px;\n  color: white;\n  text-decoration:none;\n  text-shadow:#555555 0 1px;\n  background-color: #7DC442;\n  padding: 5px 12px;\n  border:1px solid #559621;\n  border-radius: 5px;\n  display:inline-block;\n}\n#email-me-btn:hover {\n  background-color: #78D62C;\n}\n#email-me{\n  width: 420px;\n  padding:20px;\n  xborder:3px solid #888888;\n  xborder-radius: 5px;\n  margin:0px auto;<\/p>\n<p>}\n<\/style>\n<p><script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.10.2\/jquery.min.js\"><\/script><br \/>\n<script>\n  var theEmail = null;\n  $(document).ready(function(){\n    $('#email-me-btn').click(function(){\n      theEmail = $('#email-me-email').val();\n      sendEmail(theEmail);\n    });\n    $(\"#email-me-email\").keypress(function(e) {\n      if(e.which == 13) {\n        theEmail = $('#email-me-email').val();        \n        sendEmail(theEmail);\n      }\n    });\n    $('#email-me-btn2').click(function(){\n      theEmail = $('#email-me-email2').val();\n      sendEmail(theEmail);\n    });\n    $(\"#email-me-email2\").keypress(function(e) {\n      if(e.which == 13) {\n        theEmail = $('#email-me-email2').val();        \n        sendEmail(theEmail);\n      }\n    });\n  });\n  var sendEmail = function(emailAddr){\n    if(!emailAddr || emailAddr.length < 12){\n      alert('Please enter an email');\n      return;\n    }\n    $('#email-me-email').val('sending...');\n    $('#email-me-email2').val('sending...');\n    $.ajax({\n      url: \"https:\/\/freshinbox.com\/examples\/add-to-cart\/mail_example.php\",\n      data: {\n        email: emailAddr\n      },\n      success: function( data ) {\n        if(data == null || data.indexOf(\"ERROR\") != -1){\n          alert(\"There was a problem sending the email \\n\"+data);\n        }else{\n          alert(\"An email has been sent to \"+emailAddr+\"!\\n (Be sure to check the spam folder just in case)\");          \n        }\n        $('#email-me-email').val('');\n        $('#email-me-email2').val('');\n      }\n    });\n  }\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example shows how you can create an interactive carousel in email that leverages the power of form support to add products to a shopping cart&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1488,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,24,25],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1195"}],"collection":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/comments?post=1195"}],"version-history":[{"count":71,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1195\/revisions"}],"predecessor-version":[{"id":2218,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1195\/revisions\/2218"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/1488"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=1195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=1195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=1195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}