0
votes

I'm using JavaScript buy SDK with Node.js.

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

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

I'm getting a product ID like this:

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

Is there any method to add this product into cart using JavaScript Buy SDK, in the documentation they have specified that this SDK can be used to add a product to the cart too!

1

1 Answers

1
votes

The following example code is taken from the docs

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
});