February 02, 2009

Customizing Graffiti: The Amazon aStore Chalk Extension

In my last post, Customizing Graffiti: Chalk GetQuerystringValue, I promised that I was brewing up a really good Graffiti example/tip that would combine a lot of the customizations that I’ve written about recently. Are you ready for this? This one will knock your socks off and it alone is worth the price of admission. It’s the Amazon aStore Chalk extension. No “oohs and ahhs” yet? Pessimists, huh? Just wait.

Historically (if you can call 3 previous posts “historically”) I disclose the what, how, etc. details first and then show an example. This time I’m going to do it a bit differently and tell you the back story behind the creation of the extension, show you an example, and then I’ll provide you with the code and usage details.

What is Amazon aStore?

I’ve looked at Amazon’s aStore offering before, but I never really had a reason to set one up or use one, until now.  The aStore is an Amazon hosted, personally branded ecommerce tool that allows you to sell any of Amazon’s products from your own site.  Notice that I wrote “Amazon hosted”. The Url for your Amazon store will look something like this: http://astore.amazon.com/netbookroundup-20. To include your aStore as part of your own site Amazon suggests that you either link directly to it, embed it in an IFrame in your site, or include it in your site using frames (pictures courtesy of the Amazon Associates web site):

CropperCapture[140]  CropperCapture[139] CropperCapture[138]

I haven’t built anything with framesets in years and I wanted to make the store look as much a natural part of the site as possible so I took the IFrame route. Amazon suggests using the below code for your IFrame markup:

   1:  <iframe src="http://astore.amazon.com/netbookroundup-20" 
   2:          width="90%" height="4000" frameborder="0" 
   3:          scrolling="no"></iframe>

To me that looked like something I should create a Graffiti Chalk extension for, so that is exactly what I did!


The Story

NetbookRoundup.com is a site that I decided to put together over the holidays. I really wanted to get one of the new handy little laptops but I couldn’t make up my mind which make or model to get. I also had trouble keeping track of the current prices and sales/deals. I decided I could probably put together a nice little Graffiti site where I could do all that and then some. Plus the term “netbook” is still fairly new so I thought I might be able to find a few good domain names still available and stash them away as an investment. I’ll post more details about the Netbook Roundup site soon, but one of the things I decided to include was my a own online store with the help of Amazon aStore.

Below is a screenshot of what the NetbookRoundup integrated aStore looks like when you click on the “Shop” link in the primary navigation. If you want to see it live then here’s the link: http://netbookroundup.com/store/


