fix: importar excel
This commit is contained in:
parent
fa8bea2060
commit
08871b8dde
@ -12,7 +12,7 @@
|
||||
use Maatwebsite\Excel\Concerns\Importable;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
/**
|
||||
* Import de productos desde Excel
|
||||
@ -26,7 +26,7 @@
|
||||
* - precio_venta: Precio de venta (requerido, mayor que costo)
|
||||
* - impuesto: Porcentaje de impuesto (opcional, 0-100)
|
||||
*/
|
||||
class ProductsImport implements ToModel, WithHeadingRow, WithValidation, WithChunkReading, SkipsEmptyRows
|
||||
class ProductsImport implements ToModel, WithHeadingRow, WithValidation, WithChunkReading, SkipsEmptyRows, WithMapping
|
||||
{
|
||||
use Importable;
|
||||
|
||||
@ -34,6 +34,23 @@ class ProductsImport implements ToModel, WithHeadingRow, WithValidation, WithChu
|
||||
private $imported = 0;
|
||||
private $skipped = 0;
|
||||
|
||||
/**
|
||||
* Mapea y transforma los datos de cada fila antes de la validación
|
||||
*/
|
||||
public function map($row): array
|
||||
{
|
||||
return [
|
||||
'nombre' => $row['nombre'] ?? null,
|
||||
'sku' => isset($row['sku']) ? (string) $row['sku'] : null,
|
||||
'codigo_barras' => isset($row['codigo_barras']) ? (string) $row['codigo_barras'] : null,
|
||||
'categoria' => $row['categoria'] ?? null,
|
||||
'stock' => $row['stock'] ?? null,
|
||||
'costo' => $row['costo'] ?? null,
|
||||
'precio_venta' => $row['precio_venta'] ?? null,
|
||||
'impuesto' => $row['impuesto'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Procesa cada fila del Excel
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user