From f50d3d0587bb19cf0fec62722da8c4ce0e7b579d Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 12 Aug 2026 13:53:22 -0300 Subject: [PATCH] feat(tenant): provision Desfile Pura Tendencia and extend tenant customization - Add Desfile Pura Tendencia tenant migration with catalog, variants, event, menus and assets - Support tenant header/footer background images - Add configurable cart visibility - Update tenant seeding and API resources - Add migration and bootstrap feature tests --- app/Domains/Tenant/Models/Tenant.php | 21 ++ .../Tenant/Requests/StoreTenantRequest.php | 3 + .../Tenant/Requests/UpdateTenantRequest.php | 3 + .../Tenant/Resources/TenantResource.php | 3 + .../Services/TenantInformationService.php | 2 + app/Domains/Tenant/Services/TenantService.php | 33 ++ ...0_create_desfile_pura_tendencia_tenant.php | 329 ++++++++++++++++++ ...event_date_from_desfile_entry_variants.php | 66 ++++ ...0000_add_display_cart_to_tenants_table.php | 28 ++ ...add_background_images_to_tenants_table.php | 32 ++ database/seeders/TenantSeeder.php | 2 + .../CreateDesfilePuraTendenciaTenantTest.php | 228 ++++++++++++ .../Tenant/BootstrapTenantControllerTest.php | 22 ++ 13 files changed, 772 insertions(+) create mode 100644 database/migrations/2026_08_12_020000_create_desfile_pura_tendencia_tenant.php create mode 100644 database/migrations/2026_08_12_030000_remove_event_date_from_desfile_entry_variants.php create mode 100644 database/migrations/2026_08_12_040000_add_display_cart_to_tenants_table.php create mode 100644 database/migrations/2026_08_12_050000_add_background_images_to_tenants_table.php create mode 100644 tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php diff --git a/app/Domains/Tenant/Models/Tenant.php b/app/Domains/Tenant/Models/Tenant.php index 0013a9c..f2ddaf8 100644 --- a/app/Domains/Tenant/Models/Tenant.php +++ b/app/Domains/Tenant/Models/Tenant.php @@ -29,12 +29,15 @@ use Illuminate\Database\Eloquent\Relations\HasMany; 'footer_bg_color', 'header_logo_id', 'footer_logo_id', + 'header_bg_image_id', + 'footer_bg_image_id', 'website_type_code', 'search_product_layout', 'search_group_layout', 'search_items_per_page', 'display_categories', 'display_seach_bar', + 'display_cart', 'event_title', 'event_location', 'event_date_text', @@ -49,6 +52,7 @@ class Tenant extends Model 'search_items_per_page' => 12, 'display_categories' => true, 'display_seach_bar' => true, + 'display_cart' => true, ]; public function getRouteKeyName(): string @@ -69,6 +73,7 @@ class Tenant extends Model 'search_items_per_page' => 'integer', 'display_categories' => 'boolean', 'display_seach_bar' => 'boolean', + 'display_cart' => 'boolean', ]; } @@ -88,6 +93,22 @@ class Tenant extends Model return $this->belongsTo(Attachment::class, 'footer_logo_id'); } + /** + * @return BelongsTo + */ + public function headerBackgroundImage(): BelongsTo + { + return $this->belongsTo(Attachment::class, 'header_bg_image_id'); + } + + /** + * @return BelongsTo + */ + public function footerBackgroundImage(): BelongsTo + { + return $this->belongsTo(Attachment::class, 'footer_bg_image_id'); + } + /** * @return BelongsTo */ diff --git a/app/Domains/Tenant/Requests/StoreTenantRequest.php b/app/Domains/Tenant/Requests/StoreTenantRequest.php index 88d398d..91671df 100644 --- a/app/Domains/Tenant/Requests/StoreTenantRequest.php +++ b/app/Domains/Tenant/Requests/StoreTenantRequest.php @@ -63,6 +63,8 @@ class StoreTenantRequest extends FormRequest 'footer_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'header_logo' => $logoRule, 'footer_logo' => $logoRule, + 'header_bg_image' => ['sometimes', 'nullable', new ImageOrBase64Rule], + 'footer_bg_image' => ['sometimes', 'nullable', new ImageOrBase64Rule], 'social_media' => ['sometimes', 'array'], 'social_media.*.code' => [ 'required', @@ -77,6 +79,7 @@ class StoreTenantRequest extends FormRequest 'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'], 'display_categories' => ['sometimes', 'boolean'], 'display_seach_bar' => ['sometimes', 'boolean'], + 'display_cart' => ['sometimes', 'boolean'], 'website_type_code' => [ 'required_with:extras', 'sometimes', diff --git a/app/Domains/Tenant/Requests/UpdateTenantRequest.php b/app/Domains/Tenant/Requests/UpdateTenantRequest.php index dec65d9..5adf261 100644 --- a/app/Domains/Tenant/Requests/UpdateTenantRequest.php +++ b/app/Domains/Tenant/Requests/UpdateTenantRequest.php @@ -73,6 +73,8 @@ class UpdateTenantRequest extends FormRequest 'footer_bg_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'header_logo' => $logoRule, 'footer_logo' => $logoRule, + 'header_bg_image' => ['sometimes', 'nullable', new ImageOrBase64Rule], + 'footer_bg_image' => ['sometimes', 'nullable', new ImageOrBase64Rule], 'social_media' => ['sometimes', 'array'], 'social_media.*.code' => [ 'required', @@ -87,6 +89,7 @@ class UpdateTenantRequest extends FormRequest 'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'], 'display_categories' => ['sometimes', 'boolean'], 'display_seach_bar' => ['sometimes', 'boolean'], + 'display_cart' => ['sometimes', 'boolean'], ]; } } diff --git a/app/Domains/Tenant/Resources/TenantResource.php b/app/Domains/Tenant/Resources/TenantResource.php index e681a2d..dfb093a 100644 --- a/app/Domains/Tenant/Resources/TenantResource.php +++ b/app/Domains/Tenant/Resources/TenantResource.php @@ -59,11 +59,14 @@ class TenantResource extends JsonResource // 1 day 'header_logo' => $this->headerLogo?->getTemporaryUrl(1440), 'footer_logo' => $this->footerLogo?->getTemporaryUrl(1440), + 'header_bg_image' => $this->headerBackgroundImage?->getTemporaryUrl(1440), + 'footer_bg_image' => $this->footerBackgroundImage?->getTemporaryUrl(1440), 'search_product_layout' => $this->search_product_layout->value, 'search_group_layout' => $this->search_group_layout->value, 'search_items_per_page' => $this->search_items_per_page, 'display_categories' => $this->display_categories, 'display_seach_bar' => $this->display_seach_bar, + 'display_cart' => $this->display_cart, 'social_media' => $this->whenLoaded( 'socialMedia', fn () => $this->socialMedia diff --git a/app/Domains/Tenant/Services/TenantInformationService.php b/app/Domains/Tenant/Services/TenantInformationService.php index 32d7844..1b4491a 100644 --- a/app/Domains/Tenant/Services/TenantInformationService.php +++ b/app/Domains/Tenant/Services/TenantInformationService.php @@ -13,6 +13,8 @@ class TenantInformationService private const DEFAULT_RELATIONS = [ 'headerLogo', 'footerLogo', + 'headerBackgroundImage', + 'footerBackgroundImage', 'socialMedia', 'websiteExtras.websiteTypeExtra', 'eventDates', diff --git a/app/Domains/Tenant/Services/TenantService.php b/app/Domains/Tenant/Services/TenantService.php index c2692e1..de4890c 100644 --- a/app/Domains/Tenant/Services/TenantService.php +++ b/app/Domains/Tenant/Services/TenantService.php @@ -25,12 +25,16 @@ class TenantService return DB::transaction(function () use ($data): Tenant { $headerLogo = $data['header_logo'] ?? null; $footerLogo = $data['footer_logo'] ?? null; + $headerBackgroundImage = $data['header_bg_image'] ?? null; + $footerBackgroundImage = $data['footer_bg_image'] ?? null; $socialMedia = $data['social_media'] ?? []; $extras = $data['extras'] ?? []; unset( $data['header_logo'], $data['footer_logo'], + $data['header_bg_image'], + $data['footer_bg_image'], $data['social_media'], $data['extras'], ); @@ -59,6 +63,8 @@ class TenantService $data['header_logo_id'] = $headerAttachmentId; $data['footer_logo_id'] = $footerAttachmentId; + $data['header_bg_image_id'] = $this->storeTenantImage($headerBackgroundImage); + $data['footer_bg_image_id'] = $this->storeTenantImage($footerBackgroundImage); /** @var Tenant $tenant */ $tenant = Tenant::query()->create($data); @@ -79,14 +85,20 @@ class TenantService return DB::transaction(function () use ($tenant, $data): Tenant { $hasHeaderLogoKey = array_key_exists('header_logo', $data); $hasFooterLogoKey = array_key_exists('footer_logo', $data); + $hasHeaderBackgroundImageKey = array_key_exists('header_bg_image', $data); + $hasFooterBackgroundImageKey = array_key_exists('footer_bg_image', $data); $hasSocialMediaKey = array_key_exists('social_media', $data); $headerLogo = $data['header_logo'] ?? null; $footerLogo = $data['footer_logo'] ?? null; + $headerBackgroundImage = $data['header_bg_image'] ?? null; + $footerBackgroundImage = $data['footer_bg_image'] ?? null; $socialMedia = $data['social_media'] ?? []; unset( $data['header_logo'], $data['footer_logo'], + $data['header_bg_image'], + $data['footer_bg_image'], $data['social_media'] ); @@ -124,6 +136,14 @@ class TenantService } } + if ($hasHeaderBackgroundImageKey) { + $tenant->header_bg_image_id = $this->storeTenantImage($headerBackgroundImage); + } + + if ($hasFooterBackgroundImageKey) { + $tenant->footer_bg_image_id = $this->storeTenantImage($footerBackgroundImage); + } + $tenant->save(); if ($hasSocialMediaKey) { @@ -151,4 +171,17 @@ class TenantService $tenant->socialMedia()->sync($associations); $tenant->unsetRelation('socialMedia'); } + + private function storeTenantImage(mixed $image): ?int + { + if (! $image) { + return null; + } + + $attachment = is_string($image) && Str::isUuid($image) + ? Attachment::query()->where('key', $image)->first() + : $this->attachmentService->store($image, 'tenants'); + + return $attachment?->id; + } } diff --git a/database/migrations/2026_08_12_020000_create_desfile_pura_tendencia_tenant.php b/database/migrations/2026_08_12_020000_create_desfile_pura_tendencia_tenant.php new file mode 100644 index 0000000..4c51baa --- /dev/null +++ b/database/migrations/2026_08_12_020000_create_desfile_pura_tendencia_tenant.php @@ -0,0 +1,329 @@ + */ + private array $storedPaths = []; + + public function up(): void + { + if (DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) { + return; + } + + $heroExtraId = DB::table('website_type_extras') + ->where('website_type_code', 'onticket') + ->where('codigo', 'heroConfig') + ->value('id'); + + if ( + $heroExtraId === null + || ! DB::table('website_type')->where('codigo', 'onticket')->exists() + || ! DB::table('tenants')->where('codigo', self::SOURCE_TENANT_CODE)->exists() + ) { + // This data migration targets installations whose reference data was + // already provisioned. Fresh test databases do not contain seed data. + return; + } + + try { + DB::transaction(function () use ($heroExtraId): void { + $headerLogoId = $this->storeImage( + 'images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_header.png', + 'desfile_pura_tendencia_header.png', + 'tenants/'.self::TENANT_CODE, + ); + $footerLogoId = $this->storeImage( + 'images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_footer.png', + 'desfile_pura_tendencia_footer.png', + 'tenants/'.self::TENANT_CODE, + ); + $heroImageId = $this->storeImage( + 'images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_hero.png', + 'desfile_pura_tendencia_hero.png', + 'tenants/'.self::TENANT_CODE.'/extras/heroConfig', + ); + + $now = now(); + + DB::table('tenants')->insert([ + 'codigo' => self::TENANT_CODE, + 'nombre' => 'Desfile Pura Tendencia', + 'dominio' => 'desfile-pura-tendencia.localhost', + 'event_title' => 'Desfile Pura Tendencia', + 'event_location' => 'Salón Centro Recreativo Luz y Fuerza', + 'event_date_text' => '16 de Octubre 2026', + 'primary_color' => '#BA69A9', + 'secondary_color' => '#A0A0A0', + 'danger_color' => '#FF8888', + 'success_color' => '#198754', + 'header_bg_color' => '#ffffff', + 'footer_bg_color' => '#D4441C', + 'header_logo_id' => $headerLogoId, + 'footer_logo_id' => $footerLogoId, + 'website_type_code' => 'onticket', + 'display_categories' => false, + 'display_seach_bar' => false, + 'created_at' => $now, + 'updated_at' => $now, + ]); + + $validityTimeId = DB::table('validity_times')->insertGetId([ + 'type' => 'fixed_window', + 'start_time' => null, + 'end_time' => null, + 'fixed_starts_at' => '2026-10-16 20:30:00', + 'fixed_expires_at' => '2026-10-16 23:59:00', + 'created_at' => $now, + 'updated_at' => $now, + ]); + + DB::table('event_dates')->insert([ + 'tenant_code' => self::TENANT_CODE, + 'validity_time_id' => $validityTimeId, + 'date' => '2026-10-16', + 'time_start' => '20:30:00', + 'time_end' => '23:59:00', + ]); + + $this->createEntryCatalog($validityTimeId, $now); + + DB::table('websites_extras')->insert([ + 'website_code' => self::TENANT_CODE, + 'website_type_extra_id' => $heroExtraId, + 'config' => json_encode([ + 'title_html' => '

