0
votes

I'm working with a client to develop two sites: a site with general information about their business, and a separate e-commerce store to sell the products they offer. To my knowledge, this is a fairly common approach, since often a client's CMS needs are outside the scope of what most e-commerce platforms offer.

The main site will need to show some of the products in the store, so I'm looking for e-commerce platforms that have an API. Shopify caught my eye since it has APIs which return JSON. I'm going to be building the main site with Backbone.js with a Sinatra backend.

Can anyone tell me if the Shopify API can be used this way? I also see a somewhat flimsy and uncustomizable Shopify app called Shopify Widget, which I don't think will serve my client's purposes. How would you handle this situation?

2

2 Answers

1
votes

You'll have to use the sinatra app as a proxy to the Shopify store since cross-domain calls via Javascript won't work.

You can use the ShopifyAPI gem to do most of your heavy lifting and if you really wanted you could write up a ghetto RestAPI in Sinatra so you aren't re-inventing the Shopify wheel.

It could be something simple like:

POST /shopify.json
{
  "model": "ShopifyAPI::Product",
  "data": { ..shop data... }
}

And you can probably use const_get to retrieve the actual model you would need.

1
votes

If you are using Sinatra as a backend, you can indeed do cross-domain Ajax calls. I do it all the time. Simply use Rack-Cors gem, if you want to use CORS. If you're squeamish about that due to IE having problems doing CORS, you can always return JSONP as a substitute. If your Sinatra backend runs on a subdomain, you can do whatever since there is no cross-domain issue.