首页展示
This commit is contained in:
parent
14a2aaced0
commit
dc8c88e463
|
|
@ -36,14 +36,12 @@ export async function GET(req: NextRequest) {
|
|||
slug: 'hero-slider',
|
||||
})
|
||||
|
||||
// 获取产品推荐(包含深度查询的产品信息)
|
||||
// 获取产品推荐(depth: 2 足以拿到产品文档及其直接关联字段)
|
||||
const productRecommendations = await payload.findGlobal({
|
||||
slug: 'product-recommendations',
|
||||
depth: 3, // 增加深度以确保完全获取嵌套数据
|
||||
depth: 2,
|
||||
})
|
||||
|
||||
console.log('Raw productRecommendations:', JSON.stringify(productRecommendations, null, 2))
|
||||
|
||||
// 构建响应数据
|
||||
const response = {
|
||||
announcements: announcements.docs.map((announcement) => ({
|
||||
|
|
@ -66,22 +64,8 @@ export async function GET(req: NextRequest) {
|
|||
products: (list.products || []).map((productRef: any) => {
|
||||
const product = productRef.value
|
||||
|
||||
// 调试日志:查看实际接收到的产品数据
|
||||
console.log('=== Product Debug Info ===')
|
||||
console.log('relationTo:', productRef.relationTo)
|
||||
console.log('product object:', product)
|
||||
console.log('Available fields:', Object.keys(product || {}))
|
||||
console.log('=========================')
|
||||
|
||||
// 处理 description 字段
|
||||
// Products 使用 textarea (字符串),PreorderProducts 使用 richText (对象)
|
||||
let description = ''
|
||||
if (typeof product.description === 'string') {
|
||||
description = product.description
|
||||
} else if (product.description && typeof product.description === 'object') {
|
||||
// richText 字段,提取纯文本(简单处理)
|
||||
description = JSON.stringify(product.description)
|
||||
}
|
||||
// description 是纯文本(从 Medusa 同步)
|
||||
const description = product.description || ''
|
||||
|
||||
// 基础产品信息
|
||||
const baseInfo = {
|
||||
|
|
@ -92,7 +76,8 @@ export async function GET(req: NextRequest) {
|
|||
thumbnail: product.thumbnail,
|
||||
status: product.status,
|
||||
description,
|
||||
minPrice: product.minPrice,
|
||||
content: product.content || null,
|
||||
startPrice: product.startPrice ?? null,
|
||||
}
|
||||
|
||||
// 如果是预购产品,添加预购特有字段
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import {
|
|||
getAllMedusaProducts,
|
||||
transformMedusaProductToPayload,
|
||||
getProductCollection,
|
||||
convertTextToLexical,
|
||||
} from '@/lib/medusa'
|
||||
import { addCorsHeaders, handleCorsOptions } from '@/lib/cors'
|
||||
|
||||
|
|
@ -137,11 +136,8 @@ export async function POST(request: Request) {
|
|||
id: existingProduct.id,
|
||||
})
|
||||
|
||||
// 准备移动数据,包括描述转换
|
||||
// 准备移动数据(description 已包含在 productData 中)
|
||||
const moveData: any = { ...productData }
|
||||
if (medusaProduct.description) {
|
||||
moveData.description = convertTextToLexical(medusaProduct.description)
|
||||
}
|
||||
|
||||
finalProduct = await payload.create({
|
||||
collection: targetCollection,
|
||||
|
|
@ -168,10 +164,8 @@ export async function POST(request: Request) {
|
|||
if (!existingProduct.handle) mergedData.handle = productData.handle
|
||||
if (!existingProduct.thumbnail) mergedData.thumbnail = productData.thumbnail
|
||||
if (!existingProduct.status) mergedData.status = productData.status
|
||||
// 描述为空时也从 Medusa 导入(转换为富文本格式)
|
||||
if (!existingProduct.description && medusaProduct.description) {
|
||||
(mergedData as any).description = convertTextToLexical(medusaProduct.description)
|
||||
}
|
||||
// description 始终从 Medusa 同步(纯文本,只读字段)
|
||||
mergedData.description = medusaProduct.description || null
|
||||
|
||||
// 最低价格和 seedId:总是更新
|
||||
mergedData.seedId = productData.seedId
|
||||
|
|
@ -219,12 +213,9 @@ export async function POST(request: Request) {
|
|||
})
|
||||
action = 'updated_partial'
|
||||
} else {
|
||||
// 强制更新所有字段(包括描述转换为富文本)
|
||||
// 强制更新所有字段(description 已包含在 productData 中)
|
||||
console.log(`[Sync Product API] ⚡ 强制更新所有字段`)
|
||||
const forceUpdateData: any = { ...productData }
|
||||
if (medusaProduct.description) {
|
||||
forceUpdateData.description = convertTextToLexical(medusaProduct.description)
|
||||
}
|
||||
finalProduct = await payload.update({
|
||||
collection: targetCollection,
|
||||
id: existingProduct.id,
|
||||
|
|
@ -240,10 +231,7 @@ export async function POST(request: Request) {
|
|||
// 如果是预购产品,添加预购相关字段
|
||||
const createData: any = { ...productData }
|
||||
|
||||
// 添加描述(转换为富文本格式)
|
||||
if (medusaProduct.description) {
|
||||
createData.description = convertTextToLexical(medusaProduct.description)
|
||||
}
|
||||
// description 已包含在 productData 中(纯文本,从 Medusa 同步)
|
||||
|
||||
if (targetCollection === 'preorder-products') {
|
||||
if (fundingGoal !== undefined) {
|
||||
|
|
|
|||
|
|
@ -163,10 +163,10 @@ export const PreorderProducts: CollectionConfig = {
|
|||
],
|
||||
},
|
||||
{
|
||||
label: '📝 商品描述',
|
||||
label: '📝 商品详情',
|
||||
fields: [
|
||||
{
|
||||
name: 'description',
|
||||
name: 'content',
|
||||
type: 'richText',
|
||||
editor: lexicalEditor({
|
||||
features: [
|
||||
|
|
@ -217,7 +217,7 @@ export const PreorderProducts: CollectionConfig = {
|
|||
],
|
||||
}),
|
||||
admin: {
|
||||
description: '预售商品的详细描述(支持富文本编辑)',
|
||||
description: '预售商品的详细内容(富文本,由 Payload 编辑,展示在产品详情页)',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ export const Products: CollectionConfig = {
|
|||
label: '📄 商品详情',
|
||||
fields: [
|
||||
{
|
||||
name: 'description',
|
||||
name: 'content',
|
||||
type: 'richText',
|
||||
editor: lexicalEditor({
|
||||
features: [
|
||||
|
|
@ -107,7 +107,7 @@ export const Products: CollectionConfig = {
|
|||
],
|
||||
}),
|
||||
admin: {
|
||||
description: '商品详细描述(支持富文本编辑)',
|
||||
description: '商品详细内容(富文本,由 Payload 编辑,展示在产品详情页)',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -95,6 +95,14 @@ export const ProductBaseFields: Field[] = [
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
type: 'text',
|
||||
admin: {
|
||||
description: '产品简介(纯文本,从 Medusa 同步,显示在卡片和列表页)',
|
||||
readOnly: true,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -319,6 +319,9 @@ export function transformMedusaProductToPayload(product: MedusaProduct) {
|
|||
collection: collection,
|
||||
category: category,
|
||||
|
||||
// 物理属性(优先使用直接字段,否则从 metadata 中提取)
|
||||
description: product.description || null,
|
||||
|
||||
// 物理属性(优先使用直接字段,否则从 metadata 中提取)
|
||||
height: product.height || (product.metadata?.height ? Number(product.metadata.height) : null),
|
||||
width: product.width || (product.metadata?.width ? Number(product.metadata.width) : null),
|
||||
|
|
|
|||
|
|
@ -226,9 +226,13 @@ export interface Product {
|
|||
*/
|
||||
lastSyncedAt?: string | null;
|
||||
/**
|
||||
* 商品详细描述(支持富文本编辑)
|
||||
* 产品简介(纯文本,从 Medusa 同步,显示在卡片和列表页)
|
||||
*/
|
||||
description?: {
|
||||
description?: string | null;
|
||||
/**
|
||||
* 商品详细内容(富文本,由 Payload 编辑,展示在产品详情页)
|
||||
*/
|
||||
content?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
|
|
@ -356,6 +360,10 @@ export interface PreorderProduct {
|
|||
* 最后同步时间
|
||||
*/
|
||||
lastSyncedAt?: string | null;
|
||||
/**
|
||||
* 产品简介(纯文本,从 Medusa 同步,显示在卡片和列表页)
|
||||
*/
|
||||
description?: string | null;
|
||||
/**
|
||||
* 预购类型
|
||||
*/
|
||||
|
|
@ -381,9 +389,9 @@ export interface PreorderProduct {
|
|||
*/
|
||||
fakeOrderCount?: number | null;
|
||||
/**
|
||||
* 预售商品的详细描述(支持富文本编辑)
|
||||
* 预售商品的详细内容(富文本,由 Payload 编辑,展示在产品详情页)
|
||||
*/
|
||||
description?: {
|
||||
content?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
|
|
@ -921,6 +929,7 @@ export interface ProductsSelect<T extends boolean = true> {
|
|||
startPrice?: T;
|
||||
lastSyncedAt?: T;
|
||||
description?: T;
|
||||
content?: T;
|
||||
relatedProducts?: T;
|
||||
tags?: T;
|
||||
type?: T;
|
||||
|
|
@ -957,13 +966,14 @@ export interface PreorderProductsSelect<T extends boolean = true> {
|
|||
thumbnail?: T;
|
||||
startPrice?: T;
|
||||
lastSyncedAt?: T;
|
||||
description?: T;
|
||||
preorderType?: T;
|
||||
fundingGoal?: T;
|
||||
preorderStartDate?: T;
|
||||
preorderEndDate?: T;
|
||||
orderCount?: T;
|
||||
fakeOrderCount?: T;
|
||||
description?: T;
|
||||
content?: T;
|
||||
relatedProducts?: T;
|
||||
tags?: T;
|
||||
type?: T;
|
||||
|
|
|
|||
Loading…
Reference in New Issue