【问题标题】:Shopify API - add to basketShopify API - 添加到购物篮
【发布时间】:2012-03-02 01:26:30
【问题描述】:

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

http://api.shopify.com/

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

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

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

"2 items : £130 - checkout"

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

【问题讨论】:

    标签: php paypal shopify


    【解决方案1】:

    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
    }
    

    【讨论】:

    • 您好先生,是否可以通过 API 将自定义内容添加到购物车中?比如如果我想在没有 id 的情况下将自定义名称、自定义描述和自定义价格放入购物车?非常感谢先生。
    猜你喜欢
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    相关资源
    最近更新 更多