Tuesday, June 19, 2012

Zazzle on Rails

I have merchandise on the Zazzle store.  I also have sites that I manage, and I would like to advertise my merchandise on my sites under my own control.  Zazzle offers a handful of banner options, but I wasn't really finding the level of control that I wanted.  So I've set about writing my own.

Zazzle does offer a PHP front end if you want to host your own store.  However I'm a Rails guy and would much prefer to work in that language.  From what I can tell, there is no Zazzle gem.  Yet.

What they do offer is a simple enough RSS feed that will allow you to easily pull the relevant info on your products, in a variety of ways.  You can customize the call to grab newest items, or most popular, via search terms or by searching for specific product types only.  In my case, and since I have less than 100 items in the store,  I can just go ahead and grab all of them:

@feed = Feedzirra::Feed.fetch_and_parse("http://feed.zazzle.com/ShakespeareGeek/feed?st=date_created&pg=1&ps=100")

You'll get back the item URL, description, and even a pre-made

complete with image that you can just go ahead and drop right on your page, if you like.

Now it's really up to you what you do next.  I actually use this call to go ahead and seed a local database of Product objects, which I'm then tagging and categorizing as I see fit.  Since I know when I create new products, I can manually go in and update my database to stay in sync.

I wrote up a simple banner script for now that just goes in and says "Get me 3 random products," and then I display the supplied HTML that came with the RSS feed.  Later, depending on the context of the page, I'll be able to say "Get me 3 random Hamlet products" or "Get me 3 t-shirts" or possibly even change what and how I'm displaying the items.

Note that the URL takes you back to the product page on Zazzle, where your customer would then still have to hit a Buy button.  Not the greatest user experience, but I'm not trying to rebuild the store from scratch, either.  I just wanted a way to display advertisements for my merchandise in my own way.  Your mileage may vary.

When I have time I hope to expand this with more source code and examples about exactly what I'm doing.  At the moment, though, I have no idea if Google will pick up this post and if anybody will ever see it.  So if you did land here because you do want to connect Zazzle and Rails, leave a comment so I'll know whether to keep posting on the subject.


Mn3MoN1C said...

I'm interested in such a gem. I was thinking of doing one myself since none exist as it is.

star whites said...

Excellent post! I must thank you for this informative read. I hope you will post again soon.Kind regard Heavy Duty Washing Machine Manufacturers