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