使用Shopify使用特定于客户的商品/产品创建购物车

时间:2020-10-01 11:12:20

标签: cart shopify-api shopify-storefront-api

Am使用Shopify开发用于购买和销售产品的本地应用程序。 要使用Ajax API并传递产品的变体ID来创建购物车,但我需要区分并为每个用户创建单独的购物车。

当前,如果我使用以下API调用将产品添加到购物车中,那么即使其他客户/用户也可以看到其他用户之前添加到购物车的产品。 谁能帮助我解决这个问题或提出建议吗?

用于创建购物车的方法:

  addtoCart = () => {
    var that = this;   
    var variantId = this.state.artworkdescription.ID;(***product ID***)
    var data = 'id=' + variantId + '&quantity=1'
    console.log("data",data);
    //POST request 
    fetch('https://lonelywalls.myshopify.com/cart/add.js', {
        method: "POST",//Request Type 
        body: data,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'x-shopify-access-token': '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',
        },
    })
        .then((response) => response.json())
        .then((responseJson) => {
            console.log("Cart Response", responseJson);
        })
        //If response is not in json then in error
        .catch((error) => {
            console.log(error);
        });
}

0 个答案:

没有答案