This is a great start but I also wanted to be able to provide links directly to specific products. For example, on the page where I review the Lenovo Ideapad S10 (http://netbookroundup.com/models/lenovo/ideapad-s10/) I want to have a link that says “Buy the Lenovo Ideapad S10 in the Netbook Roundup Store” and have that link directly to that product’s page in the aStore. 


By reviewing the structure of the aStore site I was able to determine that the Url for a specific product followed the pattern: http://astore.amazon.com/yourstoreid/detail/ASID, where ASID is the Amazon product id. So all I had to do was figure out how to get that product id into the Iframe’s src tag. I could have used some javascript but I instead opted to just include the ASID as a querystring key/value paramater in the Graffiti post’s Url. The chalk code checks to see if the ASID is present, if it is then it sets the source of the iframe accordingly, if not then it just uses the base aStore Url. 

Okay, enough story time, here’s the code…


What does this Chalk Extension do?

You use it to display an Amazon aStore as part of your Graffiti site.


The Code

   1:  using Graffiti.Core;
   3:  namespace DanHounshell.Graffiti.Chalk 
   4:  {
   5:     [Chalk("AmazonAStore")]
   6:     public class AmazonAStore 
   7:     {
   8:        public string HTML(string AStoreUrl) 
   9:        {
  10:           return HTML(AStoreUrl, "");
  11:        }
  13:        public string HTML(string AStoreUrl, string ASID) 
  14:        {
  15:           if (!string.IsNullOrEmpty(ASID))
  16:           {
  17:              AStoreUrl += "/detail/" + ASID;
  18:           }
  19:           return string.Format("<iframe src=\"{0}\" 
  20:              width=\"100%\" height=\"4000\" 
  21:              frameborder=\"0\" scrolling=\"no\"></iframe>", 
  22:              AStoreUrl);
  23:        }
  24:     }
  25:  }



Just place the following code into the proper view for wherever you want your aStore displayed in your Graffiti site:

   1:  $AmazonAStore.HTML(
   2:       "http://astore.amazon.com/YourAStoreId")

This will display the aStore homepage like I have pictured in the screenshot above.

For including the aStore in the Netbook Roundup site, I created a new uncategorized post called “Store” and then created a new custom view called store.view, based on post.view. The new view, store.view, is what is displayed when a user is looking at the “Store” post. I then pasted just the AStore chalk markup into that custom view. YMMV – you may have other markup that you want to include in the custom view, I didn’t. The rendered HTML of the aStore is about 800px wide so you might need to consider creating a new custom layout for your post that doesn’t display any sidebars or other items included on your other pages. I’d suggest creating a copy of your layout.view called store.layout.view and stripping out anything you don’t need. If you follow the same setup that I did, don’t forget to create a custom navigation item for your main nav that points to the Url of your store post.

If you want to allow for direct linking to products then you can do something similar to the following and just include “?ASIN=AmazonProductId” in any Urls to your Graffiti store post when you want to link to a specific product (ex: http://netbookroundup.com/store/?ASIN=B001GNBD8I):

   1:  $AmazonAStore.HTML(
   2:            "http://astore.amazon.com/YourAStoreId", 
   3:            $QueryStringHelper.GetQueryStringValue("ASIN"))

Notice the use of the QueryStringHelper.GetQueryStringValue chalk extension in the code above. I told you I’d show you a useful real-world example!

Finally, if you want to store your aStore’s url in your web.config file rather than hard code it into the view you can use the ConfigurationAppSettings.GetAppSetting chalk extension:

   1:  $AmazonAStore.HTML(
   2:       $ConfigurationAppSettings.GetAppSetting("Amazon.AStoreUrl"),
   3:       $QueryStringHelper.GetQueryStringValue("ASIN"))



Of course you could just hard-code the Amazon aStore IFrame HTML code into a Graffiti post and instantly add a store to your Graffiti site, but what fun is that?!?! Also, you won’t get the ability to link directly to a product page without adding some of your own NVelocity markup.

Not everyone can (or should) use an Amazon aStore in their Graffiti site. It doesn’t make sense for my personal blog and it probably doesn’t make sense for yours either. But if you have a product-based blog, do software reviews, or even a lot of book reviews then including a store in your site might be fun and maybe even put a few extra dollars in your pocket. 

In future posts I'll discuss some of the other Graffiti custom widgets and chalk extensions that created for the Netbook Roundup site, including displaying ebay auctions that match the content (which I've discussed in the past for a different Graffiti site), writing chalk extension that pulls data from various web services to provide price comparison shopping links, and more. See the MSI Wind page on the Netbook Roundup site for examples of ebay and price comparisons. Notice the "Buy the MSI Wind U100 in the Netbook Roundup Store" link? That's something that you can do now, too! 

I hope you find this Graffiti Chalk extension tip useful. Please leave a comment if you have any suggestions or questions.


  • Trackbacks,
  • and Pingbacks
  1.  avatar Sergey Yurov says:

    Like you I tried to solve the same Amazon aStore problems but on server side. Like you I decided to share solution with community. Result is www.storebrander.com Amazon aStore SEO proxy Storebrander.com&. With storebrander.com you can apply own HTML template to aStore, assign it own domain/subdomain, use various google services, add custom head tags, etc. Please take a look. It could be interesting for you.

  2.  avatar Mao says:

    Hi Dan,

    Can you be more specific...i want to target directly a product from my astore (staying inside my website). I am using wordpress ...can i do this? And what code i need to insert and where?

    Best regards!

  3.  avatar Nick says:


    Nice post!  Have you also written something about how you have a price compare section on your blog?  I couldn't find it after browsing a bit...


  4. Good question, Nick. No I have not written how I implemented that functionality yet because it's a long story and I don't know how it ends yet :). On one end it is a custom data collector that aggregates data from several different vendors by importing data from several web services and csv files on merchant FTP sites and storing it locally. Then in the middle is a little search engine built on top of that data.

    However, on the Graffiti site it involves nothing more than using a custom property and a fairly simple Chalk extension. For the custom property I just define the "search term" that I want to use when querying for the price data. In the case of this page: netbookroundup.com/.../neutrino-oczdiy10n1 it is "OCZ neutrino". Then I just have a Chalk extension that queries my custom search engine's web service with that term, pulls back the top X results and displays them.

    As I said, I'm using a custom web service to search for products, but there is no reason you can't do the same thing with just Ebay, or Amazon, or Commission Junction, or even Netflix for that matter.

    Happy hacking!

Comments are closed.


Trackbacks and Pingbacks

  1. TrackBack says:

Where is Dan?

My Blog
My Blog
Windows Live
Windows Live
Graffiti CMS on CodePlex
Graffiti CMS

Recent Posts