Compare commits

...

2 Commits

13 changed files with 124 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Domains\Event\Models;
use App\Domains\Catalog\Models\Variant;
use App\Domains\Event\Services\EventDateTextFormatter;
use App\Domains\Tenant\Models\Tenant;
use Carbon\CarbonInterface;
use Illuminate\Database\Eloquent\Attributes\Fillable;
@@ -25,6 +26,12 @@ class EventDate extends Model
public $timestamps = false;
protected static function booted(): void
{
static::saved(fn (self $eventDate) => $eventDate->syncTenantDateText());
static::deleted(fn (self $eventDate) => $eventDate->syncTenantDateText());
}
protected function casts(): array
{
return [
@@ -64,4 +71,19 @@ class EventDate extends Model
{
return Carbon::parse($this->date->format('Y-m-d').' '.$this->time_end);
}
private function syncTenantDateText(): void
{
$tenant = $this->tenant()->first();
if (! $tenant) {
return;
}
$tenant->update([
'event_date_text' => app(EventDateTextFormatter::class)->format(
$tenant->eventDates()->pluck('date')
),
]);
}
}

View File

@@ -13,8 +13,6 @@ class EventService
'facebook_url' => 'facebook',
];
public function __construct(protected EventDateTextFormatter $eventDateTextFormatter) {}
public function forTenant(Tenant $tenant): Tenant
{
return $tenant->load(['eventDates', 'socialMedia']);
@@ -28,9 +26,6 @@ class EventService
$tenant->update([
'event_title' => $data['title'],
'event_location' => $data['location'],
'event_date_text' => $this->eventDateTextFormatter->format(
array_column($data['dates'], 'date')
),
]);
$this->syncDates($tenant, $data['dates']);

View File

@@ -33,6 +33,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
'search_product_layout',
'search_group_layout',
'search_items_per_page',
'display_categories',
'display_seach_bar',
'event_title',
'event_location',
'event_date_text',
@@ -45,6 +47,8 @@ class Tenant extends Model
'search_product_layout' => ProductLayout::ColumnWithImage->value,
'search_group_layout' => GroupLayout::Paginated->value,
'search_items_per_page' => 12,
'display_categories' => true,
'display_seach_bar' => true,
];
public function getRouteKeyName(): string
@@ -63,6 +67,8 @@ class Tenant extends Model
'search_product_layout' => ProductLayout::class,
'search_group_layout' => GroupLayout::class,
'search_items_per_page' => 'integer',
'display_categories' => 'boolean',
'display_seach_bar' => 'boolean',
];
}

View File

@@ -19,6 +19,10 @@ class WebsiteExtra extends Model
protected $table = 'websites_extras';
protected $attributes = [
'is_enabled' => true,
];
private mixed $resolvedConfig = null;
private bool $hasResolvedConfig = false;

View File

@@ -75,6 +75,8 @@ class StoreTenantRequest extends FormRequest
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
'display_categories' => ['sometimes', 'boolean'],
'display_seach_bar' => ['sometimes', 'boolean'],
'website_type_code' => [
'required_with:extras',
'sometimes',

View File

@@ -85,6 +85,8 @@ class UpdateTenantRequest extends FormRequest
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
'display_categories' => ['sometimes', 'boolean'],
'display_seach_bar' => ['sometimes', 'boolean'],
];
}
}

View File

@@ -61,6 +61,8 @@ class TenantResource extends JsonResource
'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,
'social_media' => $this->whenLoaded(
'socialMedia',
fn () => $this->socialMedia

View File

@@ -0,0 +1,23 @@
<?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->boolean('display_categories')->default(true)->after('search_items_per_page');
$table->boolean('display_seach_bar')->default(true)->after('display_categories');
});
}
public function down(): void
{
Schema::table('tenants', function (Blueprint $table): void {
$table->dropColumn(['display_categories', 'display_seach_bar']);
});
}
};

View File

@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
DB::table('tenants')
->where('codigo', 'fiesta_futbol_infantil')
->update([
'display_categories' => false,
'display_seach_bar' => false,
]);
DB::table('tenants')
->where('codigo', 'sonder')
->update([
'display_categories' => true,
'display_seach_bar' => true,
]);
}
public function down(): void {}
};

View File

@@ -0,0 +1,27 @@
<?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
{
DB::table('websites_extras')
->whereNull('is_enabled')
->update(['is_enabled' => true]);
Schema::table('websites_extras', function (Blueprint $table): void {
$table->boolean('is_enabled')->default(true)->nullable(false)->change();
});
}
public function down(): void
{
Schema::table('websites_extras', function (Blueprint $table): void {
$table->boolean('is_enabled')->nullable()->default(null)->change();
});
}
};

View File

@@ -56,6 +56,8 @@ class TenantSeeder extends Seeder
'success_color' => '#198754',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#313131',
'display_categories' => true,
'display_seach_bar' => 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,
@@ -107,6 +109,8 @@ class TenantSeeder extends Seeder
'success_color' => '#198754',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#015327',
'display_categories' => false,
'display_seach_bar' => false,
'header_logo' => $this->uploadedImage(
'images/tennants/fiesta_futbol_infantil/futbol_infantil_header.png',
'futbol_infantil_header.png',

View File

@@ -42,6 +42,8 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
$this->assertSame('9, 10, 11 y 12 de Octubre 2026', $tenant->fresh()->event_date_text);
$this->assertSame(
['color', 'event_date', 'horario', 'servicio', 'talle', 'tipo_alojamiento'],
Attribute::query()->where('tenant_codigo', $tenant->codigo)->orderBy('codigo')->pluck('codigo')->all(),

View File

@@ -53,6 +53,8 @@ class BootstrapTenantControllerTest extends TestCase
'header_logo_id' => $headerAttachment->id,
'footer_logo_id' => $footerAttachment->id,
'event_date_text' => '9, 10, 11 y 12 de Octubre 2026',
'display_categories' => false,
'display_seach_bar' => false,
]);
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
@@ -66,6 +68,8 @@ class BootstrapTenantControllerTest extends TestCase
->assertJsonPath('data.danger_color', '#0000ff')
->assertJsonPath('data.success_color', '#00ff00')
->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.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff');
$headerUrl = $response->json('data.header_logo');