feat: collection picker in product creation flow

- API /api/creation/collections liste toutes les collections Shopify
- Détection automatique depuis la colonne ID FAMILLE du Sheets
- Sélecteur avec recherche si absente ou pour modifier
- Collection affichée dans l'écran de confirmation
- collectionOverride passé à l'exécution comme fallback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-24 16:12:54 +02:00
parent 9e7423eee3
commit 8c9bce7aa5
3 changed files with 134 additions and 4 deletions
+32
View File
@@ -0,0 +1,32 @@
import { NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
const API_VERSION = '2024-01'
export async function GET() {
const session = await getServerSession(authOptions)
if (!session) return NextResponse.json({ error: 'Non authentifié' }, { status: 401 })
const domain = process.env.SHOPIFY_STORE_DOMAIN
const token = process.env.SHOPIFY_ADMIN_API_TOKEN
if (!domain || !token) return NextResponse.json({ error: 'Config Shopify manquante' }, { status: 500 })
const baseUrl = `https://${domain}/admin/api/${API_VERSION}`
const headers = { 'X-Shopify-Access-Token': token, 'Content-Type': 'application/json' }
// Récupère custom collections + smart collections
const [customRes, smartRes] = await Promise.all([
fetch(`${baseUrl}/custom_collections.json?limit=250&fields=id,title`, { headers }),
fetch(`${baseUrl}/smart_collections.json?limit=250&fields=id,title`, { headers }),
])
const custom = customRes.ok ? (await customRes.json()).custom_collections as { id: number; title: string }[] : []
const smart = smartRes.ok ? (await smartRes.json()).smart_collections as { id: number; title: string }[] : []
const collections = [...custom, ...smart]
.map(c => ({ id: String(c.id), title: c.title }))
.sort((a, b) => a.title.localeCompare(b.title))
return NextResponse.json({ collections })
}
+4 -2
View File
@@ -20,9 +20,10 @@ export async function POST(req: NextRequest) {
}
const userId = (session.user as { id: string }).id
const body = await req.json().catch(() => ({})) as { resolutions?: MetafieldResolution[]; tab?: string }
const body = await req.json().catch(() => ({})) as { resolutions?: MetafieldResolution[]; tab?: string; collectionOverride?: string }
const resolutions: MetafieldResolution[] = body.resolutions ?? []
const tabFilter: string | undefined = body.tab ?? undefined
const collectionOverride: string | undefined = body.collectionOverride ?? undefined
const resolutionMap = new Map<string, MetafieldResolution>(resolutions.map(r => [r.columnHeader, r]))
const stream = new ReadableStream({
@@ -83,7 +84,8 @@ export async function POST(req: NextRequest) {
weightKg: product.weightKg,
status: 'active',
})
if (product.collectionId) await addProductToCollection(shopifyId, product.collectionId)
const effectiveCollectionId = product.collectionId || collectionOverride || ''
if (effectiveCollectionId) await addProductToCollection(shopifyId, effectiveCollectionId)
if (product.subCollectionId) await addProductToCollection(shopifyId, product.subCollectionId)
send({ type: 'progress', current: i + 1, total, tab: product.tab, title: product.title, step: 'Métachamps…' })
for (const [colHeader, value] of Object.entries(product.specificFields)) {