From 60dc9cc0ec1b1fc62da22d876a1676d8954bde6d Mon Sep 17 00:00:00 2001 From: Mathieu Date: Fri, 26 Jun 2026 14:19:37 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20map=20prix=20march=C3=A9=20as=20compare?= =?UTF-8?q?=5Fat=5Fprice=20(barr=C3=A9)=20on=20Shopify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When Prix remisé is set: price = remisé, compare_at_price = marché When no remise: price = marché, compare_at_price = null Diff now detects compareAtPrice changes to trigger updates Co-Authored-By: Claude Sonnet 4.6 --- src/lib/googleSheets.ts | 9 ++++++--- src/lib/shopifySync.ts | 5 ++++- src/lib/syncDiff.ts | 2 +- src/types/sync.ts | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/googleSheets.ts b/src/lib/googleSheets.ts index e606423..cfb4e34 100644 --- a/src/lib/googleSheets.ts +++ b/src/lib/googleSheets.ts @@ -59,7 +59,9 @@ export function parseSheetRows(rows: string[][]): SyncProduct[] { const publie = get(row, idx.publie).toLowerCase() const status = publie.includes('inac') || publie === 'non' || publie === 'false' ? 'draft' : 'active' - const prixRemise = get(row, idx.prixRemise).replace(',', '.') + const rawRemise = get(row, idx.prixRemise).replace(',', '.') + const prixRemise = parseFloat(rawRemise || '0') + const hasRemise = !isNaN(prixRemise) && prixRemise > 0 const longueur = get(row, idx.longueur) const largeur = get(row, idx.largeur) const specificFields = extractSpecificFields(headers, row) @@ -69,11 +71,12 @@ export function parseSheetRows(rows: string[][]): SyncProduct[] { handle: normalizeHandle(ref), title: get(row, idx.nom) || ref, description: '', - price: price.toFixed(2), + price: hasRemise ? prixRemise.toFixed(2) : price.toFixed(2), + compareAtPrice: hasRemise ? price.toFixed(2) : undefined, stock: parseInt(get(row, idx.stock) || '0', 10) || 0, weightKg: parseFloat(get(row, idx.poids).replace(',', '.') || '0') || undefined, status, - prixRemise: prixRemise || undefined, + prixRemise: hasRemise ? prixRemise.toFixed(2) : undefined, marque: get(row, idx.marque) || undefined, famille: get(row, idx.famille) || undefined, sousFamille: get(row, idx.sousFamille) || undefined, diff --git a/src/lib/shopifySync.ts b/src/lib/shopifySync.ts index 49185a5..24c6eff 100644 --- a/src/lib/shopifySync.ts +++ b/src/lib/shopifySync.ts @@ -20,6 +20,7 @@ export function getConfig() { interface ShopifyVariant { id: number price: string + compare_at_price: string | null sku: string inventory_quantity: number } @@ -42,6 +43,7 @@ function toSyncProduct(p: ShopifyAPIProduct): ShopifyProductFull { title: p.title, description: p.body_html ?? '', price: p.variants[0]?.price ?? '0.00', + compareAtPrice: p.variants[0]?.compare_at_price ?? undefined, stock: p.variants[0]?.inventory_quantity ?? 0, status: p.status === 'active' ? 'active' : 'draft', images: (p.images ?? []).map(i => i.src), @@ -93,6 +95,7 @@ export async function createShopifyProduct(product: SyncProduct): Promise = { price: product.price, + compare_at_price: product.compareAtPrice ?? null, sku: product.ref, inventory_management: 'shopify', } @@ -179,7 +182,7 @@ export async function updateShopifyProduct( title: product.title, body_html: product.description, status: product.status, - variants: [{ id: variantId, price: product.price }], + variants: [{ id: variantId, price: product.price, compare_at_price: product.compareAtPrice ?? null }], }, } diff --git a/src/lib/syncDiff.ts b/src/lib/syncDiff.ts index 8036da7..a0f331f 100644 --- a/src/lib/syncDiff.ts +++ b/src/lib/syncDiff.ts @@ -1,6 +1,6 @@ import type { SyncProduct, ShopifyProductFull, SyncChange, DiffResult } from '@/types/sync' -const COMPARABLE_FIELDS = ['title', 'description', 'price', 'status'] as const +const COMPARABLE_FIELDS = ['title', 'description', 'price', 'compareAtPrice', 'status'] as const function getChangedFields( sheet: SyncProduct, diff --git a/src/types/sync.ts b/src/types/sync.ts index c0a021f..7479ac4 100644 --- a/src/types/sync.ts +++ b/src/types/sync.ts @@ -10,6 +10,7 @@ export interface SyncProduct { stock: number // colonne E weightKg?: number // poids en kg pour l'expédition status: 'active' | 'draft' // colonne F : "inactif"/"inactif" → draft, tout autre → active + compareAtPrice?: string // Champs enrichis prixRemise?: string marque?: string