我正在考虑使用 Shopify 来管理我的商店。我需要使用 API 将产品添加到网站。
我可以通过这个 API 调用获取产品和库存:
http://api.shopify.com/product.html#index
但是,我想“添加到购物篮”- 我无法从 API 文档中看到如何执行此操作。 添加到购物篮后 - 我想获取购物篮中的内容,这样我就可以显示类似...
"2 items : £130 - checkout"
我不需要详细的答案 - 只需指出正确的方向 - 谢谢。
最佳答案
Shopify 后端对个人用户购物车一无所知,它们只存在于浏览器领域。 我的错误是,后端确实知道购物车,但您不能通过 REST 编辑它们应用程序接口(interface)。 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 看起来像这样:
{
"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 获取购物车本身:
http://store.myshopify.com/cart.js
这会让你得到这个:
{
"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
}
关于php - Shopify API - 添加到购物车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9213173/