误导性和过时的 Shopify Buy JS 文档
Misleading and Outdated Shopify Buy JS Documentation
我目前正在尝试建立一个 Wordpress 网站来在线销售产品,我正在使用 Shopify 来处理电子商务部分。问题就出在这段代码上。
import Client from 'shopify-buy';
const client = Client.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
});
我正在使用 documentation 上发布的缩小版 UMD 构建版本,我的实际代码是这样的:
const client = ShopifyBuy.buildClient({
domain: 'domain.myshopify.com',
storefrontAccessToken: 'token',
apiKey: 'key',
appId: '6'
});
// Fetch all products in your shop
client.product.fetchAll().then((products) => {
// Do something with the products
console.log(products);
});
我不使用导入,因为我使用的是 CDN 资源(我将它排入我的 wordpress functions.php ),我的代码中的客户端声明是不同的,因为我不知道原因,每当我尝试仅使用 shopify 文档提供的代码片段时,我都会收到错误消息,提示我缺少 apiKey 和 appID,因此我需要包含它们,以便稍后从控制台收到此消息:
[ShopifyBuy] Config property apiKey is deprecated as of v1.0, please
use storefrontAccessToken instead.
并且还收到此错误:
"TypeError: client.product is undefined"
所以这让我相信要么提供的缩小版本已经过时,要么 shopify 提供给尝试使用缩小 UMD 版本的人的信息有问题。
在撰写本文时,还有 1 个 youtube 视频解释了大约 1 年前的使用方法,shopify UI 已过时,代码也已过时,所以我不想构建所有存储的代码都已弃用,因此我需要重新做。对于像我这样为客户构建网站的人来说,这是一笔不小的数目。
所以总而言之,我需要帮助来了解如何声明客户端对象,或者如果有人已经在 Wordpress 上做过,请告诉我怎么做
这是我提到的关于缺少 apiKey 的错误:
buy-button-storefront.min.js:2 Uncaught Error: new Config() requires
the option 'apiKey'
at buy-button-storefront.min.js:2
at Array.forEach ()
at n.constructor (buy-button-storefront.min.js:2)
at new n (buy-button-storefront.min.js:2)
at Object.buildClient (buy-button-storefront.min.js:3)
at (index):235
这段代码现在可以正常工作了。
const client = ShopifyBuy.buildClient({
domain: 'website.myshopify.com',
storefrontAccessToken: 'storeaccesstokenid'
});
除此之外,您还需要将此添加到页脚
<script src="https://sdks.shopifycdn.com/js-buy-sdk/v1/latest/index.umd.min.js"></script>
我目前正在尝试建立一个 Wordpress 网站来在线销售产品,我正在使用 Shopify 来处理电子商务部分。问题就出在这段代码上。
import Client from 'shopify-buy';
const client = Client.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
});
我正在使用 documentation 上发布的缩小版 UMD 构建版本,我的实际代码是这样的:
const client = ShopifyBuy.buildClient({
domain: 'domain.myshopify.com',
storefrontAccessToken: 'token',
apiKey: 'key',
appId: '6'
});
// Fetch all products in your shop
client.product.fetchAll().then((products) => {
// Do something with the products
console.log(products);
});
我不使用导入,因为我使用的是 CDN 资源(我将它排入我的 wordpress functions.php ),我的代码中的客户端声明是不同的,因为我不知道原因,每当我尝试仅使用 shopify 文档提供的代码片段时,我都会收到错误消息,提示我缺少 apiKey 和 appID,因此我需要包含它们,以便稍后从控制台收到此消息:
[ShopifyBuy] Config property apiKey is deprecated as of v1.0, please use storefrontAccessToken instead.
并且还收到此错误:
"TypeError: client.product is undefined"
所以这让我相信要么提供的缩小版本已经过时,要么 shopify 提供给尝试使用缩小 UMD 版本的人的信息有问题。
在撰写本文时,还有 1 个 youtube 视频解释了大约 1 年前的使用方法,shopify UI 已过时,代码也已过时,所以我不想构建所有存储的代码都已弃用,因此我需要重新做。对于像我这样为客户构建网站的人来说,这是一笔不小的数目。
所以总而言之,我需要帮助来了解如何声明客户端对象,或者如果有人已经在 Wordpress 上做过,请告诉我怎么做
这是我提到的关于缺少 apiKey 的错误:
buy-button-storefront.min.js:2 Uncaught Error: new Config() requires the option 'apiKey' at buy-button-storefront.min.js:2 at Array.forEach () at n.constructor (buy-button-storefront.min.js:2) at new n (buy-button-storefront.min.js:2) at Object.buildClient (buy-button-storefront.min.js:3) at (index):235
这段代码现在可以正常工作了。
const client = ShopifyBuy.buildClient({
domain: 'website.myshopify.com',
storefrontAccessToken: 'storeaccesstokenid'
});
除此之外,您还需要将此添加到页脚
<script src="https://sdks.shopifycdn.com/js-buy-sdk/v1/latest/index.umd.min.js"></script>