feat: remove EventProductType references and related logic from catalog and fiesta futbol infantil components
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Enums;
|
||||
|
||||
enum EventProductType: string
|
||||
{
|
||||
case Entry = 'entrada';
|
||||
case Product = 'producto';
|
||||
|
||||
/** @return list<string> */
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace App\Domains\Catalog\Models;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Services\CatalogInventoryService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
@@ -20,7 +19,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
#[Fillable([
|
||||
'tenant_code',
|
||||
'event_product_type',
|
||||
'category_id',
|
||||
'brand_id',
|
||||
'inventory_id',
|
||||
@@ -54,7 +52,6 @@ class CatalogItem extends Model
|
||||
'category_id' => 'integer',
|
||||
'brand_id' => 'integer',
|
||||
'inventory_id' => 'integer',
|
||||
'event_product_type' => EventProductType::class,
|
||||
'type' => CatalogItemType::class,
|
||||
'precio' => 'decimal:2',
|
||||
'inventory_policy' => InventoryPolicy::class,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Domains\Catalog\Requests;
|
||||
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Shared\Rules\ImageOrBase64Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
@@ -26,11 +25,6 @@ class StoreCatalogItemRequest extends FormRequest
|
||||
return [
|
||||
'tenant_code' => ['prohibited'],
|
||||
'type' => ['sometimes', Rule::enum(CatalogItemType::class)],
|
||||
'event_product_type' => [
|
||||
'sometimes',
|
||||
'nullable',
|
||||
Rule::enum(EventProductType::class),
|
||||
],
|
||||
'category_id' => [
|
||||
'sometimes',
|
||||
'nullable',
|
||||
|
||||
@@ -24,7 +24,6 @@ class CatalogItemDetailResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type->value,
|
||||
'event_product_type' => $this->event_product_type?->value,
|
||||
'category_id' => $this->category_id,
|
||||
'brand_id' => $this->brand_id,
|
||||
'slug' => $this->slug,
|
||||
|
||||
@@ -16,7 +16,6 @@ class CatalogItemResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type->value,
|
||||
'event_product_type' => $this->event_product_type?->value,
|
||||
'category_id' => $this->category_id,
|
||||
'brand_id' => $this->brand_id,
|
||||
'slug' => $this->slug,
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Domains\Catalog\Services;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Attachable\Services\AttachmentService;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
@@ -65,7 +64,6 @@ class CatalogService
|
||||
]);
|
||||
}
|
||||
|
||||
$this->validateEventProductType($data);
|
||||
$this->validateUniqueVariantCombinations($variants, $attributeCodes);
|
||||
|
||||
if ($type === CatalogItemType::Bundle) {
|
||||
@@ -622,22 +620,6 @@ class CatalogService
|
||||
return $variant;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data */
|
||||
private function validateEventProductType(array $data): void
|
||||
{
|
||||
$eventProductType = $data['event_product_type'] ?? null;
|
||||
|
||||
if ($eventProductType === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array($eventProductType, EventProductType::values(), true)) {
|
||||
throw ValidationException::withMessages([
|
||||
'event_product_type' => [__('api.catalog.invalid_event_product_type')],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $variants
|
||||
* @param array<int, string> $attributeCodes
|
||||
|
||||
@@ -29,7 +29,11 @@ class UpsertEntriesRequest extends FormRequest
|
||||
Rule::exists('catalog_items', 'id')->where(
|
||||
fn ($query) => $query
|
||||
->where('tenant_code', $tenantCode)
|
||||
->where('event_product_type', 'entrada')
|
||||
->whereIn('category_id', fn ($categoryQuery) => $categoryQuery
|
||||
->select('id')
|
||||
->from('categorias')
|
||||
->where('tenant_code', $tenantCode)
|
||||
->where('nombre', 'Entradas'))
|
||||
),
|
||||
],
|
||||
'entries.*.title' => ['required', 'string', 'max:255'],
|
||||
|
||||
@@ -28,7 +28,11 @@ class UpsertMerchandiseRequest extends FormRequest
|
||||
Rule::exists('catalog_items', 'id')->where(
|
||||
fn ($query) => $query
|
||||
->where('tenant_code', $tenantCode)
|
||||
->where('event_product_type', 'producto')
|
||||
->whereIn('category_id', fn ($categoryQuery) => $categoryQuery
|
||||
->select('id')
|
||||
->from('categorias')
|
||||
->where('tenant_code', $tenantCode)
|
||||
->where('nombre', 'Merchandising'))
|
||||
),
|
||||
],
|
||||
'items.*.title' => ['required', 'string', 'max:255'],
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Domains\FiestaFutbolInfantil\Services;
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
@@ -135,7 +134,6 @@ class AccommodationService
|
||||
if ($accommodation !== null) {
|
||||
$accommodation->update([
|
||||
'category_id' => $category->id,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'has_tickets' => true,
|
||||
]);
|
||||
@@ -150,7 +148,6 @@ class AccommodationService
|
||||
'descripcion' => 'Alojamiento',
|
||||
'category_id' => $category->id,
|
||||
'precio' => collect($variants)->min('price') ?? 0,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'has_tickets' => true,
|
||||
'inventory_id' => null,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
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;
|
||||
@@ -24,7 +23,7 @@ class EntryService
|
||||
{
|
||||
return CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('event_product_type', EventProductType::Entry->value)
|
||||
->whereHas('category', fn ($query) => $query->where('nombre', 'Entradas'))
|
||||
->with([
|
||||
'variants.inventory',
|
||||
'variants.eventDate',
|
||||
@@ -62,7 +61,6 @@ class EntryService
|
||||
'descripcion' => $entry['description'] ?? null,
|
||||
'category_id' => $category->id,
|
||||
'precio' => $entry['price'],
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'has_tickets' => true,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'attribute_codes' => ['event_date'],
|
||||
@@ -81,7 +79,6 @@ class EntryService
|
||||
$entry = CatalogItem::query()
|
||||
->whereKey($entryId)
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('event_product_type', EventProductType::Entry->value)
|
||||
->whereHas('category', fn ($query) => $query->where('nombre', 'Entradas'))
|
||||
->firstOrFail();
|
||||
|
||||
@@ -94,7 +91,7 @@ class EntryService
|
||||
$catalogItem = CatalogItem::query()
|
||||
->whereKey($entry['id'])
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('event_product_type', EventProductType::Entry->value)
|
||||
->whereHas('category', fn ($query) => $query->where('nombre', 'Entradas'))
|
||||
->lockForUpdate()
|
||||
->firstOrFail();
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Domains\FiestaFutbolInfantil\Services;
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
@@ -146,7 +145,6 @@ class FoodService
|
||||
if ($food !== null) {
|
||||
$food->update([
|
||||
'category_id' => $category->id,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'has_tickets' => true,
|
||||
]);
|
||||
@@ -161,7 +159,6 @@ class FoodService
|
||||
'descripcion' => 'Comida',
|
||||
'category_id' => $category->id,
|
||||
'precio' => collect($variants)->min('price') ?? 0,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'has_tickets' => true,
|
||||
'inventory_id' => null,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Domains\FiestaFutbolInfantil\Services;
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
@@ -29,7 +28,6 @@ class MerchandiseService
|
||||
{
|
||||
return CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('event_product_type', EventProductType::Product->value)
|
||||
->whereHas('category', fn ($query) => $query->where('nombre', 'Merchandising'))
|
||||
->with([
|
||||
'itemAttributes.attribute.options',
|
||||
@@ -74,7 +72,6 @@ class MerchandiseService
|
||||
'descripcion' => $data['description'] ?? null,
|
||||
'category_id' => $category->id,
|
||||
'max_units_per_user' => (int) $data['max_units_per_user'],
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'has_tickets' => true,
|
||||
]);
|
||||
@@ -129,7 +126,6 @@ class MerchandiseService
|
||||
->whereKey($merchandiseId)
|
||||
->whereHas('catalogItem', fn ($query) => $query
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('event_product_type', EventProductType::Product->value)
|
||||
->whereHas('category', fn ($categoryQuery) => $categoryQuery
|
||||
->where('nombre', 'Merchandising')))
|
||||
->firstOrFail();
|
||||
@@ -170,7 +166,6 @@ class MerchandiseService
|
||||
->whereKey($itemId)
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('category_id', $category->id)
|
||||
->where('event_product_type', EventProductType::Product->value)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
@@ -201,7 +196,6 @@ class MerchandiseService
|
||||
'category_id' => $category->id,
|
||||
'precio' => collect($data['variants'])->min('price') ?? 0,
|
||||
'max_units_per_user' => (int) $data['max_units_per_user'],
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
'has_tickets' => true,
|
||||
'inventory_id' => null,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@@ -43,9 +42,6 @@ return new class extends Migration
|
||||
->after('tenant_code')
|
||||
->constrained('events')
|
||||
->nullOnDelete();
|
||||
$table->enum('event_product_type', EventProductType::values())
|
||||
->nullable()
|
||||
->after('event_id');
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
@@ -71,7 +67,6 @@ return new class extends Migration
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
$table->dropColumn('event_product_type');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('event_dates');
|
||||
|
||||
@@ -14,9 +14,14 @@ return new class extends Migration
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$entryCategoryIds = DB::table('categorias')
|
||||
->select('id')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->where('nombre', 'Entradas');
|
||||
|
||||
DB::table('catalog_items')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->where('event_product_type', 'producto')
|
||||
->whereNotIn('category_id', $entryCategoryIds)
|
||||
->update(['has_tickets' => false]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasColumn('catalog_items', 'event_product_type')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropColumn('event_product_type');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasColumn('catalog_items', 'event_product_type')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->enum('event_product_type', ['entrada', 'producto'])
|
||||
->nullable()
|
||||
->after('tenant_code');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
@@ -109,7 +108,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
'nombre' => 'Abono',
|
||||
'category_id' => $categories['entradas']->id,
|
||||
'precio' => 40000,
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'has_tickets' => true,
|
||||
'attribute_codes' => ['event_date'],
|
||||
'multi_select_attribute_codes' => ['event_date'],
|
||||
@@ -143,7 +141,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
{
|
||||
return $this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'descripcion' => $data['nombre'],
|
||||
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
||||
...$data,
|
||||
|
||||
@@ -98,7 +98,6 @@ return [
|
||||
'event_date_selection_required' => 'At least one event date must be selected.',
|
||||
'single_event_date_required' => 'Exactly one event date must be selected.',
|
||||
'event_date_wrong_tenant' => 'Every event date must belong to the catalog item tenant.',
|
||||
'invalid_event_product_type' => 'The event product type is invalid.',
|
||||
'duplicate_variant_combination' => 'The variant combination must be unique.',
|
||||
'multi_value_required' => 'At least one value must be selected.',
|
||||
'single_value_required' => 'Exactly one value must be selected.',
|
||||
|
||||
@@ -98,7 +98,6 @@ return [
|
||||
'event_date_selection_required' => 'Debe seleccionar al menos una fecha de evento.',
|
||||
'single_event_date_required' => 'Debe seleccionar exactamente una fecha de evento.',
|
||||
'event_date_wrong_tenant' => 'Todas las fechas del evento deben pertenecer al tenant del ítem de catálogo.',
|
||||
'invalid_event_product_type' => 'El tipo de producto de evento no es válido.',
|
||||
'duplicate_variant_combination' => 'La combinación de la variante debe ser única.',
|
||||
'multi_value_required' => 'Debe seleccionar al menos un valor.',
|
||||
'single_value_required' => 'Debe seleccionar exactamente un valor.',
|
||||
|
||||
@@ -33,7 +33,6 @@ class CatalogSchemaTest extends TestCase
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'tenant_code',
|
||||
'event_product_type',
|
||||
'category_id',
|
||||
'brand_id',
|
||||
'inventory_id',
|
||||
|
||||
@@ -100,7 +100,6 @@ class EntryControllerTest extends TestCase
|
||||
CatalogItem::query()->each(function (CatalogItem $entry) use ($tenant, $entryCategory): void {
|
||||
$this->assertSame($tenant->codigo, $entry->tenant_code);
|
||||
$this->assertSame($entryCategory->id, $entry->category_id);
|
||||
$this->assertSame('entrada', $entry->event_product_type->value);
|
||||
$this->assertSame('tracked', $entry->inventory_policy->value);
|
||||
$this->assertTrue($entry->has_tickets);
|
||||
$this->assertNull($entry->inventory_id);
|
||||
@@ -224,6 +223,46 @@ class EntryControllerTest extends TestCase
|
||||
$this->assertDatabaseCount('catalog_items', 0);
|
||||
}
|
||||
|
||||
public function test_entries_are_identified_by_the_entries_category(): void
|
||||
{
|
||||
$tenant = $this->createFiestaTenant();
|
||||
$this->createEventDateAttribute($tenant);
|
||||
$eventDate = $tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '00:00',
|
||||
'time_end' => '23:59',
|
||||
]);
|
||||
$merchandisingCategory = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Merchandising',
|
||||
]);
|
||||
$merchandise = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'category_id' => $merchandisingCategory->id,
|
||||
'slug' => 'camiseta',
|
||||
'nombre' => 'Camiseta',
|
||||
'precio' => 100,
|
||||
]);
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/entries')
|
||||
->assertOk()
|
||||
->assertJsonCount(0, 'data');
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/entries', [
|
||||
'entries' => [[
|
||||
'id' => $merchandise->id,
|
||||
'title' => 'Entrada inválida',
|
||||
'description' => null,
|
||||
'event_date_ids' => [$eventDate->id],
|
||||
'stock' => 10,
|
||||
'price' => 100,
|
||||
]],
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['entries.0.id']);
|
||||
}
|
||||
|
||||
public function test_the_endpoint_is_only_available_for_fiesta_futbol_infantil(): void
|
||||
{
|
||||
$tenant = $this->createTenant('other');
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
@@ -76,7 +75,6 @@ class CatalogModelsTest extends TestCase
|
||||
'category_id' => '10',
|
||||
'brand_id' => '20',
|
||||
'inventory_id' => '30',
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'type' => CatalogItemType::Standard->value,
|
||||
'precio' => '12.50',
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
@@ -88,7 +86,6 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame(10, $item->category_id);
|
||||
$this->assertSame(20, $item->brand_id);
|
||||
$this->assertSame(30, $item->inventory_id);
|
||||
$this->assertSame(EventProductType::Entry, $item->event_product_type);
|
||||
$this->assertSame(CatalogItemType::Standard, $item->type);
|
||||
$this->assertSame('12.50', $item->precio);
|
||||
$this->assertSame(InventoryPolicy::Tracked, $item->inventory_policy);
|
||||
|
||||
Reference in New Issue
Block a user