feat: map prix marché as compare_at_price (barré) on Shopify

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 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 14:19:37 +02:00
parent eb5f605175
commit 60dc9cc0ec
4 changed files with 12 additions and 5 deletions
+6 -3
View File
@@ -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,
+4 -1
View File
@@ -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<string
const variant: Record<string, unknown> = {
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 }],
},
}
+1 -1
View File
@@ -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,
+1
View File
@@ -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