feat: payload cms

This commit is contained in:
2026-02-24 15:52:16 +01:00
parent a5d77fc69b
commit 4742630260
21 changed files with 255 additions and 22850 deletions

View File

@@ -155,12 +155,23 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
// Fetch ALL products in a single query to avoid N+1 getPayload() calls
const payload = await getPayload({ config: configPromise });
const selectFields = {
title: true,
slug: true,
sku: true,
description: true,
categories: true,
images: true,
locale: true,
};
// Get products for this locale
const result = await payload.find({
collection: 'products',
where: { locale: { equals: locale } },
depth: 1,
pagination: false,
select: selectFields,
});
let products: ProductMdx[] = result.docs
@@ -174,15 +185,15 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
slug: doc.slug,
frontmatter: {
title: doc.title,
sku: doc.sku,
description: doc.description,
sku: doc.sku || '',
description: doc.description || '',
categories: Array.isArray(doc.categories) ? doc.categories.map((c: any) => c.category) : [],
images: ((doc.images as any[]) || [])
.map((img) => (typeof img === 'string' ? img : img.url))
.filter(Boolean),
locale: doc.locale,
},
content: doc.content,
content: null, // Avoided loading into memory!
}));
// Also include English fallbacks for slugs not in this locale
@@ -193,6 +204,7 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
where: { locale: { equals: 'en' } },
depth: 1,
pagination: false,
select: selectFields,
});
const fallbacks = enResult.docs
@@ -207,8 +219,8 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
slug: doc.slug,
frontmatter: {
title: doc.title,
sku: doc.sku,
description: doc.description,
sku: doc.sku || '',
description: doc.description || '',
categories: Array.isArray(doc.categories)
? doc.categories.map((c: any) => c.category)
: [],
@@ -218,7 +230,7 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
locale: doc.locale,
isFallback: true,
},
content: doc.content,
content: null, // Avoided loading into memory!
}));
products = [...products, ...fallbacks];