feat(desfile): enhance entry reservation form and service with tenant-specific data
This commit is contained in:
@@ -2,15 +2,48 @@
|
||||
|
||||
namespace App\Shared\Forms\Services;
|
||||
|
||||
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Commerce\Catalog\Models\Variant;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
||||
|
||||
class DesfileEntryReservationFormService
|
||||
{
|
||||
/** @return array{payment_types: list<array{value: string, label: string}>} */
|
||||
public function get(): array
|
||||
/** @return array<string, mixed> */
|
||||
public function get(Tenant $tenant): array
|
||||
{
|
||||
$entry = CatalogItem::query()->forTenantCatalog($tenant)->where('slug', 'entrada')
|
||||
->with([
|
||||
'variants' => fn ($query) => $query->orderBy('id'),
|
||||
'variants.inventory',
|
||||
'variants.definitions.itemAttribute.attribute',
|
||||
'variants.eventDates',
|
||||
'variants.eventDate',
|
||||
])->first();
|
||||
$variants = $entry?->visibleVariants()
|
||||
->map(function (Variant $variant): array {
|
||||
$values = $variant->selectionValues();
|
||||
|
||||
return [
|
||||
'id' => $variant->id,
|
||||
'tipo' => (string) $values->get('tipo'),
|
||||
'sector' => (string) $values->get('sector'),
|
||||
'fila' => (string) $values->get('fila'),
|
||||
'asiento' => (string) $values->get('asiento'),
|
||||
'price' => $variant->getPrice(),
|
||||
];
|
||||
})->values() ?? collect();
|
||||
|
||||
return [
|
||||
'payment_types' => EntryReservationPaymentType::options(),
|
||||
'fields' => collect(['tipo' => 'Tipo', 'sector' => 'Sector', 'fila' => 'Fila', 'asiento' => 'Asiento'])
|
||||
->map(fn (string $label, string $key): array => [
|
||||
'key' => $key,
|
||||
'label' => $label,
|
||||
'options' => $variants->pluck($key)->unique()->sort(SORT_NATURAL)->values()
|
||||
->map(fn (string $value): array => ['value' => $value, 'label' => $value])->all(),
|
||||
])->values()->all(),
|
||||
'variants' => $variants->all(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user