30 lines
983 B
JavaScript
30 lines
983 B
JavaScript
import * as prismic from '@prismicio/client'
|
|
import { createStorefrontApiClient } from '@shopify/storefront-api-client'
|
|
import { GET_PRODUCT_BY_HANDLE } from '@/libs/shopify/product'
|
|
|
|
export const data = async (pageContext) => {
|
|
const { id } = pageContext.routeParams
|
|
const prismicClient = prismic.createClient('swang')
|
|
|
|
const eventDoc = await prismicClient.getByUID('event', id)
|
|
const event = eventDoc?.data
|
|
|
|
const productHandle = event?.shopify_product_handle
|
|
|
|
if (!productHandle) return { event, product: null }
|
|
|
|
const shopifyClient = createStorefrontApiClient({
|
|
storeDomain: `https://swangent.myshopify.com`,
|
|
apiVersion: '2026-04',
|
|
publicAccessToken: 'd2848b9bcde999cea878c218493cfe84',
|
|
})
|
|
|
|
const query = GET_PRODUCT_BY_HANDLE
|
|
const variables = { handle: productHandle }
|
|
|
|
const productRes = await shopifyClient.request(query, { variables })
|
|
const product = productRes?.data
|
|
|
|
return { event, product }
|
|
}
|