feat: replace product search with searchable combobox in banner builder

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 10:35:27 +02:00
parent f650225c98
commit 34ec818ad3
2 changed files with 124 additions and 25 deletions
+42
View File
@@ -0,0 +1,42 @@
import { NextRequest, NextResponse } from 'next/server'
const API_VERSION = '2024-01'
// GET /api/products/search-list?q=peinture
// Retourne jusqu'à 10 produits correspondant à la recherche (titre ou SKU)
export async function GET(req: NextRequest) {
const q = new URL(req.url).searchParams.get('q')?.trim()
if (!q || q.length < 2) return NextResponse.json([])
const domain = process.env.SHOPIFY_STORE_DOMAIN
const token = process.env.SHOPIFY_ADMIN_API_TOKEN
if (!domain || !token) return NextResponse.json([], { status: 500 })
const headers = { 'X-Shopify-Access-Token': token }
const baseUrl = `https://${domain}/admin/api/${API_VERSION}`
try {
// Recherche par titre
const res = await fetch(
`${baseUrl}/products.json?title=${encodeURIComponent(q)}&limit=10&fields=id,title,variants`,
{ headers },
)
if (!res.ok) return NextResponse.json([])
const data = await res.json()
const products = (data.products ?? []) as Array<{
id: number
title: string
variants: Array<{ sku: string }>
}>
const results = products.map(p => ({
shopifyId: String(p.id),
title: p.title,
sku: p.variants[0]?.sku ?? '',
}))
return NextResponse.json(results)
} catch {
return NextResponse.json([])
}
}