2012-02-09 224 views
4

我正在考虑使用Shopify来管理我的商店。我需要使用API​​将产品添加到网站。Shopify API - 加入购物车

http://api.shopify.com/

我能得到的产品和库存与此API调用:

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

但是,后来我想“添加到购物篮” - 我无法从API文档看这个怎么做。 一旦添加到购物篮 - 我想获得购物篮内容,所以我可以显示像...

"2 items : £130 - checkout" 

我并不需要一个详细的答案 - 只是点我朝着正确的方向 - 感谢。

回答

8

Shopify后端对个人用户购物车一无所知,它们只存在于浏览器域中。我的错误,后端了解购物车,但您无法通过REST API编辑它们。 Here's the Cart endpoint if you're interested in getting carts

若要操纵用户的购物车,您需要使用店面中的Ajax API。具体来说,this call将产品添加到购物车:

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

返回的JSON看起来是这样的:

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

{ 
    "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 
} 

您可以使用following call拿到车本身这会得到你这个:

{ 
    "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 
} 
+0

谢谢大卫。完善。 – Boz 2012-02-10 18:00:30

+1

您好,先生,有可能通过API将自定义添加到购物车吗?比如说,如果我想将自定义名称,自定义描述和自定义价格放入没有ID的购物车中?先生非常感谢您。 – 2014-11-17 02:21:49