App reviews, troubleshooting, and recommendations
I am using the Shopify SDK... I am attempting to extract the checkout id so I can use it globally or in middleware and share it with multiple pages. but I keep getting stuck in a Promise { pending }, which is the error. I was able to extract it before but it keeps creating checkout id's for every page. so I am attempting to isolate the checkout id creation so it will create only once and I can share the checkout id between each page in the website.
const Client = require("shopify-buy");
const fetch = require("node-fetch");
global.fetch = fetch;
const client = Client.buildClient({
storefrontAccessToken: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
domain: "swagunco.myshopify.com",
});
const createCheckoutId = async () => {
let store = client.checkout.create().then((checkout) => {
// Do something with the checkout
return checkout.id;
});
return store;
};
console.log(createCheckoutId());
I am attempting to store the checkout id in a variable and add it to middleware and pass it as req.query.id. or in local storage but I need the checkout id to trigger only once. If there is a better way to do this I am all ears. thanks in advance.
Below is the example of how my code is structured I am using server side rendering.
https://github.com/Shopify/storefront-api-examples/tree/master/node-js-buy
You can try using the await command, meaning this (note that I'm not fully familiar with the actual types used here but the concept should be enough)
app.get('/', async (req, res) => {
....
let checkout = await client.checkout.create();
Than checkout.id will be your data to use at the rest of the flow
The issue with the current code is that the function doesn't wait for the execution to finish and it ends without you getting what you need.
You want to make it execute at an order that will get your data from the async functions and allow you to use it as the code flows.
HTH
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024