Js-buy-sdk: Line items don't get added to checkout when using addLineItems successfully

Created on 6 Jul 2018  路  3Comments  路  Source: Shopify/js-buy-sdk

Description and Steps
I made an API call to create a product whose variant id you can see in the screenshot below

image

I then pass that product object into my function below. I'm converting the admin_graphql_api_id for the variant to base64 to create a valid variantId to pass into the addLineItems function

export async function ShopifyCheckout(box) {
  console.log(box);
  const boxVariantId = btoa(box.data.variants[0].admin_graphql_api_id);
  // const { boxDescription } = box.data;
  const checkoutId = await client.checkout.create().then(checkout => checkout.id);
  const checkoutLineItems = [{ variantId: boxVariantId, quantity: 1 }];

  console.log(`Before Adding: ${checkoutId}`);
  client.checkout.addLineItems(checkoutId, checkoutLineItems).then((checkout) => {
    console.log(`After Adding: ${checkout.id}`);
    console.log(checkout);
    console.log(checkout.lineItems);
    console.log('why wont u adddddd');
  }).catch((err) => {
    console.log(err);
  });
}

After calling the function. I see that I made a successful call to add the line items. The checkout I created is the same checkout that I attempted to add line items to. However I see an empty array of line items, meaning nothing was added.

image

Expected behavior
I expected line items to be added to my checkout

Environment (please complete the following information):

  • OS: Ubuntu 16.04
  • Browser: Chrome, Firefox
  • SDK Version: v1.6.0

Bug Report Checklist

  • [x ] I have read and agree to the CODE_OF_CONDUCT.md
  • [ x] I have read the CONTRIBUTING.md guidelines.
  • [x ] I have provided a detailed description of the bug, including code samples, and/or network data.
  • [x ] I have provided information about my development environment, including SDK version.

Most helpful comment

do you have any data from the network, as to what the data returned looks like?

Have you verified that you can fetch the product using the SDK? This would check to ensure that the product is published to the storefront channel you've created.

All 3 comments

do you have any data from the network, as to what the data returned looks like?

Have you verified that you can fetch the product using the SDK? This would check to ensure that the product is published to the storefront channel you've created.

Now I feel a bit embarrassed. You were right about the storefront channel. I had thought that a product created using the API would be available on all sales channels by default. I made it available before testing the addLineItems function and it worked perfectly. Thank you!

Great! Glad it worked 馃槃

Was this page helpful?
0 / 5 - 0 ratings