fix: recherche produit via Google Sheets (UGS col C → Shopify ID col A) + fallback Shopify
This commit is contained in:
+15
-5
@@ -57,6 +57,19 @@ export function useImages() {
|
||||
async (id: string, ref: string) => {
|
||||
update(id, { status: 'searching' })
|
||||
try {
|
||||
// 1. Cherche d'abord dans Google Sheets (col C = UGS → col A = Shopify ID)
|
||||
const sheetsRes = await fetch(`/api/products/search-sheets?ref=${encodeURIComponent(ref)}`)
|
||||
const sheetsData = await sheetsRes.json()
|
||||
if (sheetsData.found) {
|
||||
update(id, {
|
||||
status: 'ready',
|
||||
shopifyProductId: sheetsData.shopifyId,
|
||||
shopifyProductTitle: sheetsData.title,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 2. Fallback : recherche directe dans Shopify par handle/titre
|
||||
const res = await fetch(`/api/products/search?ref=${encodeURIComponent(ref)}`)
|
||||
const data = await res.json()
|
||||
if (data.found) {
|
||||
@@ -88,11 +101,8 @@ export function useImages() {
|
||||
try {
|
||||
update(id, { status: 'converting' })
|
||||
jpegBlob = await convertHeicToJpeg(blob)
|
||||
// Met à jour l'aperçu original avec le JPEG converti (Chrome ne peut pas afficher HEIC)
|
||||
update(id, {
|
||||
originalBlob: jpegBlob,
|
||||
originalUrl: URL.createObjectURL(jpegBlob),
|
||||
})
|
||||
// Met à jour originalBlob avec le JPEG converti (Chrome ne peut pas afficher HEIC)
|
||||
update(id, { originalBlob: jpegBlob })
|
||||
} catch (err) {
|
||||
update(id, { status: 'error', error: `Conversion HEIC : ${(err as Error).message}` })
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user