gpt4 book ai didi

php - Shopify API - 添加到购物车

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:09:43 24 4
gpt4 key购买 nike

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

http://api.shopify.com/

我可以通过这个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com