1

我在我的页面上使用 Shopify 的购买按钮,我对此非常满意,但我需要添加创建“添加商品”的功能 - 这意味着当客户点击商品上的商品详细信息时,商品提供了该功能有一个附加项目。

很像这个插件:https ://spice-addons-demo.myshopify.com/collections/frontpage/products/the-sg-gems-necklace (我已经尝试实现它,没有运气)

如何使用购买按钮做到这一点?(此处的文档:http: //shopify.github.io/buy-button-js/,我尝试对其进行修改,但没有真正的运气)

这是我的代码:

/*<![CDATA[*/
(function () {
  var scriptURL = 'js/buy-button-storefront.min.js';
  if (window.ShopifyBuy) {
    if (window.ShopifyBuy.UI) {
      ShopifyBuyInit();
    } else {
      loadScript();
    }
  } else {
    loadScript();
  }
  function loadScript() {
    var script = document.createElement('script');
    script.async = true;
    script.src = scriptURL;
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
    script.onload = ShopifyBuyInit;
  }
  function ShopifyBuyInit() {
    var client = ShopifyBuy.buildClient({
      domain: 'xxx',
      storefrontAccessToken: 'xxx',
    });
    ShopifyBuy.UI.onReady(client).then(function (ui) {
      ui.createComponent('collection', {
        id: '230096961724',
        node: document.getElementById('xxx'),
        moneyFormat: '%24%7B%7Bamount%7D%7D',
        options: {
  "product": {   
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "calc(33.33333% - 30px)",
          "margin-left": "30px",
          "margin-bottom": "50px",
          "width": "calc(33.33333% - 30px)"
        },
        "img": {
          "height": "calc(100% - 15px)",
          "position": "absolute",
          "left": "0",
          "right": "0",
          "top": "0"
        },
        "imgWrapper": {
          "padding-top": "calc(75% + 15px)",
          "position": "relative",
          "height": "0"
        }
      },
      "button": {
        "font-weight": "bold",
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px",
        ":hover": {
          "background-color": "#8b1a23"
        },
        "background-color": "#ca0027",
        ":focus": {
          "background-color": "#8b1a23"
        },
        "border-radius": "7px",
        "padding-left": "100px",
        "padding-right": "100px"
      },
      "quantityInput": {
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px"
      }
    },
    "buttonDestination": "modal",
    "contents": {
      "options": false
    },
    "text": {
      "button": "View product"
    }
  },
  "productSet": {
    "styles": {
      "products": {
        "@media (min-width: 601px)": {
          "margin-left": "-30px"
        }
      }
    }
  },
  "modalProduct": {
    "contents": {
      "img": false,
      "imgWithCarousel": true,
      "button": false,
      "buttonWithQuantity": true
    },
    "styles": {
      "product": {
        "@media (min-width: 601px)": {
          "max-width": "100%",
          "margin-left": "0px",
          "margin-bottom": "0px"
        }
      },
      "button": {
        "font-weight": "bold",
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px",
        ":hover": {
          "background-color": "#8b1a23"
        },
        "background-color": "#ca0027",
        ":focus": {
          "background-color": "#8b1a23"
        },
        "border-radius": "7px",
        "padding-left": "100px",
        "padding-right": "100px"
      },
      "quantityInput": {
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px"
      }
    },
    "text": {
      "button": "Add to cart"
    }
  },
  "cart": {
    "styles": {
      "button": {
        "font-weight": "bold",
        "font-size": "18px",
        "padding-top": "17px",
        "padding-bottom": "17px",
        ":hover": {
          "background-color": "#8b1a23"
        },
        "background-color": "#ca0027",
        ":focus": {
          "background-color": "#8b1a23"
        },
        "border-radius": "7px"
      }
    },
    "text": {
      "total": "Subtotal",
      "button": "Checkout"
    },
    "popup": false
  },
  "toggle": {
    "styles": {
      "toggle": {
        "font-weight": "bold",
        "background-color": "#ca0027",
        ":hover": {
          "background-color": "#8b1a23"
        },
        ":focus": {
          "background-color": "#8b1a23"
        }
      },
      "count": {
        "font-size": "18px"
      }
    }
  }
},
      });
    });
  }
})();
/*]]>*/
4

1 回答 1

0

购买按钮不可自定义。它代表您的客户可以购买的单一变体。因此,您不能向其中添加其他产品。您可以将这些附加功能捆绑在新的有凝聚力的产品中,然后用一个按钮将其出售,但是您的按钮库会变得更大,也许这个想法也会破坏您的库存管理,所以就这样吧。

您唯一真正的办法是利用 StorefrontAPI 和一些自定义 JS 来构建您自己的按钮来管理多个产品。有了这个,您可以构建一个按钮,将客户发送到结账处,其中包含一个产品,也许还有一个额外的关联产品。

于 2021-03-13T03:52:54.267 回答