Fix importazione categorie articoli

This commit is contained in:
Beppe 2020-10-02 16:45:09 +02:00
parent 1b66a888b1
commit 8bb03984cd
1 changed files with 10 additions and 10 deletions

View File

@ -82,7 +82,7 @@ class CSV extends CSVImporter
], ],
], ],
[ [
'field' => 'categoria', 'field' => 'id_categoria',
'label' => 'Categoria', 'label' => 'Categoria',
'names' => [ 'names' => [
'Categoria', 'Categoria',
@ -91,7 +91,7 @@ class CSV extends CSVImporter
], ],
], ],
[ [
'field' => 'sottocategoria', 'field' => 'id_sottocategoria',
'label' => 'Sottocategoria', 'label' => 'Sottocategoria',
'names' => [ 'names' => [
'Sottocategoria', 'Sottocategoria',
@ -147,29 +147,29 @@ class CSV extends CSVImporter
} }
// Gestione categoria e sottocategoria // Gestione categoria e sottocategoria
if (!empty($record['categoria'])) { if (!empty($record['id_categoria'])) {
// Categoria // Categoria
$categoria = Categoria::where('nome', $record['categoria'])->first(); $categoria = Categoria::where('nome', $record['id_categoria'])->first();
if (empty($categoria)) { if (empty($categoria)) {
$categoria = Categoria::build($record['categoria']); $categoria = Categoria::build($record['id_categoria']);
} }
// Sotto-categoria // Sotto-categoria
$sottocategoria = null; $sottocategoria = null;
if (!empty($record['sottocategoria'])) { if (!empty($record['id_sottocategoria'])) {
$sottocategoria = Categoria::where('nome', $record['sottocategoria']) $sottocategoria = Categoria::where('nome', $record['id_sottocategoria'])
->where('parent', $categoria->id) ->where('parent', $categoria->id)
->first(); ->first();
if (empty($sottocategoria)) { if (empty($sottocategoria)) {
$sottocategoria = Categoria::build($record['categoria']); $sottocategoria = Categoria::build($record['id_categoria']);
$sottocategoria->parent()->associate($categoria); $sottocategoria->parent()->associate($categoria);
$sottocategoria->save(); $sottocategoria->save();
} }
} }
} }
unset($record['categoria']); unset($record['id_categoria']);
unset($record['sottocategoria']); unset($record['id_sottocategoria']);
// Individuazione dell'IVA di vendita tramite il relativo Codice // Individuazione dell'IVA di vendita tramite il relativo Codice
$aliquota = null; $aliquota = null;