Skip to content

Commit f30ff8d

Browse files
Merge pull request #417 from DevLoversTeam/lso/feat/shop-legal
(SP: 3) [SHOP] complete merch-ready PDP with multi-image gallery and size guidance
2 parents a447890 + b0c6d31 commit f30ff8d

47 files changed

Lines changed: 11360 additions & 465 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/app/[locale]/admin/shop/products/[id]/edit/page.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { eq } from 'drizzle-orm';
21
import { Metadata } from 'next';
32
import { notFound } from 'next/navigation';
43
import { z } from 'zod';
54

6-
import { db } from '@/db';
7-
import { productPrices, products } from '@/db/schema';
5+
import { ProductNotFoundError } from '@/lib/errors/products';
86
import { issueCsrfToken } from '@/lib/security/csrf';
7+
import { getAdminProductByIdWithPrices } from '@/lib/services/products';
98
import type { CurrencyCode } from '@/lib/shop/currency';
109
import { currencyValues } from '@/lib/shop/currency';
1110

@@ -37,22 +36,18 @@ export default async function EditProductPage({
3736
const parsed = paramsSchema.safeParse(rawParams);
3837
if (!parsed.success) notFound();
3938

40-
const [product] = await db
41-
.select()
42-
.from(products)
43-
.where(eq(products.id, parsed.data.id))
44-
.limit(1);
39+
let product;
40+
try {
41+
product = await getAdminProductByIdWithPrices(parsed.data.id);
42+
} catch (error) {
43+
if (error instanceof ProductNotFoundError) {
44+
notFound();
45+
}
4546

46-
if (!product) notFound();
47+
throw error;
48+
}
4749

48-
const prices = await db
49-
.select({
50-
currency: productPrices.currency,
51-
price: productPrices.price,
52-
originalPrice: productPrices.originalPrice,
53-
})
54-
.from(productPrices)
55-
.where(eq(productPrices.productId, product.id));
50+
const prices = product.prices;
5651

5752
const initialPrices = prices.length
5853
? prices
@@ -98,6 +93,7 @@ export default async function EditProductPage({
9893
stock: product.stock,
9994
sku: product.sku ?? undefined,
10095
imageUrl: product.imageUrl,
96+
images: product.images,
10197
}}
10298
/>
10399
</main>

0 commit comments

Comments
 (0)