Listing 1: Run Amazon search and return results:

<cfif isDefined("form.search")>
<!--- Submit REST query --->
<cfhttp url="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&
AWSAccessKeyId=#REPLACE_WITH_YOUR_KEY#&Operation=ItemSearch&Keywords=#form.keywords#
&SearchIndex=DVD&Sort=relevancerank&ResponseGroup=Small,ItemAttributes,Images,Offers"
throwOnError="yes" charset="UTF-8"></cfhttp>
<!--- parse XML document --->
<cfset myXMLdoc = XmlParse(cfhttp.filecontent)>
<CFSET xnSearch = myXMLdoc.xmlRoot>

<cfoutput>
<!--- if results LT 10, loop through those, otherwise show first 10 --->
<cfloop index="i" from="1" to="#IIF(xnSearch.Items.TotalResults.XMLText gt
 10,'10',xnSearch.Items.TotalResults.XMLText)#">

<!--- add cftry/cfcatch in case no image or other error // we'll use UPC as div id --->
<cfif xnSearch.Items.Item[i].Offers.TotalOffers.XmlText gt 0>
<div style="font-size:10px;font-family:Arial;text-align:center;
 background-color:##eee;float:left;margin:10px; border:1px solid ##666; padding:5px;"
 id="#xnSearch.Items.Item[i].ItemAttributes.UPC.XmlText#">
<img src="#xnSearch.Items.Item[i].MediumImage.URL.XmlText#"><br />
#xnSearch.Items.Item[i].ItemAttributes.Title.XmlText#<br />
#xnSearch.Items.Item[i].ItemAttributes.UPC.XmlText#     
#xnSearch.Items.Item[i].ItemAttributes.ListPrice.FormattedPrice.XmlText#
</div>

	<!--- make this item draggable // reference by UPC as div id --->
<script type="text/javascript">
new Draggable('#xnSearch.Items.Item[i].ItemAttributes.UPC.XmlText#', {revert:true});
</script>
</cfif>
</cfloop>
</cfoutput>
<br clear="all" />
</cfif>

Listing 2:

function cartPacket_onReceive(packet) { // generates an HTML table of cart items

	var theTable = document.getElementById('tableCart');
	var tbody = document.createElement("tbody");
	var tr, td;

	if ( packet.upc.length == 0 ) { // if no results just send back empty cart
		tr = document.createElement("tr");
		td = document.createElement("td");
		td.colSpan = 4;
		td.innerHTML = "Your cart is empty.";
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	else
		for ( var i = 0 ; i < packet.upc.length; i++ ) { // loop and create new row
			tr = document.createElement("tr");
			td = document.createElement("td");
			td.innerHTML = packet.qty[i];
			tr.appendChild(td);
			td = document.createElement("td");
			td.innerHTML = '<img src="' + packet.image[i] + '">';
			tr.appendChild(td);
			td = document.createElement("td");
			td.innerHTML = packet.title[i];
			tr.appendChild(td);
			td = document.createElement("td");
			td.innerHTML = packet.price[i];
			tr.appendChild(td);
			tbody.appendChild(tr);
		}

	theTable.replaceChild(tbody, theTable.childNodes[1]);
}

Listing 3: cart.cfm gateway page:

<cfswitch expression="#action#">

<cfcase value="getCart">
	<cfparam name="session.cart" default="#ArrayNew(1)#">
	<cfset cartQuery = QueryNew("qty,upc,title,image,price")>
	<cfloop from="1" to="#ArrayLen(session.cart)#" index="i">
		<cfset queryAddRow(cartQuery)>
		<cfset querySetCell(cartQuery, "qty", session.cart[i].qty, i)>
		<cfset querySetCell(cartQuery, "upc", session.cart[i].upc, i)>
		<cfset querySetCell(cartQuery, "title", session.cart[i].title, i)>
		<cfset querySetCell(cartQuery, "image", session.cart[i].image, i)>
		<cfset querySetCell(cartQuery, "price", session.cart[i].price, i)>
	</cfloop>
<cfset request.response = cartQuery>
</cfcase>

<cfcase value="addToCart">
<cfparam name="session.cart" default="#ArrayNew(1)#">

<!--- get items from Amazon Web Services -
<cfhttp url="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&
AWSAccessKeyId=1MEQ9VMKAJS5A8DSHER2&Operation=ItemLookup&IdType=UPC&SearchIndex=DVD
&ItemId=#url.upc#&ResponseGroup=Small,ItemAttributes,Images" throwOnError="yes"
 charset="UTF-8"></cfhttp>
<cfset myXMLdoc = XmlParse(cfhttp.filecontent)>
<CFSET xnProduct = myXMLdoc.xmlRoot>
<cfscript>
addItem = StructNew();
addItem.qty = 1;
addItem.upc = xnProduct.Items.Item.ItemAttributes.UPC.XmlText;
addItem.title = xnProduct.Items.Item.ItemAttributes.Title.XmlText;
	addItem.image = xnProduct.Items.Item.SmallImage.URL.XmlText;
	addItem.price = xnProduct.Items.Item.ItemAttributes.ListPrice.FormattedPrice.XmlText;
</cfscript>
<cfset ArrayAppend(session.cart,addItem)>

<!--- return cart --->
<cfset cartQuery = QueryNew("qty,upc,title,image,price")>
<cfloop from="1" to="#ArrayLen(session.cart)#" index="i">
		<cfset queryAddRow(cartQuery)>
		<cfset querySetCell(cartQuery, "qty", session.cart[i].qty, i)>
		<cfset querySetCell(cartQuery, "upc", session.cart[i].upc, i)>
		<cfset querySetCell(cartQuery, "title", session.cart[i].title, i)>
		<cfset querySetCell(cartQuery, "image", session.cart[i].image, i)>
		<cfset querySetCell(cartQuery, "price", session.cart[i].price, i)>
</cfloop>
<cfset request.response = cartQuery>
</cfcase>

<cfcase value="clearCart">
	<cfset ArrayClear(session.cart)>
	<cfset cartQuery = QueryNew("qty,upc,title,image,price")>
	<cfset request.response = cartQuery>
</cfcase>

</cfswitch>