Merge remote-tracking branch 'origin/develop' into feature/merkmale-symbol-seite
Deploy Test / test (push) Failing after 5m56s
Deploy Test / deploy (push) Skipped
CI Feature / test (push) Successful in 5m22s

This commit is contained in:
Lars committed 2026-11-26 08:31:23 +01:00
commit fbe4226347
32 files changed
+1640 -43

No files matched your search

@@ -0,0 +1,194 @@
<?php
namespace App\Domain\Cms\Widgets\Types;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\Pillar;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Cms\Widgets\WidgetErrors;
use App\Domain\Cms\Widgets\WidgetType;
use App\Domain\Commerce\Shop;
use App\Domain\Commerce\ShopCatalog;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
/**
* Shop-Produkte (ADR-55): die kaufbaren Produkte als Kacheln, aus derselben Datenquelle wie die Shopseite (ShopCatalog).
*
* Gespeichert werden nur Darstellungswahl und Filter (Säule, Materialart); Titel, Bild, Preis und Marker kommen zur
* Laufzeit aus den Fachdaten. Das Widget zeigt nichts, solange der Shop nicht sichtbar ist (Schalter „Shop sichtbar“).
* Eine Kachel begründet keine Berechtigung. Anders als Programm- und Modulkarten trägt es Preise und führt zur Produktseite.
*/
class ShopProductsWidget extends WidgetType
{
public function key(): string
{
return 'shop_products';
}
public function label(): string
{
return 'Shop-Produkte';
}
public function description(): string
{
return 'Die kaufbaren Produkte des Shops als Kacheln mit Bild, Marker und Preis; optional gefiltert und sortiert.';
}
public function supportedUnits(): array
{
return [2, 3, 4];
}
public function minUnits(): int
{
return 2;
}
public function preferredUnits(): int
{
return 4;
}
public function narrowBehavior(): string
{
return 'Die Kacheln stehen untereinander; ab etwa 17 rem Kachelbreite mehrere nebeneinander.';
}
public function stages(): array
{
return [
'narrow' => 'eine Kachel je Zeile',
'wide' => 'mehrere Kacheln nebeneinander ab 17 rem Kachelbreite',
];
}
public function icon(): string
{
return 'heroicon-o-shopping-bag';
}
public function schematic(): array
{
return [[2, 4, 17, 28, 'line'], [21, 4, 17, 28, 'line'], [40, 4, 17, 28, 'line'], [4, 6, 13, 10, 'image'], [23, 6, 13, 10, 'image'], [42, 6, 13, 10, 'image'], [4, 19, 11, 3, 'ink'], [23, 19, 11, 3, 'ink'], [42, 19, 11, 3, 'ink'], [4, 26, 7, 3, 'accent'], [23, 26, 7, 3, 'accent'], [42, 26, 7, 3, 'accent']];
}
public function variants(): array
{
return [
'kacheln' => 'Kacheln mit Bild',
];
}
public function settings(): array
{
return [
'sort' => ['name' => 'Alphabetisch', 'neu' => 'Neueste zuerst', 'preis' => 'Preis aufsteigend'],
'limit' => ['alle' => 'Alle Produkte', 'n3' => '3 Produkte', 'n6' => '6 Produkte', 'n9' => '9 Produkte', 'n12' => '12 Produkte', 'n24' => '24 Produkte'],
'search' => ['aus' => 'Ohne Suchfeld', 'an' => 'Mit Suchfeld'],
];
}
public function settingLabels(): array
{
return [
'sort' => ['Reihenfolge', 'Ohne Wahl gilt die Reihenfolge der Shopseite: Altbestand, Artikel, Pakete.'],
'limit' => ['Anzahl', 'Wie viele Produkte höchstens erscheinen. Ohne Wahl erscheinen alle.'],
'search' => ['Suchfeld', 'Ein Suchfeld über den Kacheln. Es wirkt auf der Shopseite; auf anderen Seiten führt die Suche in den Shop.'],
];
}
public function settingGroups(): array
{
return ['Auswahl' => ['sort', 'limit', 'search']];
}
public function dataRules(): array
{
return [
'heading' => ['nullable', 'string', 'max:160'],
'intro' => ['nullable', 'string', 'max:400'],
'pillar' => ['nullable', 'integer'],
'kind' => ['nullable', 'integer'],
];
}
public function dataFields(): array
{
return [
TextInput::make('heading')->label('Abschnittsüberschrift (optional)')->maxLength(160),
Textarea::make('intro')->label('Einleitung (optional)')->rows(2)->maxLength(400),
Select::make('pillar')
->label('Nur Produkte einer Säule (optional)')
->helperText('Nur veröffentlichte Säulen sind wählbar. Ohne Wahl erscheinen alle Produkte.')
->options(fn (): array => Pillar::query()->published()->pluck('name', 'id')->all())
->placeholder('Alle Säulen')
->native(false),
Select::make('kind')
->label('Nur eine Materialart (optional)')
->options(fn (): array => EditorialContentKind::query()->where('is_active', true)->orderBy('sort_order')->get()
->filter(fn (EditorialContentKind $kind): bool => in_array('lizenzartikel', (array) ($kind->contexts ?? []), true))
->pluck('label', 'id')->all())
->placeholder('Alle Materialarten')
->native(false),
];
}
public function clean(array $data, array $refs, WidgetErrors $errors): array
{
foreach (['heading', 'intro'] as $key) {
$data[$key] = filled($data[$key] ?? null) ? trim((string) $data[$key]) : null;
}
$pillar = filled($data['pillar'] ?? null) ? (int) $data['pillar'] : null;
if ($pillar !== null && ! Pillar::query()->published()->whereKey($pillar)->exists()) {
$errors->add('data.pillar', 'Diese Säule gibt es nicht oder sie ist nicht veröffentlicht.');
$pillar = null;
}
$kind = filled($data['kind'] ?? null) ? (int) $data['kind'] : null;
if ($kind !== null && ! EditorialContentKind::query()->whereKey($kind)->exists()) {
$errors->add('data.kind', 'Diese Materialart gibt es nicht.');
$kind = null;
}
$data['pillar'] = $pillar;
$data['kind'] = $kind;
return [$data, $refs];
}
public function resolve(array $widget, RenderContext $context): array
{
if (! Shop::visible()) {
return ['cards' => [], 'term' => '', 'shopVisible' => false];
}
$settings = is_array($widget['settings'] ?? null) ? $widget['settings'] : [];
$search = ($settings['search'] ?? 'aus') === 'an';
$term = $search && ! $context->preview ? trim((string) request()->query('suche', '')) : '';
$limit = preg_match('/^n(\d+)$/', (string) ($settings['limit'] ?? ''), $match) === 1 ? (int) $match[1] : null;
return [
'cards' => app(ShopCatalog::class)->cards($term, [
'pillar' => $widget['data']['pillar'] ?? null,
'kind' => $widget['data']['kind'] ?? null,
'sort' => $settings['sort'] ?? null,
'limit' => $limit,
]),
'term' => $term,
'shopVisible' => true,
];
}
public function summary(array $widget): string
{
$heading = $widget['data']['heading'] ?? null;
return trim(($heading ? $heading.' · ' : '').'Shop-Produkte');
}
}