detail page port
This commit is contained in:
29
pages/@id/+data.js
Normal file
29
pages/@id/+data.js
Normal file
@@ -0,0 +1,29 @@
|
||||
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 }
|
||||
}
|
||||
Reference in New Issue
Block a user