LA NOCHE DE LA MODA

', + 'description_html' => 'Viví una experiencia de Alta Costura con conducción exclusiva de Pampita y las colecciones de Pucheta-Paz.', + 'background_image_id' => $heroImageId, + ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'is_enabled' => true, + 'created_at' => $now, + 'updated_at' => $now, + ]); + + $menuAssignments = DB::table('tenants_menues') + ->where('tenant_code', self::SOURCE_TENANT_CODE) + ->where('menu_code', 'not like', 'adminapp.fiesta-futbol-infantil.%') + ->orderBy('id') + ->get(['menu_code', 'static_content']); + + foreach ($menuAssignments as $assignment) { + DB::table('tenants_menues')->insert([ + 'tenant_code' => self::TENANT_CODE, + 'menu_code' => $assignment->menu_code, + 'static_content' => $assignment->static_content, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + }); + } catch (Throwable $throwable) { + Storage::disk('s3')->delete($this->storedPaths); + + throw $throwable; + } + } + + public function down(): void + { + // Intentionally irreversible: once active, this tenant can own users, + // purchases, tickets and catalog data that a rollback must not delete. + } + + private function storeImage(string $relativePath, string $filename, string $directory): int + { + $sourcePath = public_path($relativePath); + + if (! is_file($sourcePath)) { + throw new RuntimeException("Image not found at path: {$sourcePath}"); + } + + $contents = file_get_contents($sourcePath); + + if ($contents === false) { + throw new RuntimeException("Could not read image at path: {$sourcePath}"); + } + + $key = (string) Str::uuid(); + $storedPath = trim($directory, '/').'/'.$key.'.png'; + + if (! Storage::disk('s3')->put($storedPath, $contents)) { + throw new RuntimeException("Could not store image at path: {$storedPath}"); + } + + $this->storedPaths[] = $storedPath; + + return DB::table('attachments')->insertGetId([ + 'key' => $key, + 'path' => $storedPath, + 'filename' => $filename, + 'type' => 'image', + 'mime_type' => 'image/png', + 'extension' => 'png', + 'size' => strlen($contents), + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + + private function createEntryCatalog(int $validityTimeId, DateTimeInterface $now): void + { + $attributes = [ + 'tipo' => [ + 'name' => 'Tipo', + 'options' => ['VIP + LUNCH', 'NORMAL'], + ], + 'sector' => [ + 'name' => 'Sector', + 'options' => ['A', 'B', 'C', 'D'], + ], + 'fila' => [ + 'name' => 'Fila', + 'options' => array_map('strval', range(1, 17)), + ], + 'asiento' => [ + 'name' => 'Asiento', + 'options' => array_map('strval', range(1, 5)), + ], + ]; + $attributeIds = []; + + foreach ($attributes as $code => $definition) { + $attributeId = DB::table('attribute')->insertGetId([ + 'tenant_codigo' => self::TENANT_CODE, + 'codigo' => $code, + 'nombre' => $definition['name'], + 'is_required' => true, + 'metadata_schema' => null, + 'type' => 'select', + 'created_at' => $now, + 'updated_at' => $now, + ]); + $attributeIds[$code] = $attributeId; + + foreach ($definition['options'] as $index => $option) { + DB::table('attribute_options')->insert([ + 'attribute_id' => $attributeId, + 'validity_time_id' => null, + 'value' => $option, + 'label' => $option, + 'sort_order' => $index + 1, + 'metadata' => null, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + } + + $catalogItemId = DB::table('catalog_items')->insertGetId([ + 'tenant_code' => self::TENANT_CODE, + 'category_id' => null, + 'brand_id' => null, + 'inventory_id' => null, + 'type' => 'standard', + 'slug' => 'entrada', + 'nombre' => 'Entrada', + 'descripcion' => 'Entrada para Desfile Pura Tendencia', + 'precio' => 40000, + 'inventory_policy' => 'tracked', + 'has_tickets' => true, + 'ticket_generation_policy' => 'one_per_unit', + 'validity_time_id' => $validityTimeId, + 'max_units_per_user' => null, + ]); + $itemAttributeIds = []; + + foreach (array_keys($attributes) as $index => $code) { + $itemAttributeIds[$code] = DB::table('item_attributes')->insertGetId([ + 'catalog_item_id' => $catalogItemId, + 'attribute_id' => $attributeIds[$code], + 'allow_multi_select' => false, + 'sort_order' => $index + 1, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + + foreach (['A', 'B', 'C', 'D'] as $sector) { + $lastRow = in_array($sector, ['B', 'D'], true) ? 16 : 17; + + foreach (range(1, $lastRow) as $row) { + foreach (range(1, 5) as $seat) { + [$type, $price] = $this->entryTypeAndPrice($sector, $seat); + $inventoryId = DB::table('inventories')->insertGetId([ + 'sold_units' => 0, + 'reserved_stock' => 0, + 'real_stock' => 1, + ]); + $variantId = DB::table('variantes')->insertGetId([ + 'catalog_item_id' => $catalogItemId, + 'event_date_id' => null, + 'inventory_id' => $inventoryId, + 'descripcion' => "Sector {$sector} - Fila {$row} - Asiento {$seat} - {$type}", + 'precio' => $price, + ]); + + foreach ([ + 'tipo' => $type, + 'sector' => $sector, + 'fila' => (string) $row, + 'asiento' => (string) $seat, + ] as $code => $value) { + DB::table('variant_values')->insert([ + 'variant_id' => $variantId, + 'item_attribute_id' => $itemAttributeIds[$code], + 'value' => $value, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + } + } + } + + $entryImageId = $this->storeImage( + 'images/tennants/desfile_pura_tendencia/catalog/entrada_pasarela.png', + 'entrada_pasarela.png', + 'catalog-items', + ); + + DB::table('catalog_items_attachments')->insert([ + 'variant_id' => null, + 'catalog_item_id' => $catalogItemId, + 'attachment_id' => $entryImageId, + 'orden' => 0, + ]); + + DB::table('featured_groups')->insert([ + 'tenant_code' => self::TENANT_CODE, + 'source_type' => 'all', + 'category_id' => null, + 'product_layout' => 'ticket_selector', + 'group_layout' => 'single', + 'group_name' => 'Entradas', + 'group_order' => 0, + ]); + } + + /** @return array{string, int} */ + private function entryTypeAndPrice(string $sector, int $seat): array + { + $prices = in_array($sector, ['A', 'C'], true) + ? [1 => 250000, 2 => 200000, 3 => 100000, 4 => 75000, 5 => 50000] + : [1 => 240000, 2 => 190000, 3 => 90000, 4 => 65000, 5 => 40000]; + + return [ + $seat <= 2 ? 'VIP + LUNCH' : 'NORMAL', + $prices[$seat], + ]; + } +}; diff --git a/database/migrations/2026_08_12_030000_remove_event_date_from_desfile_entry_variants.php b/database/migrations/2026_08_12_030000_remove_event_date_from_desfile_entry_variants.php new file mode 100644 index 0000000..1b7b7e1 --- /dev/null +++ b/database/migrations/2026_08_12_030000_remove_event_date_from_desfile_entry_variants.php @@ -0,0 +1,66 @@ +variantIds(); + + if ($variantIds->isEmpty()) { + return; + } + + DB::transaction(function () use ($variantIds): void { + DB::table('variant_event_dates') + ->whereIn('variant_id', $variantIds) + ->delete(); + + DB::table('variantes') + ->whereIn('id', $variantIds) + ->update(['event_date_id' => null]); + }); + } + + public function down(): void + { + $eventDateId = DB::table('event_dates') + ->where('tenant_code', self::TENANT_CODE) + ->where('date', '2026-10-16') + ->value('id'); + $variantIds = $this->variantIds(); + + if ($eventDateId === null || $variantIds->isEmpty()) { + return; + } + + DB::transaction(function () use ($eventDateId, $variantIds): void { + DB::table('variantes') + ->whereIn('id', $variantIds) + ->update(['event_date_id' => $eventDateId]); + + foreach ($variantIds as $variantId) { + DB::table('variant_event_dates')->insertOrIgnore([ + 'variant_id' => $variantId, + 'event_date_id' => $eventDateId, + ]); + } + }); + } + + private function variantIds(): Collection + { + return DB::table('variantes') + ->join('catalog_items', 'catalog_items.id', '=', 'variantes.catalog_item_id') + ->where('catalog_items.tenant_code', self::TENANT_CODE) + ->where('catalog_items.slug', self::CATALOG_SLUG) + ->pluck('variantes.id'); + } +}; diff --git a/database/migrations/2026_08_12_040000_add_display_cart_to_tenants_table.php b/database/migrations/2026_08_12_040000_add_display_cart_to_tenants_table.php new file mode 100644 index 0000000..a3dc4b8 --- /dev/null +++ b/database/migrations/2026_08_12_040000_add_display_cart_to_tenants_table.php @@ -0,0 +1,28 @@ +boolean('display_cart')->default(true)->after('display_seach_bar'); + }); + + DB::table('tenants')->update(['display_cart' => true]); + DB::table('tenants') + ->where('codigo', 'desfile_pura_tendencia') + ->update(['display_cart' => false]); + } + + public function down(): void + { + Schema::table('tenants', function (Blueprint $table): void { + $table->dropColumn('display_cart'); + }); + } +}; diff --git a/database/migrations/2026_08_12_050000_add_background_images_to_tenants_table.php b/database/migrations/2026_08_12_050000_add_background_images_to_tenants_table.php new file mode 100644 index 0000000..0378088 --- /dev/null +++ b/database/migrations/2026_08_12_050000_add_background_images_to_tenants_table.php @@ -0,0 +1,32 @@ +foreignId('header_bg_image_id') + ->nullable() + ->after('footer_logo_id') + ->constrained('attachments') + ->nullOnDelete(); + $table->foreignId('footer_bg_image_id') + ->nullable() + ->after('header_bg_image_id') + ->constrained('attachments') + ->nullOnDelete(); + }); + } + + public function down(): void + { + Schema::table('tenants', function (Blueprint $table): void { + $table->dropConstrainedForeignId('footer_bg_image_id'); + $table->dropConstrainedForeignId('header_bg_image_id'); + }); + } +}; diff --git a/database/seeders/TenantSeeder.php b/database/seeders/TenantSeeder.php index 6500d33..c478e7d 100644 --- a/database/seeders/TenantSeeder.php +++ b/database/seeders/TenantSeeder.php @@ -58,6 +58,7 @@ class TenantSeeder extends Seeder 'footer_bg_color' => '#313131', 'display_categories' => true, 'display_seach_bar' => true, + 'display_cart' => true, 'header_logo' => $this->uploadedImage('images/tennants/sonder/sonder_header.png', 'sonder_header.png'), 'footer_logo' => $this->uploadedImage('images/tennants/sonder/sonder_footer.png', 'sonder_footer.png'), 'social_media' => self::SOCIAL_MEDIA, @@ -111,6 +112,7 @@ class TenantSeeder extends Seeder 'footer_bg_color' => '#015327', 'display_categories' => false, 'display_seach_bar' => false, + 'display_cart' => true, 'header_logo' => $this->uploadedImage( 'images/tennants/fiesta_futbol_infantil/futbol_infantil_header.png', 'futbol_infantil_header.png', diff --git a/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php b/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php new file mode 100644 index 0000000..a616b11 --- /dev/null +++ b/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php @@ -0,0 +1,228 @@ +seed([ + WebsiteTypeSeeder::class, + SocialMediaSeeder::class, + TenantSeeder::class, + MenuSeeder::class, + ]); + + $migration = require database_path( + 'migrations/2026_08_12_020000_create_desfile_pura_tendencia_tenant.php' + ); + $migration->up(); + + $this->assertDatabaseHas('tenants', [ + 'codigo' => 'desfile_pura_tendencia', + 'nombre' => 'Desfile Pura Tendencia', + 'dominio' => 'desfile-pura-tendencia.localhost', + 'website_type_code' => 'onticket', + 'event_title' => 'Desfile Pura Tendencia', + 'event_location' => 'Salón Centro Recreativo Luz y Fuerza', + 'event_date_text' => '16 de Octubre 2026', + 'primary_color' => '#BA69A9', + 'secondary_color' => '#A0A0A0', + 'danger_color' => '#FF8888', + 'success_color' => '#198754', + 'header_bg_color' => '#ffffff', + 'footer_bg_color' => '#D4441C', + 'display_categories' => false, + 'display_seach_bar' => false, + ]); + + $eventDate = DB::table('event_dates') + ->where('tenant_code', 'desfile_pura_tendencia') + ->sole(); + + $this->assertSame('2026-10-16', $eventDate->date); + $this->assertSame('20:30:00', $eventDate->time_start); + $this->assertSame('23:59:00', $eventDate->time_end); + $this->assertDatabaseHas('validity_times', [ + 'id' => $eventDate->validity_time_id, + 'type' => 'fixed_window', + 'fixed_starts_at' => '2026-10-16 20:30:00', + 'fixed_expires_at' => '2026-10-16 23:59:00', + ]); + + $hero = DB::table('websites_extras') + ->join( + 'website_type_extras', + 'website_type_extras.id', + '=', + 'websites_extras.website_type_extra_id', + ) + ->where('websites_extras.website_code', 'desfile_pura_tendencia') + ->where('website_type_extras.codigo', 'heroConfig') + ->value('websites_extras.config'); + $hero = json_decode($hero, true, flags: JSON_THROW_ON_ERROR); + + $this->assertSame('

