mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Implement Shopify Provider
This commit is contained in:
34
framework/shopify/common/get-all-pages.ts
Normal file
34
framework/shopify/common/get-all-pages.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { Page, PageEdge } from '../schema'
|
||||
import { getAllPagesQuery } from '../utils/queries'
|
||||
|
||||
type Variables = {
|
||||
first?: number
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
pages: Page[]
|
||||
}
|
||||
|
||||
const getAllPages = async (options?: {
|
||||
variables?: Variables
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllPagesQuery, { variables })
|
||||
|
||||
const pages = data.pages.edges.map(({ node }: PageEdge) => {
|
||||
return {
|
||||
...node,
|
||||
name: node.handle,
|
||||
url: `${config!.locale}/${node.handle}`,
|
||||
}
|
||||
})
|
||||
|
||||
return { pages }
|
||||
}
|
||||
|
||||
export default getAllPages
|
27
framework/shopify/common/get-page.ts
Normal file
27
framework/shopify/common/get-page.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ShopifyConfig, getConfig } from '../api'
|
||||
import type { Page } from '../types'
|
||||
|
||||
export type { Page }
|
||||
|
||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||
|
||||
export type PageVariables = {
|
||||
id: string
|
||||
}
|
||||
|
||||
async function getPage({
|
||||
url,
|
||||
variables,
|
||||
config,
|
||||
preview,
|
||||
}: {
|
||||
url?: string
|
||||
variables: PageVariables
|
||||
config?: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetPageResult> {
|
||||
config = getConfig(config)
|
||||
return {}
|
||||
}
|
||||
|
||||
export default getPage
|
31
framework/shopify/common/get-site-info.ts
Normal file
31
framework/shopify/common/get-site-info.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { CollectionEdge } from '@framework/schema'
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
|
||||
|
||||
const getSiteInfo = async (options?: {
|
||||
variables?: any
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}) => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllCollectionsQuery, { variables })
|
||||
const edges = data.collections?.edges ?? []
|
||||
|
||||
const categories = edges.map(
|
||||
({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
|
||||
entityId,
|
||||
name,
|
||||
path: `/${handle}`,
|
||||
})
|
||||
)
|
||||
|
||||
return {
|
||||
categories,
|
||||
brands: [],
|
||||
}
|
||||
}
|
||||
|
||||
export default getSiteInfo
|
Reference in New Issue
Block a user