【问题标题】:How to get the ID required for a shopify buy button?如何获取shopify购买按钮所需的ID?
【发布时间】:2018-12-11 22:45:31
【问题描述】:

如何获取 shopify 产品资源 ID?在他们的一篇博文中here(向下滚动到本节,3. 创建组件)他们建议它看起来像这样,id: 1234567

ui.createComponent('product', {
  id: 1234567,
  node: document.getElementById('my-product')
});

如何获得这个值? id: 1234567

当我在how to find a resource ID 上单击the article 中的链接时,我被带到here,然后我被带到here。

我正在尝试在我的 wordpress 网站上构建一个带有迷你购物车的 shopify 购买按钮。 Shopify 为每个产品提供了开箱即用的生成代码,如下所示:

<div id='product-component-a3721b1ed3e' ></div>
<script type="text/javascript">
    /*<![CDATA[*/

    (function () {
      var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/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: 'my-shop.com',
          storefrontAccessToken: 'my-token',
        });

        ShopifyBuy.UI.onReady(client).then(function (ui) {

          ui.createComponent('product', {
            id: [12345667820298],
            node: document.getElementById('product-component-a3721b1ed3e'),
            moneyFormat: '%24%7B%7Bamount%7D%7D',
            options: {
            "product": {
              "variantId": "all",
              "width": "240px",
              "contents": {
                "img": false,
                "imgWithCarousel": false,
                "title": false,
                "variantTitle": false,
                "price": false,
                "description": false,
                "buttonWithQuantity": false,
                "quantity": false
              },
              "styles": {
                "product": {
                  "text-align": "left",
                  "@media (min-width: 601px)": {
                    "max-width": "100%",
                    "margin-left": "0",
                    "margin-bottom": "50px"
                  }
                },
                "title": {
                  "font-size": "26px"
                },
                "price": {
                  "font-size": "18px"
                },
                "compareAt": {
                  "font-size": "15px"
                }
              }
            },
            "cart": {
              "contents": {
                "button": true
              },
              "styles": {
                "footer": {
                  "background-color": "#ffffff"
                }
              }
            },
            "modalProduct": {
              "contents": {
                "img": false,
                "imgWithCarousel": true,
                "variantTitle": false,
                "buttonWithQuantity": true,
                "button": false,
                "quantity": false
              },
              "styles": {
                "product": {
                  "@media (min-width: 601px)": {
                    "max-width": "100%",
                    "margin-left": "0px",
                    "margin-bottom": "0px"
                  }
                }
              }
            },
            "productSet": {
              "styles": {
                "products": {
                  "@media (min-width: 601px)": {
                    "margin-left": "-20px"
                  }
                }
              }
            }
          }
          });
        });
      }
    })();
    /*]]>*/
</script>

看起来这是我想要的每个产品的 ID:

      ui.createComponent('product', {
        id: [12345667820298],

我只是不知道如何获得它。

【问题讨论】:

    标签: wordpress shopify


    【解决方案1】:

    是的,这是 ID。如果您生成购买按钮,您将获得 id。无需进一步操作。此 id 也显示在 URL 中。例如,在后端转到产品 - 所有产品并单击一个产品。 URL 现在以 id 结尾。

    我认为这很混乱。它们的存在句柄(源自产品名称)、此变体 id 和 API 中使用的 id。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      • 2016-06-14
      相关资源
      最近更新 更多