LA NOCHE DE LA MODA

', $hero['title_html']); + $this->assertSame( + 'Viví una experiencia de Alta Costura con conducción exclusiva de Pampita y las colecciones de Pucheta-Paz.', + $hero['description_html'], + ); + $this->assertDatabaseHas('attachments', [ + 'id' => $hero['background_image_id'], + 'filename' => 'desfile_pura_tendencia_hero.png', + 'type' => 'image', + ]); + + foreach ([ + 'desfile_pura_tendencia_header.png', + 'desfile_pura_tendencia_footer.png', + 'desfile_pura_tendencia_hero.png', + 'entrada_pasarela.png', + ] as $filename) { + $path = DB::table('attachments')->where('filename', $filename)->value('path'); + + $this->assertNotNull($path); + Storage::disk('s3')->assertExists($path); + } + + $expectedMenus = DB::table('tenants_menues') + ->where('tenant_code', 'fiesta_futbol_infantil') + ->where('menu_code', 'not like', 'adminapp.fiesta-futbol-infantil.%') + ->orderBy('menu_code') + ->pluck('menu_code') + ->all(); + $actualMenus = DB::table('tenants_menues') + ->where('tenant_code', 'desfile_pura_tendencia') + ->orderBy('menu_code') + ->pluck('menu_code') + ->all(); + + $this->assertSame($expectedMenus, $actualMenus); + $this->assertContains('main.adminapp', $actualMenus); + $this->assertContains('adminapp.event', $actualMenus); + $this->assertContains('scanner.scan', $actualMenus); + $this->assertNotContains('adminapp.fiesta-futbol-infantil.entradas', $actualMenus); + + $catalogItem = DB::table('catalog_items') + ->where('tenant_code', 'desfile_pura_tendencia') + ->where('slug', 'entrada') + ->sole(); + + $this->assertSame('Entrada', $catalogItem->nombre); + $this->assertSame('tracked', $catalogItem->inventory_policy); + $this->assertSame(1, $catalogItem->has_tickets); + $this->assertSame('one_per_unit', $catalogItem->ticket_generation_policy); + $this->assertSame($eventDate->validity_time_id, $catalogItem->validity_time_id); + $this->assertDatabaseHas('catalog_items_attachments', [ + 'catalog_item_id' => $catalogItem->id, + 'variant_id' => null, + 'orden' => 0, + ]); + $this->assertDatabaseHas('featured_groups', [ + 'tenant_code' => 'desfile_pura_tendencia', + 'source_type' => 'all', + 'product_layout' => 'ticket_selector', + 'group_layout' => 'single', + ]); + + $attributes = DB::table('attribute') + ->where('tenant_codigo', 'desfile_pura_tendencia') + ->orderBy('id') + ->get() + ->keyBy('codigo'); + + $this->assertSame(['tipo', 'sector', 'fila', 'asiento'], $attributes->keys()->all()); + $this->assertSame([ + 'tipo' => ['VIP + LUNCH', 'NORMAL'], + 'sector' => ['A', 'B', 'C', 'D'], + 'fila' => array_map('strval', range(1, 17)), + 'asiento' => array_map('strval', range(1, 5)), + ], $attributes->map(fn (object $attribute): array => DB::table('attribute_options') + ->where('attribute_id', $attribute->id) + ->orderBy('sort_order') + ->pluck('value') + ->all())->all()); + + $variants = DB::table('variantes')->where('catalog_item_id', $catalogItem->id); + + $this->assertSame(330, (clone $variants)->count()); + $this->assertSame(1320, DB::table('variant_values') + ->whereIn('variant_id', (clone $variants)->pluck('id')) + ->count()); + $this->assertSame(0, DB::table('variant_event_dates') + ->whereIn('variant_id', (clone $variants)->pluck('id')) + ->count()); + $this->assertSame(330, (clone $variants)->whereNull('event_date_id')->count()); + $this->assertSame(330, DB::table('inventories') + ->whereIn('id', (clone $variants)->pluck('inventory_id')) + ->where('real_stock', 1) + ->where('reserved_stock', 0) + ->where('sold_units', 0) + ->count()); + + foreach ([ + 250000 => 34, + 200000 => 34, + 100000 => 34, + 75000 => 34, + 50000 => 34, + 240000 => 32, + 190000 => 32, + 90000 => 32, + 65000 => 32, + 40000 => 32, + ] as $price => $expectedCount) { + $this->assertSame($expectedCount, (clone $variants)->where('precio', $price)->count()); + } + + $this->assertSame(0, $this->variantCountForSelection($catalogItem->id, [ + 'sector' => ['B', 'D'], + 'fila' => ['17'], + ])); + $this->assertSame(66, $this->variantCountForSelection($catalogItem->id, [ + 'tipo' => ['VIP + LUNCH'], + 'asiento' => ['1'], + ])); + $this->assertSame(66, $this->variantCountForSelection($catalogItem->id, [ + 'tipo' => ['NORMAL'], + 'asiento' => ['5'], + ])); + } + + /** @param array> $selection */ + private function variantCountForSelection(int $catalogItemId, array $selection): int + { + $query = DB::table('variantes')->where('catalog_item_id', $catalogItemId); + + foreach ($selection as $attributeCode => $values) { + $query->whereExists(fn ($subquery) => $subquery + ->selectRaw('1') + ->from('variant_values') + ->join( + 'item_attributes', + 'item_attributes.id', + '=', + 'variant_values.item_attribute_id', + ) + ->join('attribute', 'attribute.id', '=', 'item_attributes.attribute_id') + ->whereColumn('variant_values.variant_id', 'variantes.id') + ->where('attribute.codigo', $attributeCode) + ->whereIn('variant_values.value', $values)); + } + + return $query->count(); + } +} diff --git a/tests/Feature/Tenant/BootstrapTenantControllerTest.php b/tests/Feature/Tenant/BootstrapTenantControllerTest.php index c5e4162..ef7b114 100644 --- a/tests/Feature/Tenant/BootstrapTenantControllerTest.php +++ b/tests/Feature/Tenant/BootstrapTenantControllerTest.php @@ -39,6 +39,20 @@ class BootstrapTenantControllerTest extends TestCase 'type' => AttachmentType::Image, 'mime_type' => 'image/png', ]); + $headerBackgroundAttachment = Attachment::create([ + 'key' => (string) Str::uuid(), + 'path' => 'tenants/header-background.png', + 'filename' => 'header-background.png', + 'type' => AttachmentType::Image, + 'mime_type' => 'image/png', + ]); + $footerBackgroundAttachment = Attachment::create([ + 'key' => (string) Str::uuid(), + 'path' => 'tenants/footer-background.png', + 'filename' => 'footer-background.png', + 'type' => AttachmentType::Image, + 'mime_type' => 'image/png', + ]); $tenant = Tenant::create([ 'codigo' => 'acme', @@ -52,9 +66,12 @@ class BootstrapTenantControllerTest extends TestCase 'footer_bg_color' => '#ffffff', 'header_logo_id' => $headerAttachment->id, 'footer_logo_id' => $footerAttachment->id, + 'header_bg_image_id' => $headerBackgroundAttachment->id, + 'footer_bg_image_id' => $footerBackgroundAttachment->id, 'event_date_text' => '9, 10, 11 y 12 de Octubre 2026', 'display_categories' => false, 'display_seach_bar' => false, + 'display_cart' => false, ]); $response = $this->getJson('/api/tenants/bootstrap/acme.com'); @@ -70,13 +87,18 @@ class BootstrapTenantControllerTest extends TestCase ->assertJsonPath('data.event_date_text', '9, 10, 11 y 12 de Octubre 2026') ->assertJsonPath('data.display_categories', false) ->assertJsonPath('data.display_seach_bar', false) + ->assertJsonPath('data.display_cart', false) ->assertJsonPath('data.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff'); $headerUrl = $response->json('data.header_logo'); $footerUrl = $response->json('data.footer_logo'); + $headerBackgroundUrl = $response->json('data.header_bg_image'); + $footerBackgroundUrl = $response->json('data.footer_bg_image'); $this->assertStringContainsString($headerAttachment->key, $headerUrl); $this->assertStringContainsString($footerAttachment->key, $footerUrl); + $this->assertStringContainsString($headerBackgroundAttachment->key, $headerBackgroundUrl); + $this->assertStringContainsString($footerBackgroundAttachment->key, $footerBackgroundUrl); $this->assertTrue( str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=') );