mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 21:51:21 +00:00
Shopify changes
This commit is contained in:
parent
2f428791cf
commit
cac0ec16dd
@ -38,7 +38,9 @@ export default function getAllPagesOperation({
|
|||||||
preview?: boolean
|
preview?: boolean
|
||||||
query?: string
|
query?: string
|
||||||
} = {}): Promise<T['data']> {
|
} = {}): Promise<T['data']> {
|
||||||
const { fetch, locale, locales = ['en-US'] } = commerce.getConfig(config)
|
const { fetch, locale, locales = ['en-US', 'es'] } = commerce.getConfig(
|
||||||
|
config
|
||||||
|
)
|
||||||
|
|
||||||
const { data } = await fetch<GetAllPagesQuery, GetAllPagesQueryVariables>(
|
const { data } = await fetch<GetAllPagesQuery, GetAllPagesQueryVariables>(
|
||||||
query,
|
query,
|
||||||
|
@ -39,7 +39,7 @@ export default function getPageOperation({
|
|||||||
config?: Partial<ShopifyConfig>
|
config?: Partial<ShopifyConfig>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
}): Promise<T['data']> {
|
}): Promise<T['data']> {
|
||||||
const { fetch, locale = 'en-US' } = commerce.getConfig(config)
|
const { fetch, locale } = commerce.getConfig(config)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { node: page },
|
data: { node: page },
|
||||||
|
@ -50,18 +50,18 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
})
|
})
|
||||||
// filter on client when brandId & categoryId are set since is not available on collection product query
|
// filter on client when brandId & categoryId are set since is not available on collection product query
|
||||||
products = brandId
|
products = brandId
|
||||||
? data.node.products.edges.filter(
|
? data.node?.products?.edges?.filter(
|
||||||
({ node: { vendor } }: ProductEdge) =>
|
({ node: { vendor } }: ProductEdge) =>
|
||||||
vendor.replace(/\s+/g, '-').toLowerCase() === brandId
|
vendor.replace(/\s+/g, '-').toLowerCase() === brandId
|
||||||
)
|
)
|
||||||
: data.node.products.edges
|
: data.node?.products?.edges
|
||||||
} else {
|
} else {
|
||||||
const data = await fetch<GetAllProductsQuery>({
|
const data = await fetch<GetAllProductsQuery>({
|
||||||
query: options.query,
|
query: options.query,
|
||||||
method,
|
method,
|
||||||
variables,
|
variables,
|
||||||
})
|
})
|
||||||
products = data.products.edges
|
products = data.products?.edges
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -174,14 +174,14 @@ function normalizeLineItem({
|
|||||||
|
|
||||||
export const normalizePage = (
|
export const normalizePage = (
|
||||||
{ title: name, handle, ...page }: ShopifyPage,
|
{ title: name, handle, ...page }: ShopifyPage,
|
||||||
locale: string
|
locale: string = 'en-US'
|
||||||
): Page => ({
|
): Page => ({
|
||||||
...page,
|
...page,
|
||||||
url: `/${locale}/${handle}`,
|
url: `/${locale}/${handle}`,
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const normalizePages = (edges: PageEdge[], locale: string): Page[] =>
|
export const normalizePages = (edges: PageEdge[], locale?: string): Page[] =>
|
||||||
edges?.map((edge) => normalizePage(edge.node, locale))
|
edges?.map((edge) => normalizePage(edge.node, locale))
|
||||||
|
|
||||||
export const normalizeCategory = ({
|
export const normalizeCategory = ({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user