4

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

http://api.shopify.com/

我可以通过这个 API 调用获取产品和库存:

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

但是,然后我想“添加到购物篮” - 我无法从 API 文档中看到如何执行此操作。添加到购物篮后 - 我想获取购物篮内容,以便显示类似...

"2 items : £130 - checkout"

我不需要详细的答案 - 只需指出正确的方向 - 谢谢。

4

1 回答 1

8

Shopify 后端对个人用户购物车一无所知,它们只存在于浏览器领域。我的错误,后端确实知道购物车,但您不能通过 REST API 编辑它们。如果您对获取 carts 感兴趣,这里是 Cart 端点

操作用户的购物车,您需要使用店面中的Ajax API。具体来说,此调用会将产品添加到购物车:

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
}

您可以使用以下调用获取购物车本身:

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
}
于 2012-02-09T21:08:32.783 回答