The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
3. Create a user control called AmazonItemLookUp.ascx and use the code below:
AmazonItemLookUp.ascx
<h2>Insert ASIN</h2> |
<asp:TextBox ID="ItemIDTextBox" runat="server" MaxLength="10"></asp:TextBox> |
<br /> |
<asp:Button ID="btnSubmit" runat="server" Text="Submit" |
onclick="btnSubmit_Click" /> |
<br /> |
<br /> |
<asp:Repeater ID="Repeater1" runat="server"> |
<ItemTemplate> |
<asp:Image ID="SmallImage" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "MediumProductImageURL") %>' /> |
<br /> |
<asp:Label ID="ASIN" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ASIN") %>' Visible="false"></asp:Label> |
<br /> |
<i><asp:Label ID="ProductNameLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ProductName") %>'></asp:Label></i> |
<br /> |
<b><asp:Label ID="ProductPriceLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ProductPrice") %>'></asp:Label> |
</b> |
<br /> |
<asp:HyperLink ID="DetailPageURLHyperLink" runat="server" Text="Buy this Product!" Target="_blank" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "DetailPageURL") %>'></asp:HyperLink> |
</ItemTemplate> |
</asp:Repeater> |
AmazonItemLookUp.ascx.cs
protected void btnSubmit_Click(object sender, EventArgs e) |
{ |
Amazon a = new Amazon(); |
//Insert AwsAccessKeyId below |
a.AwsAccessKeyId = "xxxxxxxxxxxx"; |
a.ItemId = ItemIDTextBox.Text; |
Repeater1.DataSource = a.PopulateAmazonList(); |
Repeater1.DataBind(); |
} |
4. Create a class called Amazon in your App_Code folder and insert the code below:
using System.Linq; |
using System.Collections; |
using System.Xml.Linq; |
/// <summary> |
/// Summary description for Amazon |
/// </summary> |
public class Amazon |
{ |
public string GetURL() |
{ |
return "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=" + AwsAccessKeyId + "&Version=2009-03-31&Operation=ItemLookup&ResponseGroup=Request,SalesRank,Small,Images,OfferSummary&ItemId=" + ItemId; |
} |
private string _AwsAccessKeyId; |
public string AwsAccessKeyId |
{ |
get |
{ |
return _AwsAccessKeyId; |
} |
set |
{ |
_AwsAccessKeyId = value; |
} |
} |
private string _ItemId; |
public string ItemId |
{ |
get |
{ |
return _ItemId; |
} |
set |
{ |
_ItemId = value; |
} |
} |
/// <summary> |
/// Gets namespace needed for Amazon.com recommendations |
/// </summary> |
public static XNamespace ns |
{ |
get |
{ |
return "http://webservices.amazon.com/AWSECommerceService/2009-03-31"; |
} |
} |
/// <summary> |
/// Populates a list of product recommendations from Amazon.com |
/// </summary> |
/// <param name="list2"></param> |
public IList PopulateAmazonList() |
{ |
XElement tags = XElement.Load(GetURL()); |
var groups = from book in tags.Descendants(ns + "Item") // Return all nodes with the word "Item" in it |
let bookAttributes = book.Element(ns + "ItemAttributes") //In each Item node, get the "ItemAttributes" node |
let offerAttributes = book.Element(ns + "OfferSummary") //Get the Offer Summary Node |
let mediumImageAttributes = book.Element(ns + "MediumImage") |
let lowestNewPrice = offerAttributes.Element(ns + "LowestNewPrice") //Within the Offer Summary Node, get the Lowest New Price node |
select new |
{ |
ASIN = ((string)book.Element(ns + "ASIN")), |
ProductName = ((string)bookAttributes.Element(ns + "Title")), |
MediumProductImageURL = ((string)mediumImageAttributes.Element(ns + "URL")), |
DetailPageURL = ((string)book.Element(ns + "DetailPageURL")), |
ProductPrice = ((string)lowestNewPrice.Element(ns + "FormattedPrice")) |
}; |
return groups.ToList(); |
} |
} |
5. Upload the User Control to Sitefinity
6. Inside the text box, insert the ASIN number of the product
7. Click on the link "Buy this Product" ,that appears below, and give it to your customer as shown below:
How it Works
Using a long query string, Amazon returns a large XML file with many attributes for the item. Here is a sample:
To view your URL, place a break point on this code in Amazon.cs:
var Groups
In the URL, you'll notice many properties in the query string and here is an explanation of a few of them:
Operation - This defines what you're seeking to do. In this case, I want to look up a single product. You can also look up a list of products based on other identifying information, like a search index or a tag. Amazon also has many other operations and for more info, please read this article.
Response Groups - These pull certain item attributes into the XML file. If attributes were removed from your query string in response groups, you'd notice that data would be missing in the XML file. For more info on response groups, please read this article.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.