traduccion canasta

This commit is contained in:
Alejandro Tasistro 2024-07-03 19:23:24 -03:00
parent 2a35fd85a9
commit ccfdb4bf11
1 changed files with 20 additions and 20 deletions

View File

@ -38,14 +38,14 @@ public function run(): void
if (!in_array($tipo, $tipos)) {
if (!Str::contains($tipo,'¿') && ($tipo != 'T')) {
$currentCategoria = Categoria::firstOrCreate(['name' => $tipo]);
$currentCategoria = Categoria::firstOrCreate(['nombre' => $tipo]);
}
} else {
$parsed = $this->parseAndFormatName($record[$productoColumn]);
$productosToInsert[] = [
'name' => $parsed['name'],
'price' => $record[$precioColumn],
'nombre' => $parsed['nombre'],
'precio' => $record[$precioColumn],
'solidario' => $parsed['solidario'],
'bono' => $tipo == 'B',
'categoria_id' => $currentCategoria->id,
@ -54,7 +54,7 @@ public function run(): void
];
$caracteristicasToInsert[] = [
'name' => $parsed['name'],
'nombre' => $parsed['nombre'],
'caracteristicas' => $parsed['caracteristicas']
];
}
@ -70,39 +70,39 @@ public function run(): void
/**
* Returns an array data parsed from productoColumn.
*
* @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica)}
* @return array{solidario: bool, nombre: string, caracteristicas: array(Caracteristica)}
*/
private function parseAndFormatName($productoColumn): array {
$solidario = Str::contains($productoColumn, '*');
$name = Str::replace('*','',$productoColumn);
$nombre = Str::replace('*','',$productoColumn);
$caracteristicas = [];
if (Str::contains($name, 'S-G'))
$caracteristicas[] = Caracteristica::where('key','S-G')->first()->id;
if (Str::contains($name, 'S-A'))
$caracteristicas[] = Caracteristica::where('key','S-A')->first()->id;
if (Str::contains($name, 'S-S'))
$caracteristicas[] = Caracteristica::where('key','S-S')->first()->id;
if (Str::contains($name, 'S-P-A'))
$caracteristicas[] = Caracteristica::where('key','S-P-A')->first()->id;
if (Str::contains($nombre, 'S-G'))
$caracteristicas[] = Caracteristica::where('codigo','S-G')->first()->id;
if (Str::contains($nombre, 'S-A'))
$caracteristicas[] = Caracteristica::where('codigo','S-A')->first()->id;
if (Str::contains($nombre, 'S-S'))
$caracteristicas[] = Caracteristica::where('codigo','S-S')->first()->id;
if (Str::contains($nombre, 'S-P-A'))
$caracteristicas[] = Caracteristica::where('codigo','S-P-A')->first()->id;
if ($caracteristicas) {
$name = Str::replaceMatches('/\(S\-.*\)/', '', $name);
$nombre = Str::replaceMatches('/\(S\-.*\)/', '', $nombre);
}
return [
'solidario' => $solidario,
'name' => trim($name),
'nombre' => trim($nombre),
'caracteristicas' => $caracteristicas
];
}
private function insertCaracteristicas($caracteristicasToInsert) : void {
foreach ($caracteristicasToInsert as $key => $item) {
$name = $item['name'];
$match = Producto::where('name',$name)->first();
foreach ($caracteristicasToInsert as $codigo => $item) {
$nombre = $item['nombre'];
$match = Producto::where('nombre',$nombre)->first();
if ($match) {
foreach ($item['caracteristicas'] as $key => $caracteristica) {
foreach ($item['caracteristicas'] as $codigo => $caracteristica) {
DB::table('productos_caracteristicas')->insert([
'producto_id' => $match->id,
'caracteristica_id' => $caracteristica,