Shopify API - 添加到购物篮

时间:2012-02-09 14:58:34

标签: php paypal shopify

我想用Shopify来管理我的店铺。我需要使用API​​将产品添加到网站。

http://api.shopify.com/

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

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

但是,我想加入购物篮' - 我无法从API文档中看到如何执行此操作。 一旦添加到篮子里 - 我想获得篮子内容,所以我可以显示类似......

"2 items : £130 - checkout"

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

1 个答案:

答案 0 :(得分: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:

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