php - Shopify API - 添加到购物车

标签 php paypal shopify

我正在考虑使用 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/

相关文章:

php - 警告:mysql_fetch_assoc()期望参数1为资源, bool 值在[duplicate]中给出

php(或python)监听unix域流套接字

php - 无法使用动态创建位置的 file_get_contents

php - Paypal api 将产品插入数组

paypal - Authorize.Net 上的 IPN(即时付款通知)就像 Paypal 一样

jquery - Fancybox 弹出窗口和 cookie 不起作用

PHP:如何处理 SQL 返回值?

xml - 如何将 BN 代码与 XML Pay 集成? ( Paypal 支付流专业版)

shopify - 如何获取 Shopify 商店的所有产品?

php - Shopify - 通过多个变体 ID 检索多个变体详细信息