mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 23:16:59 +00:00
Fix paths
This commit is contained in:
parent
a44a6c0291
commit
8eedf41879
@ -100,7 +100,7 @@ export default function getAllProductPathsOperation({
|
|||||||
const variables: GetProductQueryVariables = {
|
const variables: GetProductQueryVariables = {
|
||||||
locale,
|
locale,
|
||||||
hasLocale: !!locale,
|
hasLocale: !!locale,
|
||||||
path: slug ? `/${slug}/` : vars.path!,
|
path: slug ? `/${slug}` : vars.path!,
|
||||||
}
|
}
|
||||||
const { data } = await config.fetch<GetProductQuery>(query, { variables })
|
const { data } = await config.fetch<GetProductQuery>(query, { variables })
|
||||||
const product = data.site?.route?.node
|
const product = data.site?.route?.node
|
||||||
|
@ -76,6 +76,7 @@ export function normalizePage(page: definitions['page_Full']): Page {
|
|||||||
is_visible: page.is_visible,
|
is_visible: page.is_visible,
|
||||||
sort_order: page.sort_order,
|
sort_order: page.sort_order,
|
||||||
body: page.body ?? '',
|
body: page.body ?? '',
|
||||||
|
url: page.url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ export const withSchemaParser =
|
|||||||
const parse = (operation: AllowedOperations, data: OperationsData) => {
|
const parse = (operation: AllowedOperations, data: OperationsData) => {
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case 'getProduct':
|
case 'getProduct':
|
||||||
productSchema.parse(data.product)
|
productSchema.nullable().parse(data.product)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'getAllProducts':
|
case 'getAllProducts':
|
||||||
@ -36,7 +36,7 @@ const parse = (operation: AllowedOperations, data: OperationsData) => {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case 'getPage':
|
case 'getPage':
|
||||||
pageSchema.parse(data.page)
|
pageSchema.nullable().parse(data.page)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'getAllPages':
|
case 'getAllPages':
|
||||||
|
@ -3,7 +3,7 @@ import { z } from 'zod'
|
|||||||
export const pageSchema = z.object({
|
export const pageSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
url: z.string().startsWith('/'),
|
url: z.string().startsWith('/').optional(),
|
||||||
body: z.string(),
|
body: z.string(),
|
||||||
is_visible: z.boolean().optional(),
|
is_visible: z.boolean().optional(),
|
||||||
sort_order: z.number().optional(),
|
sort_order: z.number().optional(),
|
||||||
@ -12,7 +12,7 @@ export const pageSchema = z.object({
|
|||||||
export const pagesPathsSchema = z.array(
|
export const pagesPathsSchema = z.array(
|
||||||
z.object({
|
z.object({
|
||||||
page: z.object({
|
page: z.object({
|
||||||
path: z.string(),
|
path: z.string().startsWith('/'),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -26,8 +26,8 @@ export const productImageSchema = z.object({
|
|||||||
|
|
||||||
export const productVariantSchema = z.object({
|
export const productVariantSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
sku: z.string().optional(),
|
sku: z.string().nullish(),
|
||||||
name: z.string(),
|
name: z.string().optional(),
|
||||||
options: z.array(productOptionSchema),
|
options: z.array(productOptionSchema),
|
||||||
image: productImageSchema.optional(),
|
image: productImageSchema.optional(),
|
||||||
})
|
})
|
||||||
@ -37,7 +37,7 @@ export const productSchema = z.object({
|
|||||||
name: z.string(),
|
name: z.string(),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
descriptionHtml: z.string().optional(),
|
descriptionHtml: z.string().optional(),
|
||||||
sku: z.string().optional(),
|
sku: z.string().nullish(),
|
||||||
slug: z.string(),
|
slug: z.string(),
|
||||||
path: z.string().startsWith('/'),
|
path: z.string().startsWith('/'),
|
||||||
images: z.array(productImageSchema),
|
images: z.array(productImageSchema),
|
||||||
|
@ -63,7 +63,7 @@ export function normalizeProduct(
|
|||||||
description,
|
description,
|
||||||
descriptionHtml: description,
|
descriptionHtml: description,
|
||||||
slug: permalink,
|
slug: permalink,
|
||||||
path: permalink,
|
path: `/${permalink}`,
|
||||||
images: assets.map(({ url, description, filename }) => ({
|
images: assets.map(({ url, description, filename }) => ({
|
||||||
url,
|
url,
|
||||||
alt: description || filename,
|
alt: description || filename,
|
||||||
|
@ -37,15 +37,15 @@ export default function getAllPagesOperation({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const pages = data?.pages?.edges?.map(
|
const pages =
|
||||||
({ node: { title: name, slug, ...node } }: PageCountableEdge) =>
|
data?.pages?.edges?.map(
|
||||||
({
|
({ node: { title: name, slug, ...node } }: PageCountableEdge) => ({
|
||||||
id: node.id,
|
id: node.id,
|
||||||
url: `/${locale}/${slug}`,
|
url: `/${locale}/${slug}`,
|
||||||
body: node.content || '',
|
body: node.content || '',
|
||||||
name,
|
name,
|
||||||
} ?? [])
|
})
|
||||||
)
|
) ?? []
|
||||||
|
|
||||||
return { pages }
|
return { pages }
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ export function normalizeProduct(
|
|||||||
// TODO: use `name-ID` as a virtual slug (for search 1:1)
|
// TODO: use `name-ID` as a virtual slug (for search 1:1)
|
||||||
slug: product.id, // use product ID as a slug
|
slug: product.id, // use product ID as a slug
|
||||||
name: product.name!,
|
name: product.name!,
|
||||||
|
path: `/${product.id}`,
|
||||||
description: product.longDescription!,
|
description: product.longDescription!,
|
||||||
price: {
|
price: {
|
||||||
value: product.price!,
|
value: product.price!,
|
||||||
@ -77,6 +78,7 @@ export function normalizeSearchProducts(
|
|||||||
return products.map((product) => ({
|
return products.map((product) => ({
|
||||||
id: product.productId,
|
id: product.productId,
|
||||||
slug: product.productId, // use product ID as a slug
|
slug: product.productId, // use product ID as a slug
|
||||||
|
path: `/${product.productId}`,
|
||||||
name: product.productName!,
|
name: product.productName!,
|
||||||
description: '',
|
description: '',
|
||||||
price: {
|
price: {
|
||||||
|
@ -111,7 +111,7 @@ export default function getSiteInfoOperation({
|
|||||||
id: spreeTaxon.id,
|
id: spreeTaxon.id,
|
||||||
name: spreeTaxon.attributes.name,
|
name: spreeTaxon.attributes.name,
|
||||||
slug: spreeTaxon.id,
|
slug: spreeTaxon.id,
|
||||||
path: spreeTaxon.id,
|
path: `/${spreeTaxon.id}`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ export default function getProductOperation({
|
|||||||
name: product.name,
|
name: product.name,
|
||||||
description: product.description,
|
description: product.description,
|
||||||
slug: product.slug,
|
slug: product.slug,
|
||||||
|
path: `/${product.slug}`,
|
||||||
images: product.assets.map((a) => ({
|
images: product.assets.map((a) => ({
|
||||||
url: a.preview,
|
url: a.preview,
|
||||||
alt: a.name,
|
alt: a.name,
|
||||||
|
@ -33,8 +33,8 @@ export default function getSiteInfoOperation({
|
|||||||
})
|
})
|
||||||
const collections = data.collections?.items.map((i) => ({
|
const collections = data.collections?.items.map((i) => ({
|
||||||
...i,
|
...i,
|
||||||
entityId: i.id,
|
id: i.id,
|
||||||
path: i.slug,
|
path: `/${i.id}`,
|
||||||
productCount: i.productVariants.totalItems,
|
productCount: i.productVariants.totalItems,
|
||||||
}))
|
}))
|
||||||
const categories = arrayToTree(collections).children
|
const categories = arrayToTree(collections).children
|
||||||
|
@ -8,7 +8,7 @@ export function normalizeSearchResult(item: SearchResultFragment): Product {
|
|||||||
name: item.productName,
|
name: item.productName,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
slug: item.slug,
|
slug: item.slug,
|
||||||
path: item.slug,
|
path: `${item.slug}`,
|
||||||
images: [
|
images: [
|
||||||
{
|
{
|
||||||
url: item.productAsset?.preview
|
url: item.productAsset?.preview
|
||||||
|
Loading…
x
Reference in New Issue
Block a user