From 51632b16688cff1ae3cf38cee2342c6aab44b993 Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 1 Aug 2026 15:04:35 +0000 Subject: [PATCH] Fix wishlist items not saving: pass customerId into toggleWishlistItem The create POST omitted the customer relationship field entirely, so added items never matched getWishlist's customer-scoped query. Also scope the toggle-off fallback lookup to the current customer. Co-Authored-By: Claude Sonnet 5 --- app/api/account/wishlist/route.ts | 2 +- app/lib/customerAuth.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/api/account/wishlist/route.ts b/app/api/account/wishlist/route.ts index ccc4552..fec315f 100644 --- a/app/api/account/wishlist/route.ts +++ b/app/api/account/wishlist/route.ts @@ -20,7 +20,7 @@ export async function POST(request: Request) { return NextResponse.json({ ok: false, reason: "Ungültiges Produkt." }, { status: 400 }); } - const result = await toggleWishlistItem(session.token, productId, variant); + const result = await toggleWishlistItem(session.token, session.customer.id, productId, variant); if (!result.ok) return NextResponse.json({ ok: false, reason: "Merkliste konnte nicht aktualisiert werden." }, { status: 500 }); return NextResponse.json({ ok: true, wishlisted: result.wishlisted }); } diff --git a/app/lib/customerAuth.ts b/app/lib/customerAuth.ts index d1f7d49..af7358a 100644 --- a/app/lib/customerAuth.ts +++ b/app/lib/customerAuth.ts @@ -435,17 +435,19 @@ export async function getWishlist(token: string, customerId: number): Promise { const createRes = await fetch(`${PAYLOAD_URL}/api/wishlist-items`, { method: "POST", headers: { Authorization: `JWT ${token}`, "Content-Type": "application/json" }, - body: JSON.stringify({ product: productId, variant }), + body: JSON.stringify({ customer: customerId, product: productId, variant }), }); if (createRes.ok) return { ok: true, wishlisted: true }; const findParams = new URLSearchParams({ + "where[customer][equals]": String(customerId), "where[product][equals]": String(productId), "where[variant][equals]": variant, depth: "0",