1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
```
|