Shopify API - Add to Cart

I am thinking of using Shopify to manage my store. I need to add products to the site using the API.

http://api.shopify.com/

I can get products and promotions using this API call:

http://api.shopify.com/product.html#index

But, then I would like to "Add to Cart" - I don’t see the API documents how to do this. After adding to the basket - I would like to get the contents of the basket so that I can display something like ...

"2 items : Β£130 - checkout" 

I don't need a detailed answer - just point me in the right direction - thanks.

+4
source share
1 answer

The Shopify database does not know anything about individual user carts; they exist only in the browser area. My mistake, the backend knows about carts, but you cannot edit them through the REST API. Here's the end point of Cart if you're interested in getting trolleys .

To manipulate a custom cart, you need to use the Ajax API from the storefront. In particular, this call will add products to the cart:

 http://store.myshopify.com/cart.add.js?quantity=2&id=30104012 

which returns json that looks something like this:

 { "handle": "amelia", "line_price": 4000, "requires_shipping": true, "price": 2000, "title": "amelia - medium", "url": "/products/amelia", "quantity": 2, "id": 30104012, "grams": 200, "sku": "", "vendor": "the candi factory", "image": "http://static.shopify.com/s/files/1/0040/7092/products/2766315_da1b.png?1268045506", "variant_id": 30104012 } 

You can get the cart yourself using the following call :

 http://store.myshopify.com/cart.js 

What do you get:

 { "items": [ { "handle": "aquarius", "line_price": 6000, "requires_shipping": true, "price": 2000, "title": "aquarius - medium", "url": "/products/aquarius", "quantity": 3, "id": 30104042, "grams": 181, "sku": "", "vendor": "the candi factory", "image": "http://static.shopify.com/s/files/1/0040/7092/products/aquarius_1.gif?1268045506", "variant_id": 30104042 }, { "handle": "amelia", "line_price": 4000, "requires_shipping": true, "price": 2000, "title": "amelia - medium", "url": "/products/amelia", "quantity": 2, "id": 30104012, "grams": 200, "sku": "", "vendor": "the candi factory", "image": "http://static.shopify.com/s/files/1/0040/7092/products/2766315_da1b.png?1268045506", "variant_id": 30104012 } ], "requires_shipping": true, "total_price": 10000, "attributes": null, "item_count": 5, "note": null, "total_weight": 947 } 
+8
source

Source: https://habr.com/ru/post/1395616/


All Articles