cambios menores

This commit is contained in:
Alejandro Tasistro 2024-03-14 22:49:24 -03:00
parent 09a024b69d
commit c746e41060
2 changed files with 13 additions and 15 deletions

View File

@ -21,7 +21,7 @@ public function run(): void
])->id;
Barrio::create([
'name'=>'PRUEBA','region_id'=>$prueba_id, 'created_at'=>Date::now()
'name'=>'PRUEBA','region_id' => $prueba_id
]);
}
}

View File

@ -37,16 +37,15 @@ public function run(): void
$tipo = trim($record[$tipoColumn]);
if (!in_array($tipo, $tipos)) {
if (!Str::contains($tipo,'¿') && ($tipo != 'T')) {
if (!Str::contains($tipo,'¿') && ($tipo != 'T'))
$currentCategoria = Categoria::firstOrCreate(['name' => $tipo]);
}
} else {
$parsed = $this->parseAndFormatName($record[$productoColumn]);
[$solidario, $name, $caracteristicas] = $this->parseAndFormatName($record[$productoColumn]);
$productosToInsert[] = [
'name' => $parsed['name'],
'name' => $name,
'price' => $record[$precioColumn],
'solidario' => $parsed['solidario'],
'solidario' => $solidario,
'bono' => $tipo == 'B',
'categoria_id' => $currentCategoria->id,
'created_at' => Date::now(),
@ -54,23 +53,22 @@ public function run(): void
];
$caracteristicasToInsert[] = [
'name' => $parsed['name'],
'caracteristicas' => $parsed['caracteristicas']
'name' => $name,
'caracteristicas' => $caracteristicas
];
}
}
foreach (array_chunk($productosToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) {
foreach (array_chunk($productosToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
DB::table('productos')->insert($chunk);
}
$this->insertCaracteristicas($caracteristicasToInsert);
}
/**
* Returns an array data parsed from productoColumn.
* Returns an array with data parsed from productoColumn.
*
* @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica)}
* @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica->id)}
*/
private function parseAndFormatName($productoColumn): array {
$solidario = Str::contains($productoColumn, '*');
@ -91,9 +89,9 @@ private function parseAndFormatName($productoColumn): array {
}
return [
'solidario' => $solidario,
'name' => trim($name),
'caracteristicas' => $caracteristicas
$solidario,
trim($name),
$caracteristicas
];
}