feat(food): implement FoodController, FoodService, and related resources for managing food items and variants

refactor(catalog): add description and price fields to variants and update related resources

feat(migration): add commercial overrides to variants with description and price fields

test(food): add tests for FoodController and ensure correct seeding of food items and variants
This commit is contained in:
2026-08-07 14:17:51 -03:00
parent 6a6d3690cc
commit e1ad27ecf0
19 changed files with 725 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('variantes', function (Blueprint $table): void {
$table->text('descripcion')->nullable()->after('inventory_id');
$table->decimal('precio', 10, 2)->nullable()->after('descripcion');
});
DB::table('variantes')->orderBy('id')->each(function (object $variant): void {
$price = DB::table('catalog_items')
->where('id', $variant->catalog_item_id)
->value('precio');
DB::table('variantes')->where('id', $variant->id)->update([
'precio' => $price,
]);
});
}
public function down(): void
{
Schema::table('variantes', function (Blueprint $table): void {
$table->dropColumn(['descripcion', 'precio']);
});
}
};

View File

@@ -73,13 +73,20 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
$this->createProduct($tenant, [
'slug' => 'comida',
'nombre' => 'Comida',
'precio' => 8000,
'precio' => 4000,
'attribute_codes' => ['event_date', 'horario', 'servicio'],
'variants' => $dateIds
'variants' => $eventDates
->crossJoin(['Desayuno', 'Almuerzo', 'Cena'], ['Comedor', 'Vianda'])
->map(fn (array $values): array => [
'real_stock' => 0,
'event_date_ids' => [(int) $values[0]],
'event_date_ids' => [(int) $values[0]->id],
'descripcion' => sprintf(
'%s del %s - %s',
$values[1],
$values[0]->date->format('d/m/Y'),
$values[2],
),
'precio' => $this->foodPrice($values[1]),
'values' => ['horario' => $values[1], 'servicio' => $values[2]],
])->all(),
]);
@@ -128,4 +135,14 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
...$data,
]);
}
private function foodPrice(string $schedule): int
{
return match ($schedule) {
'Desayuno' => 4000,
'Almuerzo' => 10000,
'Cena' => 8000,
default => throw new RuntimeException("Horario de comida desconocido: {$schedule}"),
};
}
}