freakdesign / Shopify-code-snippets

Shopify code examples and tips

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can’t get Shopify cart via jsonp crossdomain anymore

oscarni opened this issue · comments

commented

I’m using “Get Shopify cart data with JSONP“. Since a couple of days ago the request returns empty carts. Anyone else experiencing the same?

I make sure the Shopify store has items in the cart, but when getting the cart via Jsonp from another domain the cart response is without any cart items. Did Shopify change it’s api in some way?

Interesting. It's possible that JSONP is no longer accepted but would have to look into it.
Do you have some replication steps/code used so I can give it a test using the same process?

commented

To test I'm running your script in the console. I get the response from shopify, it's just without any items which I can see are in the cart when I visit the shop.

This could be far fetched, but I think I've figured it out. It looks like it works when I have https setup and only when i'm running the script from the same main domain. So it works when I run it on a subdomain of the main shopify store. But cross-domain with a totally different domain doesn't look like it works anymore. Could be related to chrome setting same-site: lax as default on cookies or some other cookie restriction shopify has limiting the session to only be available on the main domain.

Edit: I can confirm that it get the correct cart when request is made from a subdomain of the same main Shopify domain and over ssl. To test locally i suggest running your local server over https (adding certificates was a pain) and adding a testing subdomain.maindomain to your hosts file.

Looks like @oscarni is correct about the cookies. My shop is on a subdomain, so I'm able to set my own cookie that is usable by both domains.