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
This commit is contained in:
@@ -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<Attachment, $this>
|
||||
*/
|
||||
public function headerBackgroundImage(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Attachment::class, 'header_bg_image_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Attachment, $this>
|
||||
*/
|
||||
public function footerBackgroundImage(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Attachment::class, 'footer_bg_image_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<WebsiteType, $this>
|
||||
*/
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -13,6 +13,8 @@ class TenantInformationService
|
||||
private const DEFAULT_RELATIONS = [
|
||||
'headerLogo',
|
||||
'footerLogo',
|
||||
'headerBackgroundImage',
|
||||
'footerBackgroundImage',
|
||||
'socialMedia',
|
||||
'websiteExtras.websiteTypeExtra',
|
||||
'eventDates',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const TENANT_CODE = 'desfile_pura_tendencia';
|
||||
|
||||
private const SOURCE_TENANT_CODE = 'fiesta_futbol_infantil';
|
||||
|
||||
/** @var list<string> */
|
||||
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' => '<h1>LA NOCHE DE LA MODA</h1>',
|
||||
'description_html' => 'Viví una experiencia de <b>Alta Costura con conducción exclusiva de Pampita</b> 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],
|
||||
];
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const TENANT_CODE = 'desfile_pura_tendencia';
|
||||
|
||||
private const CATALOG_SLUG = 'entrada';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$variantIds = $this->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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('tenants', function (Blueprint $table): void {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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',
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Migrations;
|
||||
|
||||
use Database\Seeders\MenuSeeder;
|
||||
use Database\Seeders\SocialMediaSeeder;
|
||||
use Database\Seeders\TenantSeeder;
|
||||
use Database\Seeders\WebsiteTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateDesfilePuraTendenciaTenantTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_provisions_the_desfile_tenant_configuration(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
$this->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('<h1>LA NOCHE DE LA MODA</h1>', $hero['title_html']);
|
||||
$this->assertSame(
|
||||
'Viví una experiencia de <b>Alta Costura con conducción exclusiva de Pampita</b> 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<string, list<string>> $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();
|
||||
}
|
||||
}
|
||||
@@ -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=')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user