-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using cartjs on a custom site? #20
Comments
Hi @dhstack! Thanks for the kind words :). Am I right in understanding that you're trying to use Cart.js to add to a Shopify cart from a site that's not hosted on Shopify? If so, that's not really a use case Cart.js supports, but I guess you may be able to initialise Cart.js with a cart-like object. Here's what an empty cart looks like when rendered by Liquid's
Does that help? If you do get this working, let me know as it's an interesting use case that I'll add to the docs. |
Yes, that is correct. Trying to use Cart.js on a site not hosted by Shopify. Still working on it, but I had a thought... Have you considered passing a Then simply have a basic conditional check within
And you wouldn't need the note about the cart object being required, just optional. Nice and simple :) PS Just discovered this trick: use |
So it doesn't look like this is going to work. Not because of a limitation with CartJS, but because Shopify doesn't support CORS The exact error I am getting on the Chrome Developer tools console is:
EDIT: Looks like Shopify does actually have JSONP support. Will likely need to modify core.coffee and/or queue.coffee for this to work, but it may only allow using GET requests (no adding to cart). But it's better than nothing. Will try adapting this code. |
Ah, that CORS restriction is limiting. Thanks for digging in to this. I take your idea/point about allowing the cart to be optionally So, please feel free to report back your findings here. If you publish them somewhere like a blog, then I'd love to link to them from within the Cart.js docs. Otherwise, I'm going to close this issue as I don't think off-Shopify site support will be a priority moving forward. Thanks! |
Yeah, at this point adding remote site support doesn't seem like it will work with CartJS (which is too bad since it looks so easy to use). Perhaps if/when Shopify adds CORS this issue can be revisited. Until then JSONP can be used for displaying cart contents, but not updating them as JSONP supports only the GET request method. To update it would be best to use the methods Shopify describes. |
First off, cartjs looks incredibly helpful for creating ajax carts with Shopify. Keep up the great work!
I'd like to use it on my custom bootstrap site, but am not sure how to initialize it properly.
In the cartjs documentation (which is great by the way) it says under configuration to call
CartJS.init()
and pass a liquid cart object as JSON. As I'm not using liquid, how can I create a liquid-cart-like JSON object and pass it to cartjs?The only other related documentation I've found so far that might help is about Adding to cart from a remote website.
The text was updated successfully, but these errors were encountered: