diff --git a/.claude/settings.local.json b/.claude/settings.local.json index d786477..1268589 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -134,7 +134,8 @@ "Bash(timeout 30 git push origin main --force)", "Bash(GIT_TRACE=1 git push origin main --force)", "Bash(pkill -f \"node.exe\")", - "PowerShell(Stop-Process -Name node -Force -ErrorAction SilentlyContinue)" + "PowerShell(Stop-Process -Name node -Force -ErrorAction SilentlyContinue)", + "Bash(find \"D:\\\\Craft2Prints\\\\src\\\\app\" -path \"*/\\\\[slug\\\\]/*\" -name \"page.tsx\" | head -10)" ] } } diff --git a/src/app/api/checkout/route.ts b/src/app/api/checkout/route.ts index 102f5e4..d71b776 100644 --- a/src/app/api/checkout/route.ts +++ b/src/app/api/checkout/route.ts @@ -110,9 +110,19 @@ export async function POST(req: Request) { const pricedItems = items.map((i) => { const design = typeof i.designJson === 'string' ? JSON.parse(i.designJson) : i.designJson; const isPersonalised = (design.front?.length ?? 0) > 0 || (design.back?.length ?? 0) > 0; + const product = productsById.get(i.productId)!; + + // Determine which price to use + let priceType: 'base' | 'plain' | 'personalised' = 'base'; + if (isPersonalised) { + priceType = 'personalised'; + } else if (product.plainPrice != null) { + priceType = 'plain'; + } + return { ...i, - unitPrice: getEffectivePrice(productsById.get(i.productId)!, activePromotions, new Date(), isPersonalised).price, + unitPrice: getEffectivePrice(product, activePromotions, new Date(), priceType).price, }; }); diff --git a/src/app/made-to-order/[slug]/page.tsx b/src/app/made-to-order/[slug]/page.tsx index a4e377e..fb11288 100644 --- a/src/app/made-to-order/[slug]/page.tsx +++ b/src/app/made-to-order/[slug]/page.tsx @@ -19,13 +19,13 @@ export default async function ProductDetailPage({ const row = await prisma.product.findUnique({ where: { slug: params.slug } }); if (!row || !row.showOnPersonalised) notFound(); - const product = toProductDTO(row, activePromotions); + const product = toProductDTO(row, activePromotions, 'personalised'); const relatedRows = await prisma.product.findMany({ where: { category: product.category, showOnPersonalised: true, NOT: { id: product.id } }, take: 4, }); - const related = relatedRows.map((p) => toProductDTO(p, activePromotions)); + const related = relatedRows.map((p) => toProductDTO(p, activePromotions, 'personalised')); // Fetch custom photo from request if customRequestId is provided let customPhoto: string | undefined; diff --git a/src/app/made-to-order/page.tsx b/src/app/made-to-order/page.tsx index 45609f3..c395bea 100644 --- a/src/app/made-to-order/page.tsx +++ b/src/app/made-to-order/page.tsx @@ -70,7 +70,7 @@ export default async function ProductsPage({ searchParams }: { searchParams: Sea const activePromotions = await fetchActivePromotions(); const rows = await prisma.product.findMany({ where, orderBy: { createdAt: 'asc' } }); - const products = rows.map((p) => toProductDTO(p, activePromotions)); + const products = rows.map((p) => toProductDTO(p, activePromotions, 'personalised')); const hasFilters = selectedCategories.length > 0 || diff --git a/src/app/products/[slug]/page.tsx b/src/app/products/[slug]/page.tsx index 79a951d..f0d89dc 100644 --- a/src/app/products/[slug]/page.tsx +++ b/src/app/products/[slug]/page.tsx @@ -11,13 +11,13 @@ export default async function StandardProductPage({ params }: { params: { slug: const row = await prisma.product.findUnique({ where: { slug: params.slug } }); if (!row || !row.showOnProducts) notFound(); - const product = toProductDTO(row, activePromotions); + const product = toProductDTO(row, activePromotions, 'plain'); const relatedRows = await prisma.product.findMany({ where: { category: product.category, showOnProducts: true, NOT: { id: product.id } }, take: 4, }); - const related = relatedRows.map((p) => toProductDTO(p, activePromotions)); + const related = relatedRows.map((p) => toProductDTO(p, activePromotions, 'plain')); return (