-
-
Save Harasz/b51d04e6422ee52253494a510945fd7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get("/settings", async (ctx) => { | |
const session = await Shopify.Utils.loadCurrentSession(ctx.req, ctx.res); | |
const shop = session.shop; | |
// This shop hasn't been seen yet, go through OAuth to create a session | |
if (session === undefined || ACTIVE_SHOPIFY_SHOPS[shop] === undefined) { | |
ctx.redirect(`/auth?shop=${shop}`); | |
return; | |
} | |
const shopSettings = ACTIVE_SHOPIFY_SHOPS[shop].settings; | |
if (!shopSettings.productId) { | |
ctx.status = 200; | |
ctx.body = { | |
status: "EMPTY_SETTINGS", | |
data: undefined, | |
}; | |
return; | |
} | |
const client = new Shopify.Clients.Rest(session.shop, session.accessToken); | |
const productDetails = await client.get({ | |
path: `products/${shopSettings.productId}`, | |
type: DataType.JSON, | |
}); | |
ctx.body = { | |
status: "OK_SETTINGS", | |
data: productDetails.body.product, | |
}; | |
ctx.status = 200; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment