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 <noreply@anthropic.com>
This commit is contained in:
Marco
2026-08-01 15:04:35 +00:00
parent d010a3aff1
commit 51632b1668
2 changed files with 4 additions and 2 deletions
+3 -1
View File
@@ -435,17 +435,19 @@ export async function getWishlist(token: string, customerId: number): Promise<Wi
// toggle (the common case, adding something new, only needs one request).
export async function toggleWishlistItem(
token: string,
customerId: number,
productId: number,
variant: string,
): Promise<{ ok: true; wishlisted: boolean } | { ok: false }> {
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",