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
The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024