这两个页面应该可以帮助您:
从远程网站添加到购物车
我不确定您现在正在做什么以添加到购物车,但这是“正确”的做法。鉴于您已经完成了这项工作,我不会太担心。
要获取购物车,您应该使用AJAX API。此 API 允许您在不使用您链接到的 REST 版本的情况下为当前用户拉购物车。那个是为进行更重的提升而设计的(例如,获取所有当前活动的推车)。AJAX 版本更简单,专为前端使用而设计。简单来说,只需调用
http://[the-shop].myshopify.com/cart.js
您将以 JSON 格式取回当前会话的购物车内容。它看起来像这样:
{
"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
}