Main Menu

Contact Andrew Quinn

jaquinn@ihug.co.nz http://twitter.com/jaquinn
fishpond.co.nz integration
Written by Administrator   
Sunday, 15 February 2009 09:52

My RailTrack web site has been a lot of fun to develop but I really need to find a way to cover at least some of the hosting costs.

Tried adding Amazon links to books relevant to the topic (trains!) and while I did get a few clicks through it wasn't wildly successful. 

I think there are two issues here:

  • The rapidly declining New Zealand dollar makes everything from the US particularly expensive.... and then there are the Amazon freight charges!
  • The Amazon generated links didn't seem to change very often so there wasn't a lot to draw users through.

Not much I can do about the dollar and I am sure I could sort out the second one by managing the section of product myself.... but instead I am going to try out fishpond

To keep the customers happy they seem to have a good product range at reasonable NZ$ prices and shipping is affordable.

To keep me happy they provide a downloadable XML feed for selected product categories so I can load this and use it as the basis for selecting products for the site.

RailTrack is based on Rails (it is a web site on trains.... what else would you expect) so hpricot came to the rescue for the XML parsing.... sure the requirements weren't that challenging but the gem is so nice to use..... 

Fishpond catalog records look like:


    <PRODUCT NUM="3575385">
    <ATTRIBUTE1><![CDATA[Engine Drivers Manual: How to Prepare, Fire and Drive a Steam Lo]]></ATTRIBUTE1>
    <author><![CDATA[ Topping, Brian]]></author>
    <isbn>0860935396</isbn>
    <PRODUCT_URL><![CDATA[http://www.fishpond.co.nz/Books/Nonfiction/Transport/Railroads/General/product_info/3575385/?ref=1402]]></PRODUCT_URL>
    <IMAGE>http://image.fishpond.co.nz/9780860935391.jpg</IMAGE>
    <SHIPMENT_COST>4.95</SHIPMENT_COST>
    <RRP>$72.99</RRP>
    <PRICE>$70.48</PRICE>
    <CURRENCY>NZD</CURRENCY>
    </PRODUCT>

 

 

and the model import method looks like:


    def self.import(sourcefile)
        doc = open(sourcefile) { |f| Hpricot(f) }
        (doc/"products/product").each do |book|
            mi = Merchandise.find_by_vendor_product(book.attributes['num'])
            if mi.nil?
                mi = Merchandise.new
            end
            mi.vendor_product = book.attributes["num"]
            mi.isbn = book.at("isbn").inner_text
            mi.title = book.at("attribute1").inner_text
            mi.author = book.at("author").inner_text
            mi.vendor_url = book.at("product_url").inner_text
            mi.vendor_image = book.at("image").inner_text
            mi.rrp = book.at("rrp").inner_text.to_s.sub!("$","")
            mi.vendor_price = book.at("price").inner_text.to_s.sub!("$","")
            mi.vendor_shipping = book.at("shipment_cost").inner_text
            mi.vendor_currency = book.at("currency").inner_text
            puts mi.isbn
            mi.save
        end
    end