0

我正在使用带有 Node.js 的 JavaScript 购买 SDK。

const fetch = require('node-fetch');
const shopify = require('shopify-buy');

const client = shopify.buildClient({
  storefrontAccessToken: 'MY_STORE_ACCESS_TOKEN',
  domain: 'SHOP_URL',
}, fetch);

我得到这样的产品 ID:

const products = yield client.product.fetchAll();
const variantId = products[0].variants[0].id;
const checkout = yield client.checkout.create();

有没有使用 JavaScript Buy SDK 将此产品添加到购物车的方法,在他们指定的文档中,该 SDK 也可用于将产品添加到购物车!

4

1 回答 1

1

以下示例代码取自文档

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; //  ID of an existing checkout
const lineItemsToAdd = [
  {variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', quantity: 5}
];
// Add an item to the checkout
client.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout.lineItems); // Array with one additional line item
});
于 2018-12-15T16:32:59.700 回答