refactor: integrate category handling for entries and food items in services and tests
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Domains\FiestaFutbolInfantil\Services;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Catalog\Services\CatalogService;
|
||||
@@ -26,10 +27,14 @@ class EntryService
|
||||
{
|
||||
return DB::transaction(function () use ($tenant, $entries): Collection {
|
||||
$reservedSlugs = [];
|
||||
$category = Category::query()->firstOrCreate([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Entradas',
|
||||
]);
|
||||
|
||||
return collect($entries)->map(function (array $entry, int $index) use ($tenant, &$reservedSlugs): CatalogItem {
|
||||
return collect($entries)->map(function (array $entry, int $index) use ($tenant, $category, &$reservedSlugs): CatalogItem {
|
||||
if (isset($entry['id'])) {
|
||||
return $this->update($tenant, $entry, $index);
|
||||
return $this->update($tenant, $category, $entry, $index);
|
||||
}
|
||||
|
||||
$slug = $this->uniqueSlug($tenant, $entry['title'], $reservedSlugs);
|
||||
@@ -40,6 +45,7 @@ class EntryService
|
||||
'slug' => $slug,
|
||||
'nombre' => $entry['title'],
|
||||
'descripcion' => $entry['description'] ?? null,
|
||||
'category_id' => $category->id,
|
||||
'precio' => $entry['price'],
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'has_tickets' => true,
|
||||
@@ -56,7 +62,7 @@ class EntryService
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $entry */
|
||||
private function update(Tenant $tenant, array $entry, int $index): CatalogItem
|
||||
private function update(Tenant $tenant, Category $category, array $entry, int $index): CatalogItem
|
||||
{
|
||||
$catalogItem = CatalogItem::query()
|
||||
->whereKey($entry['id'])
|
||||
@@ -100,6 +106,7 @@ class EntryService
|
||||
$catalogItem->update([
|
||||
'nombre' => $entry['title'],
|
||||
'descripcion' => $entry['description'] ?? null,
|
||||
'category_id' => $category->id,
|
||||
'precio' => $entry['price'],
|
||||
'has_tickets' => true,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
|
||||
Reference in New Issue
Block a user