From aa494fd8e24b0aabcc890655370a15358f9e6755 Mon Sep 17 00:00:00 2001 From: ertopogo Date: Thu, 5 Feb 2026 23:48:50 +0100 Subject: WIP: prepare import csv --- DOC_IMPORT_PRODUITS.md | 193 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 DOC_IMPORT_PRODUITS.md (limited to 'DOC_IMPORT_PRODUITS.md') diff --git a/DOC_IMPORT_PRODUITS.md b/DOC_IMPORT_PRODUITS.md new file mode 100644 index 0000000..b41cba8 --- /dev/null +++ b/DOC_IMPORT_PRODUITS.md @@ -0,0 +1,193 @@ +# Import CSV Produits (Medusa) + +## FR - Objectif +Importer des produits depuis un CSV dans Medusa en mode upsert (creation ou mise a jour) sur le champ `external_id`. + +## FR - Prerequis +- Backend Medusa operationnel +- Dependances installees (`npm install` dans `backend/`) +- Fichier CSV present dans `backend/data/products-import.csv` (ou un autre chemin) + +## FR - Commande rapide +Depuis `backend/` : +``` +npm run import:products +``` + +Options: +``` +node scripts/import-products.js --file ./data/products-import.csv --report ./data/import-report.json +node scripts/import-products.js --file ./data/products-import.csv --dry-run +node scripts/import-products.js --file ./data/products-import.csv --currency eur +``` + +## FR - Schema CSV +Colonnes minimales: +- `external_id` (obligatoire, cle d'upsert) +- `title` (obligatoire) +- `handle` (optionnel, genere depuis title si absent) +- `description` (optionnel) +- `thumbnail` (optionnel) +- `option_title` (optionnel, defaut: Taille) +- `option_value` (optionnel, defaut: variant_title) +- `variant_title` (optionnel, defaut: option_value) +- `variant_sku` (optionnel) +- `price_amount` (obligatoire, entier en centimes) +- `currency_code` (optionnel, defaut: eur) +- `inventory_quantity` (optionnel, defaut: 0) +- `manage_inventory` (optionnel, true/false) + +Exemple: +``` +external_id,title,handle,description,thumbnail,option_title,option_value,variant_title,variant_sku,price_amount,currency_code,inventory_quantity,manage_inventory +prod-001,Savon Lavande,savon-lavande,"Savon artisanal a la lavande.",https://via.placeholder.com/600x600.png?text=Savon+Lavande,Taille,100g,100g,SKU-SAV-100,650,eur,100,true +``` + +## FR - Comportement +- Un produit est trouve par `external_id`. +- Si `external_id` existe: mise a jour du produit. +- Si `external_id` n'existe pas: creation du produit. +- Une ligne CSV = une variante. Regrouper plusieurs variantes avec le meme `external_id`. +- Une seule option produit est supportee dans ce script (ex: Taille). + +## FR - Git flow (branche + push) +Nom de branche suggere: `feature/import-csv-produits` + +Commandes type: +``` +git flow feature start import-csv-produits +git status +git add backend/scripts/import-products.js backend/data/products-import.csv backend/package.json DOC_IMPORT_PRODUITS.md helper-cmd.md DOC_TECHNIQUE.md +git commit -m "Add product CSV import script and docs" +git push -u chillka feature/import-csv-produits +``` + +Selon votre process: +``` +git flow feature finish import-csv-produits +``` + +## FR - Troubleshoot git-flow +**Erreur**: `Fatal: Working tree contains unstaged changes. Aborting.` + +Cause: git-flow exige un working tree propre. + +Actions: +``` +git status +git add -A +git commit -m "WIP: prepare import CSV" +git flow init -d +``` + +Alternative (mettre de cote): +``` +git stash -u +git flow init -d +git stash pop +``` + +**Erreur**: `git: 'flow' is not a git command` + +Installe git-flow: +``` +sudo apt update +sudo apt install git-flow +``` + +--- + +## DE - Ziel +Produkte per CSV in Medusa importieren, mit Upsert per `external_id` (anlegen oder aktualisieren). + +## DE - Voraussetzungen +- Medusa Backend laeuft +- Abhaengigkeiten installiert (`npm install` in `backend/`) +- CSV Datei in `backend/data/products-import.csv` (oder eigener Pfad) + +## DE - Schnellstart +Aus `backend/`: +``` +npm run import:products +``` + +Optionen: +``` +node scripts/import-products.js --file ./data/products-import.csv --report ./data/import-report.json +node scripts/import-products.js --file ./data/products-import.csv --dry-run +node scripts/import-products.js --file ./data/products-import.csv --currency eur +``` + +## DE - CSV Schema +Pflichtspalten: +- `external_id` (Pflicht, Upsert-Schluessel) +- `title` (Pflicht) +- `handle` (optional, wird aus title erzeugt) +- `description` (optional) +- `thumbnail` (optional) +- `option_title` (optional, Default: Taille) +- `option_value` (optional, Default: variant_title) +- `variant_title` (optional, Default: option_value) +- `variant_sku` (optional) +- `price_amount` (Pflicht, integer in Cent) +- `currency_code` (optional, Default: eur) +- `inventory_quantity` (optional, Default: 0) +- `manage_inventory` (optional, true/false) + +Beispiel: +``` +external_id,title,handle,description,thumbnail,option_title,option_value,variant_title,variant_sku,price_amount,currency_code,inventory_quantity,manage_inventory +prod-001,Savon Lavande,savon-lavande,"Savon artisanal a la lavande.",https://via.placeholder.com/600x600.png?text=Savon+Lavande,Taille,100g,100g,SKU-SAV-100,650,eur,100,true +``` + +## DE - Verhalten +- Produkt wird per `external_id` gefunden. +- Wenn `external_id` existiert: Produkt wird aktualisiert. +- Wenn `external_id` nicht existiert: Produkt wird angelegt. +- Eine CSV Zeile = eine Variante. Mehrere Varianten mit gleichem `external_id` gruppieren. +- Nur eine Produktoption ist in diesem Script vorgesehen (z.B. Taille). + +## DE - Git flow (Branch + Push) +Branch Vorschlag: `feature/import-csv-produits` + +Typische Befehle: +``` +git flow feature start import-csv-produits +git status +git add backend/scripts/import-products.js backend/data/products-import.csv backend/package.json DOC_IMPORT_PRODUITS.md helper-cmd.md DOC_TECHNIQUE.md +git commit -m "Add product CSV import script and docs" +git push -u chillka feature/import-csv-produits +``` + +Optional nach Prozess: +``` +git flow feature finish import-csv-produits +``` + +## DE - Troubleshooting git-flow +**Fehler**: `Fatal: Working tree contains unstaged changes. Aborting.` + +Ursache: git-flow braucht ein sauberes Working Tree. + +Schritte: +``` +git status +git add -A +git commit -m "WIP: prepare import CSV" +git flow init -d +``` + +Alternative (parken): +``` +git stash -u +git flow init -d +git stash pop +``` + +**Fehler**: `git: 'flow' is not a git command` + +git-flow installieren: +``` +sudo apt update +sudo apt install git-flow +``` -- cgit v1.2.3