New Shopify Certification now available: Liquid Storefronts for Theme Developers

/cart.json object empty

Solved
lenafuchs
Shopify Partner
11 0 0

Hi! I'm trying to get my shopify cart object from an external website. This is the code I'm using:

 

$.ajax({
type: 'GET',
url: 'https://*domain*/cart.json',
dataType: 'jsonp',
success: function(data) {
console.log(data);
}
});

 

but as a response I only get an empty cart with item count 0.

 

But when I open up https://*domain*/cart.json in my browser it works correctly and the cart object is filled with the right products. Also, when I open up https://*domain*/cart I can see the products in the cart.

 

Any idea why it doesn't work via get request and how to fix this?

Thanks!

Accepted Solution (1)
iDoThemes
Trailblazer
207 43 91

This is an accepted solution.

The cart is tied to a cookie, as a matter of security you won't be able to get the cart contents from an external domain.

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line

View solution in original post

Replies 2 (2)
iDoThemes
Trailblazer
207 43 91

This is an accepted solution.

The cart is tied to a cookie, as a matter of security you won't be able to get the cart contents from an external domain.

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line
lenafuchs
Shopify Partner
11 0 0

Hi @iDoThemes I'm pretty sure it has to be possible since i did read about that topic in many different forums e.g. http://code.tiffbits.com/shopify-displaying-cart-items-on-remote-website-with-ajax-json/ - but I can't figure out why it's working in others codes but not in mine. 

Do you think this way might work if the external domain was a subdomain from the shopify domain?