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