From f0ffb47210fd3dfad5d78761dd9915ba2f86db1e Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 26 Nov 2026 08:35:33 +0100 Subject: [PATCH] Biete in der Shopliste Auswahl, Reihenfolge, Listenansicht und Seiten MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ShopCatalog::listing mit Auswahl nach Thema, Materialart, Eignung und Nutzerkreis, Reihenfolge, Ansicht und Seiten - Listenansicht shop/zeile, gemeinsame Liste fuer Shopseite und Widget (Variante Liste, Einstellung Auswahl fuer Besucher) - Werte aus dem Abfragetext werden gegen vorhandene Werte geprueft, Felder als Liste und Zahlen ausserhalb des Bereichs sind harmlos - Suchfeld heisst nach dem Umbau Zurücksetzen statt Suche zuruecksetzen (Test bewusst angepasst) - ADR-57 Co-Authored-By: Claude Sonnet 5.5 --- .../Cms/Widgets/Types/ShopProductsWidget.php | 32 ++-- app/Domain/Commerce/ProductOptions.php | 10 +- app/Domain/Commerce/ShopCatalog.php | 151 +++++++++++++-- app/Http/Controllers/ShopController.php | 4 +- config/shop.php | 4 + docs/analysen/shop-umbauplan-2026-11-26.md | 2 +- .../12_Entscheidungsprotokoll_ADR.md | 13 ++ docs/architektur/cms-widget-registry.md | 2 +- resources/css/components/lf-shop.css | 154 +++++++++++++++ resources/views/shop/index.blade.php | 23 +-- resources/views/shop/liste.blade.php | 89 +++++++++ resources/views/shop/zeile.blade.php | 31 +++ .../views/widgets/shop_products.blade.php | 26 +-- tests/Feature/ShopListingTest.php | 181 ++++++++++++++++++ tests/Feature/ShopProductPageTest.php | 2 +- 15 files changed, 651 insertions(+), 73 deletions(-) create mode 100644 resources/views/shop/liste.blade.php create mode 100644 resources/views/shop/zeile.blade.php create mode 100644 tests/Feature/ShopListingTest.php diff --git a/app/Domain/Cms/Widgets/Types/ShopProductsWidget.php b/app/Domain/Cms/Widgets/Types/ShopProductsWidget.php index d298507..815527b 100644 --- a/app/Domain/Cms/Widgets/Types/ShopProductsWidget.php +++ b/app/Domain/Cms/Widgets/Types/ShopProductsWidget.php @@ -79,6 +79,7 @@ public function variants(): array { return [ 'kacheln' => 'Kacheln mit Bild', + 'liste' => 'Liste mit kleinem Bild', ]; } @@ -88,6 +89,7 @@ public function settings(): array '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'], + 'filter' => ['aus' => 'Ohne Auswahl', 'an' => 'Mit Suche, Auswahl, Ansicht und Seiten'], ]; } @@ -96,13 +98,14 @@ 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.'], + 'search' => ['Suchfeld', 'Ein einfaches Suchfeld über den Kacheln. Es sendet an die Seite, auf der das Widget steht.'], + 'filter' => ['Auswahl für Besucher', 'Suche, Auswahl nach Thema, Materialart, Eignung und Nutzerkreis, Reihenfolge, Umschalter Kacheln und Liste und Seiten. Sinnvoll auf der Shopseite mit vielen Produkten. Ersetzt das einfache Suchfeld und die Einstellung „Anzahl“.'], ]; } public function settingGroups(): array { - return ['Auswahl' => ['sort', 'limit', 'search']]; + return ['Auswahl' => ['sort', 'limit', 'search', 'filter']]; } public function dataRules(): array @@ -165,21 +168,28 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array public function resolve(array $widget, RenderContext $context): array { if (! Shop::visible()) { - return ['cards' => [], 'term' => '', 'shopVisible' => false]; + return ['listing' => null, 'cards' => [], 'term' => '', 'shopVisible' => false]; } $settings = is_array($widget['settings'] ?? null) ? $widget['settings'] : []; + $filters = ($settings['filter'] ?? 'aus') === 'an'; $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; + $limit = preg_match('/^n(\\d+)$/', (string) ($settings['limit'] ?? ''), $match) === 1 ? (int) $match[1] : null; + $query = $context->preview ? [] : request()->query(); + $term = ($search || $filters) && isset($query['suche']) && is_string($query['suche']) ? mb_substr(trim($query['suche']), 0, 100) : ''; + $fixed = [ + 'pillar' => $widget['data']['pillar'] ?? null, + 'kind' => $widget['data']['kind'] ?? null, + 'sort' => $settings['sort'] ?? null, + 'limit' => $filters ? null : $limit, + 'view' => ($widget['variant'] ?? 'kacheln') === 'liste' ? 'liste' : 'kacheln', + 'filters' => $filters, + ]; + $listing = app(ShopCatalog::class)->listing($filters ? $query : ['suche' => $term], $fixed); return [ - 'cards' => app(ShopCatalog::class)->cards($term, [ - 'pillar' => $widget['data']['pillar'] ?? null, - 'kind' => $widget['data']['kind'] ?? null, - 'sort' => $settings['sort'] ?? null, - 'limit' => $limit, - ]), + 'listing' => $listing, + 'cards' => $listing['cards'], 'term' => $term, 'shopVisible' => true, ]; diff --git a/app/Domain/Commerce/ProductOptions.php b/app/Domain/Commerce/ProductOptions.php index b59ebe0..d5f0ec3 100644 --- a/app/Domain/Commerce/ProductOptions.php +++ b/app/Domain/Commerce/ProductOptions.php @@ -210,7 +210,7 @@ private function optionsFor(string $key): array /** * Günstigster Preis und Zahl der Optionen je Seite einer Art ('a', 'b' oder 'c'): Kennung => Zusammenfassung. * - * @return array + * @return array, scopes: list}> */ private function summariesOf(string $kind): array { @@ -224,6 +224,8 @@ private function summariesOf(string $kind): array $summary[(int) substr($key, 2)] = [ 'from_cents' => min(array_map(fn (array $row): int => (int) $row['version']->price_cents, $rows)), 'count' => count($rows), + 'holders' => array_values(array_unique(array_map(fn (array $row): string => (string) $row['version']->holder_kind, $rows))), + 'scopes' => array_values(array_unique(array_filter(array_map(fn (array $row): ?string => $row['version']->licence_scope, $rows)))), ]; } @@ -233,7 +235,7 @@ private function summariesOf(string $kind): array /** * Artikel mit kaufbarer Option: Artikelkennung => günstigster Preis und Zahl der Optionen. * - * @return array + * @return array, scopes: list}> */ public function articleSummaries(): array { @@ -243,7 +245,7 @@ public function articleSummaries(): array /** * Pakete mit kaufbarer Option: Paketkennung => günstigster Preis und Zahl der Optionen. * - * @return array + * @return array, scopes: list}> */ public function bundleSummaries(): array { @@ -253,7 +255,7 @@ public function bundleSummaries(): array /** * Altbestand: Programmseiten mit kaufbaren Optionen (Angebote mit mehreren Positionen). * - * @return array + * @return array, scopes: list}> */ public function summaries(): array { diff --git a/app/Domain/Commerce/ShopCatalog.php b/app/Domain/Commerce/ShopCatalog.php index 31d217b..a62afff 100644 --- a/app/Domain/Commerce/ShopCatalog.php +++ b/app/Domain/Commerce/ShopCatalog.php @@ -6,6 +6,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\EditorialProfileReader; use App\Domain\Catalog\FormattedText; +use App\Domain\Catalog\LicenceScope; use App\Domain\Catalog\LicenseArticle; use App\Domain\Catalog\Pillar; use App\Domain\Catalog\PresentationMedia; @@ -37,11 +38,21 @@ public function __construct( public const SORTS = ['name' => 'Alphabetisch', 'neu' => 'Neueste zuerst', 'preis' => 'Preis aufsteigend']; /** - * @param array{pillar?: int|null, kind?: int|null, sort?: string|null, limit?: int|null} $options Filter nach Säule - * und Materialart, Sortierung (name, neu, preis) und Höchstzahl + * @param array{pillar?: int|null, kind?: int|null, holder?: string|null, scope?: string|null, sort?: string|null, limit?: int|null} $options Filter + * nach Säule, Materialart, Eignung und Nutzerkreis, Sortierung (name, neu, preis) und Höchstzahl * @return list> */ public function cards(string $term = '', array $options = []): array + { + return $this->arrange($this->all($term), $options); + } + + /** + * Alle Kacheln zu einem Suchbegriff, ungefiltert und in der Reihenfolge der Quellen. + * + * @return list> + */ + public function all(string $term = ''): array { $term = mb_strtolower(mb_substr(trim($term), 0, 100)); $cards = []; @@ -56,10 +67,13 @@ public function cards(string $term = '', array $options = []): array $title = (string) ($composition->display_title ?: $composition->designation); $teaser = (string) ($composition->teaser ?: FormattedText::plain($composition->summary)); - $pillars = $this->pillarNames($composition->pillars); + $pillarMap = $this->publishedPillars($composition->pillars); + $pillars = array_values($pillarMap); $card = $this->card('c:'.$composition->id, 'programm', route('public.program', $composition), $title, $teaser, $summaries[$composition->id], 'Programm', null, $pillars, [], $this->image($composition)); - $card['pillar_ids'] = $composition->pillars->pluck('id')->map(fn ($id): int => (int) $id)->all(); + $card['pillar_ids'] = array_keys($pillarMap); $card['kind_id'] = $composition->editorial_content_kind_id !== null ? (int) $composition->editorial_content_kind_id : null; + $card['holders'] = $summaries[$composition->id]['holders'] ?? []; + $card['scopes'] = $summaries[$composition->id]['scopes'] ?? []; if ($this->matches($term, $title.' '.$teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms.' '.implode(' ', $pillars))) { $cards[] = $card; @@ -74,15 +88,18 @@ public function cards(string $term = '', array $options = []): array $title = $this->products->articleTitle($article); $teaser = (string) ($profile->value('teaser') ?: $profile->value('summary')); $kind = $article->editorialContentKind; - $pillars = $this->pillarNames($article->pillars); + $pillarMap = $this->publishedPillars($article->pillars); + $pillars = array_values($pillarMap); $offerIds = array_map(fn ($offer): int => (int) $offer->id, $this->products->offersOfArticle($article)); $card = $this->card( 'a:'.$article->id, 'artikel', route('shop.article', $article), $title, $teaser, $articleSummaries[$article->id], (string) ($kind?->label ?? ''), $this->symbol($kind?->symbol), $pillars, $this->markers->visible($article, $offerIds), $this->image($article), ); - $card['pillar_ids'] = $article->pillars->pluck('id')->map(fn ($id): int => (int) $id)->all(); + $card['pillar_ids'] = array_keys($pillarMap); $card['kind_id'] = $kind !== null ? (int) $kind->id : null; $card['since'] = $this->markers->firstOffered($offerIds)?->getTimestamp() ?? 0; + $card['holders'] = $articleSummaries[$article->id]['holders'] ?? []; + $card['scopes'] = $articleSummaries[$article->id]['scopes'] ?? []; if ($this->matches($term, $title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms.' '.($kind?->label ?? '').' '.implode(' ', $pillars))) { $cards[] = $card; @@ -97,13 +114,15 @@ public function cards(string $term = '', array $options = []): array $names = implode(', ', array_column($contents, 'title')); $teaser = 'Paket mit '.count($contents).' '.(count($contents) === 1 ? 'Inhalt' : 'Inhalten').($names !== '' ? ': '.$names : ''); $card = $this->card('b:'.$bundle->id, 'paket', route('public.package', $bundle), (string) $bundle->name, $teaser, $bundleSummaries[$bundle->id], 'Paket', null, [], [], $this->image($bundle)); + $card['holders'] = $bundleSummaries[$bundle->id]['holders'] ?? []; + $card['scopes'] = $bundleSummaries[$bundle->id]['scopes'] ?? []; if ($this->matches($term, $bundle->name.' '.$names)) { $cards[] = $card; } } - return $this->arrange($cards, $options); + return $cards; } /** @@ -114,7 +133,7 @@ public function cards(string $term = '', array $options = []): array * @param array $options * @return list> */ - private function arrange(array $cards, array $options): array + public function arrange(array $cards, array $options): array { $pillar = isset($options['pillar']) ? (int) $options['pillar'] : 0; $kind = isset($options['kind']) ? (int) $options['kind'] : 0; @@ -127,6 +146,17 @@ private function arrange(array $cards, array $options): array $cards = array_filter($cards, fn (array $card): bool => ($card['kind_id'] ?? null) === $kind); } + $holder = (string) ($options['holder'] ?? ''); + $scope = (string) ($options['scope'] ?? ''); + + if ($holder !== '') { + $cards = array_filter($cards, fn (array $card): bool => in_array($holder, $card['holders'] ?? [], true)); + } + + if ($scope !== '') { + $cards = array_filter($cards, fn (array $card): bool => in_array($scope, $card['scopes'] ?? [], true)); + } + $cards = array_values($cards); match ($options['sort'] ?? null) { @@ -141,6 +171,103 @@ private function arrange(array $cards, array $options): array return $limit > 0 ? array_slice($cards, 0, $limit) : $cards; } + public const HOLDERS = ['person' => 'Privatpersonen', 'organisation' => 'Organisationen und Vereine']; + + public const SCOPES = [LicenceScope::SINGLE => 'Einzellizenz', LicenceScope::MULTI => 'Mehrfachlizenz']; + + /** + * Die Auswahl, die ein Besucher bei diesen Kacheln hat: nur Werte, die es gibt, und nur Auswahlfelder mit mindestens + * zwei Werten (sonst filtert nichts). + * + * @param list> $cards + * @return array{pillar: array, kind: array, holder: array, scope: array} + */ + public function facets(array $cards): array + { + $pillars = []; + $kinds = []; + $holders = []; + $scopes = []; + + foreach ($cards as $card) { + foreach (array_values($card['pillar_ids'] ?? []) as $index => $id) { + $pillars[(int) $id] = (string) ($card['pillars'][$index] ?? ''); + } + + if (($card['kind_id'] ?? null) !== null && ($card['kind_label'] ?? '') !== '') { + $kinds[(int) $card['kind_id']] = (string) $card['kind_label']; + } + + foreach ($card['holders'] ?? [] as $holder) { + if (isset(self::HOLDERS[$holder])) { + $holders[$holder] = self::HOLDERS[$holder]; + } + } + + foreach ($card['scopes'] ?? [] as $scope) { + if (isset(self::SCOPES[$scope])) { + $scopes[$scope] = self::SCOPES[$scope]; + } + } + } + + asort($pillars); + asort($kinds); + + $facets = ['pillar' => $pillars, 'kind' => $kinds, 'holder' => $holders, 'scope' => $scopes]; + + return array_map(fn (array $values): array => count($values) >= 2 ? $values : [], $facets); + } + + /** + * Die Produktliste für Shopseite und Widget: Suche, Auswahl des Besuchers (Säule, Materialart, Eignung, + * Nutzerkreis), Reihenfolge, Ansicht und Seiten. Alles kommt aus dem Abfragetext und wird gegen feste Werte + * geprüft; unbekannte Werte entfallen. + * + * @param array $query Abfrage des Besuchers (suche, saeule, art, eignung, kreis, sort, ansicht, seite) + * @param array $fixed Vorgaben der Seite (pillar, kind, sort, limit, view, filters) + * @return array + */ + public function listing(array $query, array $fixed = []): array + { + $text = fn (string $key): string => isset($query[$key]) && (is_string($query[$key]) || is_int($query[$key])) ? trim((string) $query[$key]) : ''; + $filters = (bool) ($fixed['filters'] ?? true); + $term = mb_substr($text('suche'), 0, 100); + $base = $this->arrange($this->all($term), array_intersect_key($fixed, ['pillar' => 1, 'kind' => 1])); + $facets = $filters ? $this->facets($base) : ['pillar' => [], 'kind' => [], 'holder' => [], 'scope' => []]; + $pick = function (string $key, string $facet) use ($text, $facets, $filters): int|string|null { + $value = $text($key); + + return $filters && $value !== '' && array_key_exists($value, $facets[$facet]) ? (ctype_digit($value) ? (int) $value : $value) : null; + }; + $chosen = [ + 'pillar' => $pick('saeule', 'pillar'), + 'kind' => $pick('art', 'kind'), + 'holder' => $pick('eignung', 'holder'), + 'scope' => $pick('kreis', 'scope'), + ]; + $sort = $filters && isset(self::SORTS[$text('sort')]) ? $text('sort') : ($fixed['sort'] ?? null); + $view = $filters && in_array($text('ansicht'), ['kacheln', 'liste'], true) ? $text('ansicht') : (string) ($fixed['view'] ?? 'kacheln'); + $cards = $this->arrange($base, $chosen + ['sort' => $sort, 'limit' => $fixed['limit'] ?? null]); + $perPage = max(1, (int) config('shop.per_page', 12)); + $pages = max(1, (int) ceil(count($cards) / $perPage)); + $page = $filters ? min($pages, max(1, (int) $text('seite'))) : 1; + $shown = $filters ? array_slice($cards, ($page - 1) * $perPage, $perPage) : $cards; + + return [ + 'cards' => $shown, + 'total' => count($cards), + 'page' => $page, + 'pages' => $filters ? $pages : 1, + 'facets' => $facets, + 'chosen' => $chosen, + 'sort' => $sort, + 'view' => $view, + 'term' => $term, + 'filters' => $filters, + ]; + } + /** * @param array{from_cents: int, count: int} $summary * @param list $pillars @@ -167,6 +294,8 @@ private function card(string $key, string $kind, string $url, string $title, str 'pillar_ids' => [], 'kind_id' => null, 'since' => 0, + 'holders' => [], + 'scopes' => [], ]; } @@ -179,11 +308,11 @@ private function matches(string $term, string $haystack): bool * Nur veröffentlichte Säulen sind öffentlich (Säulenverwaltung). * * @param Collection $pillars - * @return list + * @return array Kennung => Name */ - private function pillarNames(Collection $pillars): array + private function publishedPillars(Collection $pillars): array { - return $pillars->filter(fn (Pillar $pillar): bool => $pillar->published_at !== null)->map(fn (Pillar $pillar): string => (string) $pillar->name)->values()->all(); + return $pillars->filter(fn (Pillar $pillar): bool => $pillar->published_at !== null)->mapWithKeys(fn (Pillar $pillar): array => [(int) $pillar->id => (string) $pillar->name])->all(); } /** Ein Symbol zeigt nur, was die Symbolbibliothek kennt (die Auswahl wird an der Materialart geprüft, hier noch einmal). */ diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 4b6291a..c94b7b2 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -35,8 +35,6 @@ public function index(Request $request, ShopCatalog $catalog, PageController $pa return $pages->showPage($page); } - $term = trim((string) $request->query('suche', '')); - - return view('shop.index', ['cards' => $catalog->cards($term), 'term' => $term]); + return view('shop.index', ['listing' => $catalog->listing($request->query())]); } } diff --git a/config/shop.php b/config/shop.php index 23b3945..099f780 100644 --- a/config/shop.php +++ b/config/shop.php @@ -33,6 +33,10 @@ 'marker_days' => 30, + /* Produkte je Seite in der Shopliste (Kacheln und Liste). */ + + 'per_page' => 12, + /* | Kauf auf Rechnung für Vereine und Organisationen (PAY-006): auf Anfrage, Rechnung manuell durch den Betreiber. | Standardmäßig aus: Das Mitglied sieht die Möglichkeit erst, wenn der Prozess vollständig ist (Rechnungserstellung diff --git a/docs/analysen/shop-umbauplan-2026-11-26.md b/docs/analysen/shop-umbauplan-2026-11-26.md index 862ea63..3dcdbe3 100644 --- a/docs/analysen/shop-umbauplan-2026-11-26.md +++ b/docs/analysen/shop-umbauplan-2026-11-26.md @@ -28,7 +28,7 @@ ## Phasen | 2 | Kachel und Datenquelle: ein Dienst für Liste und Widget, Titelbild über die Website-Freigabe, Säulen und Materialart als Gruppen, Symbol je Materialart, Marker | umgesetzt (ADR-54) | | 3 | CMS: Seite „shop“ mit Abschnitten, Widget „Shop-Produkte“, Kacheln auf der Mitgliederseite (ADR-55) | umgesetzt; „Für dich“ folgt mit Phase 4 | | 4 | Regelmodell für freie Artikel: für alle, besitzt einen Artikel, bestimmte Konten (Freigabe je Angebot und Konto, wie bei Rabattcodes), „Für dich“ | umgesetzt (ADR-56) | -| 5 | Viele Produkte: Listenansicht, Filter, Sortierung, Seiten | offen | +| 5 | Viele Produkte: Listenansicht, Filter, Sortierung, Seiten | umgesetzt (ADR-57) | Jede Phase wird mit Tests, einer Sicherheitsdurchsicht und (bei Oberfläche) der Abnahme auf `luf-test` belegt (`docs/ux/verwaltung/abnahme/etappe-1.md`). diff --git a/docs/architektur/12_Entscheidungsprotokoll_ADR.md b/docs/architektur/12_Entscheidungsprotokoll_ADR.md index 7399d9a..353da42 100644 --- a/docs/architektur/12_Entscheidungsprotokoll_ADR.md +++ b/docs/architektur/12_Entscheidungsprotokoll_ADR.md @@ -837,3 +837,16 @@ ## ADR-56 – Regeln für freie Artikel und „Für dich“ im Mitgliederbereich **Nicht Teil dieses Schritts.** Keine Benachrichtigung per E-Mail bei einer Freigabe (das Konto sieht sie bei seinem nächsten Besuch); Gruppen und „Konto seit …“ als weitere Regeln; ein Ende des Abrufs je Angebot (dafür gibt es das Beenden der Fassung). **Folgen.** Eine additive Migration (zwei Spalten an `offers`, Tabelle `offer_releases`). **Bis zum Deployment gilt weiter die Regel „alle“** für jedes Angebot auf Abruf; die Vorgabe ändert kein bestehendes Verhalten. Wer ein Angebot auf Abruf nur bestimmten Konten geben will, stellt die Regel um, bevor er es aktiviert. **Quelle.** Anfrage von Lars vom 26.11.2026; ADR-09, ADR-47, ADR-52, ADR-55. + +## ADR-57 – Shopliste für viele Produkte: Auswahl, Reihenfolge, Listenansicht und Seiten + +**Status am 26.11.2026:** Umgesetzt auf `feature/shop-aufraeumen` (Phase 5 des Plans `docs/analysen/shop-umbauplan-2026-11-26.md`); Abnahme siehe `docs/ux/verwaltung/abnahme/etappe-1.md`, Abschnitt „Shopliste für viele Produkte“. Die Produktivfreigabe bleibt bei Lars. +**Kontext.** Kacheln sind für wenige Produkte übersichtlich; mit größeren Mengen wird die Shopseite unübersichtlich. +**Entscheidung (Auftrag von Lars, 26.11.2026).** +- **Eine Liste für Shopseite und Widget** (`ShopCatalog::listing`, `shop/liste.blade.php`): Suche, Auswahl nach **Thema** (veröffentlichte Säule), **Materialart**, **Eignung** (Privatpersonen, Organisationen und Vereine) und **Nutzerkreis** (Einzel- oder Mehrfachlizenz), **Reihenfolge** (alphabetisch, neueste zuerst, Preis aufsteigend), **Ansicht** (Kacheln oder Liste) und **Seiten** (`shop.per_page`, Vorgabe 12). Ein Auswahlfeld erscheint nur, wenn es mindestens zwei Werte gibt, die es bei den Produkten tatsächlich gibt. +- **Alles im Abfragetext, ohne Script.** Das Formular sendet per GET; Seiten- und Ansichtsumschalter sind Links, die die Auswahl behalten. Jeder Wert wird gegen die vorhandenen Werte geprüft; unbekannte, fehlerhafte oder als Liste gesendete Werte entfallen, nie ein Fehler. Der Suchbegriff ist auf 100 Zeichen gekürzt und maskiert; eine Seitenzahl außerhalb des Bereichs wird auf die erste oder letzte Seite gesetzt. +- **Listenansicht** (`shop/zeile.blade.php`) mit denselben Angaben wie die Kachel: kleines Bild oder Symbol, Art, Marker mit Wort, Titel als Link, Kurztext, Themen, Preis ab und Zahl der Optionen. Bei schmalem Fenster steht der Preis unter dem Text. +- **Widget.** Variante „Liste mit kleinem Bild“ und die Einstellung „Auswahl für Besucher“ (an: Suche, Auswahl, Ansicht, Seiten; aus: wie bisher mit Anzahl und einfachem Suchfeld). Festlegungen im Widget (Säule, Materialart) gelten immer und lassen sich vom Besucher nicht aufheben. +**Grenzen.** Die Kacheln werden bei jedem Aufruf aus den Fachdaten gebildet (kein Zwischenspeicher). Für die erwartete Zahl von Produkten (Dutzende bis wenige Hundert) genügt das; bei deutlich mehr wird ein Zwischenspeicher nötig. Pakete haben keine Materialart und kein Thema und erscheinen daher bei diesen Auswahlen nicht. +**Folgen.** Kein Schema, keine Migration. Die bisherige Suche der Shopseite bleibt (Feld „Shop durchsuchen“). +**Quelle.** Anfrage von Lars vom 26.11.2026; ADR-54, ADR-55. diff --git a/docs/architektur/cms-widget-registry.md b/docs/architektur/cms-widget-registry.md index d0a2202..7de8792 100644 --- a/docs/architektur/cms-widget-registry.md +++ b/docs/architektur/cms-widget-registry.md @@ -82,7 +82,7 @@ ## 4. Registrierte Widget-Arten | `program_card` | Programm- oder Modulkarte, Kit v1.7 | 1 | `adaptive`, `stacked` | 1–4 | `auto` (Vorgabe), `fill` | `refs.composition`, `refs.image` | | `call_to_action` | Handlungsaufruf | 1 | `standard` | 1–4 | `auto` (Vorgabe), `fill` (Abschnittshöhe füllen) | – | | `faq` | FAQ | 1 | `standard` | 2–4 | – | – | -| `shop_products` | Shop-Produkte (Kacheln aus `ShopCatalog`, ADR-55) | 1 | `kacheln` | 2–4 | – | – (Filter `data.pillar`, `data.kind`; Einstellungen `sort`, `limit`, `search`) | +| `shop_products` | Shop-Produkte (Kacheln aus `ShopCatalog`, ADR-55, ADR-57) | 1 | `kacheln`, `liste` | 2–4 | – | – (Filter `data.pillar`, `data.kind`; Einstellungen `sort`, `limit`, `search`, `filter`) | Darstellungsklassen an der Widget-Hülle: `widget widget- widget-variant-` und, wenn die Art Höhen anbietet, `widget-height-`. Premium-Ansichten: `lf-hero lf-hero--{photo-split|editorial-solid} lf-hero--height- lf-hero--accent-` und `lf-bt lf-bt--{cream|clear|navy} lf-bt--image-{left|right} lf-bt--height-`. diff --git a/resources/css/components/lf-shop.css b/resources/css/components/lf-shop.css index 60eedd9..88bb385 100644 --- a/resources/css/components/lf-shop.css +++ b/resources/css/components/lf-shop.css @@ -563,3 +563,157 @@ .shop-marker-beliebt { border-color: var(--color-success); color: var(--color-success); } + +/* + * Auswahl, Listenansicht und Seiten (ADR-57). Alles ohne Script bedienbar; die Auswahl steht im Abfragetext. + */ +.shop-filter { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); + gap: var(--space-3) var(--space-4); + align-items: end; + max-width: none; +} + +.shop-filter-field { + display: grid; + gap: var(--space-1); +} + +.shop-filter-search { + grid-column: 1 / -1; +} + +.shop-filter-actions { + display: flex; + flex-wrap: wrap; + gap: var(--space-2); +} + +.shop-viewbar { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: var(--space-3); + margin: var(--space-4) 0 0; +} + +.shop-view { + display: flex; + gap: var(--space-2); + margin: 0; +} + +.shop-view a { + padding: 0.2rem 0.8rem; + border: 2px solid var(--color-border-strong); + border-radius: var(--radius-pill); + text-decoration: none; + font-weight: 600; +} + +.shop-view a[aria-current='true'] { + background: var(--lf-navy); + border-color: var(--lf-navy); + color: var(--lf-white); +} + +.shop-rows { + list-style: none; + margin: var(--space-5) 0; + padding: 0; + display: grid; + gap: var(--space-3); +} + +.shop-row { + position: relative; + display: grid; + grid-template-columns: 7rem minmax(0, 1fr) auto; + gap: var(--space-4); + align-items: center; + background: var(--color-surface-raised); + border: 1px solid var(--color-border); + border-radius: var(--radius-card); + padding: var(--space-3) var(--space-4); +} + +.shop-row-media { + aspect-ratio: 16 / 9; + background: var(--color-surface-subtle); + border-radius: var(--radius-card); + overflow: hidden; + display: flex; + align-items: center; + justify-content: center; +} + +.shop-row-media img { + inline-size: 100%; + block-size: 100%; + object-fit: cover; +} + +.shop-row-symbol { + --sym-s: 2.5rem; +} + +.shop-row-body h2 { + margin: 0 0 var(--space-1); + font-size: var(--text-h3); +} + +.shop-row-body h2 a { + color: inherit; + text-decoration: none; +} + +.shop-row-body h2 a:hover, +.shop-row-body h2 a:focus-visible { + text-decoration: underline; +} + +.shop-row-body h2 a::after { + content: ''; + position: absolute; + inset: 0; +} + +.shop-row .shop-tile-kind { + flex-wrap: wrap; +} + +.shop-row-price { + margin: 0; + font-weight: 700; + text-align: end; + white-space: nowrap; +} + +.shop-row-price span { + display: block; + font-weight: 400; + font-size: var(--text-small); + color: var(--color-text-muted); +} + +.shop-pages { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + gap: var(--space-4); + margin: var(--space-5) 0; +} + +@media (max-width: 40rem) { + .shop-row { + grid-template-columns: 4.5rem minmax(0, 1fr); + } + + .shop-row-price { + grid-column: 1 / -1; + text-align: start; + } +} diff --git a/resources/views/shop/index.blade.php b/resources/views/shop/index.blade.php index 604ec4d..1f532f4 100644 --- a/resources/views/shop/index.blade.php +++ b/resources/views/shop/index.blade.php @@ -6,26 +6,5 @@

Shop

Hier findest du kaufbare Produkte und Pakete. Jede Kachel öffnet die Produktseite mit Inhalt und den verfügbaren Lizenzoptionen.

- - - @if ($cards === []) -
-

{{ $term !== '' ? 'Keine Treffer' : 'Noch keine kaufbaren Produkte' }}

-

{{ $term !== '' ? 'Zu „'.$term.'“ gibt es keine kaufbaren Produkte. Prüfe die Schreibweise oder setze die Suche zurück.' : 'Sobald ein Angebot aktiv ist, erscheint es hier.' }}

-
- @else -

{{ count($cards) }} {{ count($cards) === 1 ? 'Produkt' : 'Produkte' }}

-
    - @foreach ($cards as $card) - @include('shop.kachel', ['card' => $card]) - @endforeach -
- @endif + @include('shop.liste', ['listing' => $listing, 'action' => route('shop'), 'uid' => 'seite']) @endsection diff --git a/resources/views/shop/liste.blade.php b/resources/views/shop/liste.blade.php new file mode 100644 index 0000000..78280c2 --- /dev/null +++ b/resources/views/shop/liste.blade.php @@ -0,0 +1,89 @@ +{{-- + Die Produktliste des Shops: Suche, Auswahl (Säule, Materialart, Eignung, Nutzerkreis), Reihenfolge, Ansicht und Seiten. + Parameter: $listing (ShopCatalog::listing), $action (Adresse der Seite, an die das Formular sendet), $uid (Kennung + für die Feldnamen). Die Auswahl steht im Abfragetext; ohne Script bleibt alles bedienbar. +--}} +@php + $keep = ['suche', 'saeule', 'art', 'eignung', 'kreis', 'sort', 'ansicht']; + $link = fn (array $extra): string => $action.'?'.http_build_query(array_filter(array_merge(request()->only($keep), $extra), fn ($value): bool => $value !== null && $value !== '')); + $chosen = $listing['chosen']; + $facets = $listing['facets']; + $active = count(array_filter($chosen, fn ($value): bool => $value !== null)) + ($listing['term'] !== '' ? 1 : 0); +@endphp +@if ($listing['filters']) + +
+

{{ $listing['total'] }} {{ $listing['total'] === 1 ? 'Produkt' : 'Produkte' }}@if ($listing['pages'] > 1), Seite {{ $listing['page'] }} von {{ $listing['pages'] }}@endif

+

+ Kacheln + Liste +

+
+@elseif ($listing['cards'] !== []) +

{{ $listing['total'] }} {{ $listing['total'] === 1 ? 'Produkt' : 'Produkte' }}

+@endif + +@if ($listing['cards'] === []) +
+

{{ $active > 0 ? 'Keine Treffer' : 'Noch keine kaufbaren Produkte' }}

+

{{ $active > 0 ? 'Zu dieser Auswahl gibt es keine kaufbaren Produkte. Ändere die Auswahl oder setze sie zurück.' : 'Sobald ein Angebot aktiv ist, erscheint es hier.' }}

+
+@elseif ($listing['view'] === 'liste') +
    + @foreach ($listing['cards'] as $card) + @include('shop.zeile', ['card' => $card]) + @endforeach +
+@else +
    + @foreach ($listing['cards'] as $card) + @include('shop.kachel', ['card' => $card]) + @endforeach +
+@endif + +@if ($listing['pages'] > 1) + +@endif diff --git a/resources/views/shop/zeile.blade.php b/resources/views/shop/zeile.blade.php new file mode 100644 index 0000000..2db8fb7 --- /dev/null +++ b/resources/views/shop/zeile.blade.php @@ -0,0 +1,31 @@ +{{-- + Ein Produkt in der Listenansicht. Die Zeile trägt dieselben Angaben wie die Kachel: kleines Bild oder Symbol, Art, + Marker mit Wort, Titel als Link, Kurztext, Themen und Preis. +--}} +
  • + +
    +

    + @if ($card['kind_label'] !== ''){{ $card['kind_label'] }}@endif + @foreach ($card['markers'] as $marker) + {{ $marker['label'] }} + @endforeach +

    +

    {{ $card['title'] }}

    + @if ($card['teaser'] !== '')

    {{ $card['teaser'] }}

    @endif + @if ($card['pillars'] !== []) +
      + @foreach (array_slice($card['pillars'], 0, 3) as $pillar) +
    • {{ $pillar }}
    • + @endforeach +
    + @endif +
    +

    ab {{ $card['from'] }}{{ $card['count'] }} {{ $card['count'] === 1 ? 'Lizenzoption' : 'Lizenzoptionen' }}

    +
  • diff --git a/resources/views/widgets/shop_products.blade.php b/resources/views/widgets/shop_products.blade.php index f98559c..091f5f3 100644 --- a/resources/views/widgets/shop_products.blade.php +++ b/resources/views/widgets/shop_products.blade.php @@ -1,6 +1,6 @@ {{-- - Shop-Produkte (ADR-55). Die Kacheln kommen aus ShopCatalog, nichts davon wird im CMS gespeichert. Ist der Shop nicht - sichtbar, bleibt der Abschnitt öffentlich leer; die Redaktionsvorschau zeigt einen Hinweis. + Shop-Produkte (ADR-55, ADR-57). Die Produkte kommen aus ShopCatalog, nichts davon wird im CMS gespeichert. Ist der Shop + nicht sichtbar, bleibt der Abschnitt öffentlich leer; die Redaktionsvorschau zeigt einen Hinweis. --}} @if ($shopVisible || $context->preview)
    @@ -13,29 +13,17 @@ @unless ($shopVisible)

    Der Shop ist zurzeit nicht sichtbar. Öffentlich erscheint dieser Abschnitt nicht.

    @else - @if (($settings['search'] ?? 'aus') === 'an') - @endif - @if ($cards === []) -
    -

    {{ $term !== '' ? 'Keine Treffer' : 'Noch keine kaufbaren Produkte' }}

    -

    {{ $term !== '' ? 'Zu „'.$term.'“ gibt es keine kaufbaren Produkte. Prüfe die Schreibweise oder setze die Suche zurück.' : 'Sobald ein Angebot aktiv ist, erscheint es hier.' }}

    -
    - @else -

    {{ count($cards) }} {{ count($cards) === 1 ? 'Produkt' : 'Produkte' }}

    -
      - @foreach ($cards as $card) - @include('shop.kachel', ['card' => $card]) - @endforeach -
    - @endif + @include('shop.liste', ['listing' => $listing, 'action' => url()->current(), 'uid' => $widget['id'] ?? 'w']) @endunless
    @endif diff --git a/tests/Feature/ShopListingTest.php b/tests/Feature/ShopListingTest.php new file mode 100644 index 0000000..e0766fa --- /dev/null +++ b/tests/Feature/ShopListingTest.php @@ -0,0 +1,181 @@ +seedShop(); + } + + /** Zwei Säulen, je ein Artikel; zwei Materialarten. */ + private function classify(): array + { + $service = app(PillarService::class); + $grenzen = $service->create('Grenzen'); + $service->present($grenzen, 'Grenzen', 'grenzen-saeule', null, true, 10); + $konflikte = $service->create('Konfliktklärung'); + $service->present($konflikte, 'Konfliktklärung', 'konfliktklaerung', null, true, 20); + $service->assign($this->article('shop-grenzen'), [$grenzen->id]); + $service->assign($this->article('shop-konflikte'), [$konflikte->id]); + $programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail(); + $modul = EditorialContentKind::query()->where('slug', 'modul')->firstOrFail(); + $this->article('shop-grenzen')->forceFill(['editorial_content_kind_id' => $programm->id])->save(); + $this->article('shop-konflikte')->forceFill(['editorial_content_kind_id' => $modul->id])->save(); + + return [$grenzen, $konflikte, $programm, $modul]; + } + + private function titles(array $listing): array + { + return array_column($listing['cards'], 'title'); + } + + public function test_the_choices_offer_only_values_that_exist_and_only_when_there_is_a_real_choice(): void + { + [$grenzen, $konflikte, $programm, $modul] = $this->classify(); + $facets = app(ShopCatalog::class)->listing([])['facets']; + + $this->assertSame([$grenzen->id => 'Grenzen', $konflikte->id => 'Konfliktklärung'], $facets['pillar']); + $this->assertEquals([$programm->id => $programm->label, $modul->id => $modul->label], $facets['kind']); + $this->assertArrayHasKey('person', $facets['holder']); + $this->assertArrayHasKey('organisation', $facets['holder']); + + $html = $this->get(route('shop'))->assertOk()->getContent(); + $this->assertStringContainsString('name="saeule"', $html); + $this->assertStringContainsString('name="art"', $html); + $this->assertStringContainsString('name="eignung"', $html); + $this->assertStringContainsString('name="sort"', $html); + } + + public function test_a_choice_narrows_the_list_and_unknown_or_junk_values_are_ignored(): void + { + [$grenzen, , , $modul] = $this->classify(); + $catalog = app(ShopCatalog::class); + + $this->assertSame(['Grenzen setzen im Verein'], $this->titles($catalog->listing(['saeule' => (string) $grenzen->id]))); + $this->assertSame(['Konflikte im Training'], $this->titles($catalog->listing(['art' => (string) $modul->id]))); + $this->assertCount(3, $catalog->listing(['saeule' => '999999'])['cards'], 'Eine unbekannte Säule filtert nichts.'); + $this->assertCount(3, $catalog->listing(['saeule' => '1 OR 1=1', 'art' => '../x', 'eignung' => 'alle', 'kreis' => '']))->assertOk()->getContent(); + + $this->assertStringNotContainsString('', $html); + $this->assertMatchesRegularExpression('##', $html); + $this->assertMatchesRegularExpression('##', $html); + $this->assertStringContainsString('role="search"', $html); + $this->assertStringContainsString('Keine Treffer', $html); + } + + public function test_an_empty_choice_shows_an_honest_empty_state_with_a_way_back(): void + { + [$grenzen] = $this->classify(); + + $this->get(route('shop', ['saeule' => $grenzen->id, 'suche' => 'gibt-es-nicht']))->assertOk() + ->assertSee('Keine Treffer')->assertSee('Zurücksetzen'); + } + + public function test_the_widget_offers_the_choice_only_when_asked_and_keeps_its_fixed_filters(): void + { + [$grenzen] = $this->classify(); + $widget = fn (array $settings, array $data = [], string $variant = 'kacheln'): array => ['type' => 'shop_products', 'v' => 1, 'variant' => $variant, 'settings' => $settings, 'data' => $data]; + $service = app(PageService::class); + $page = Page::query()->create(['path' => '/auswahl']); + $service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$widget(['filter' => 'an'], [], 'liste')]]], null, null, null)); + $plain = Page::query()->create(['path' => '/ohne-auswahl']); + $service->publish($plain, $service->saveRevision($plain, [['layout' => 'u4', 'style' => [], 'slots' => [$widget([])]]], null, null, null)); + $fixed = Page::query()->create(['path' => '/nur-grenzen']); + $service->publish($fixed, $service->saveRevision($fixed, [['layout' => 'u4', 'style' => [], 'slots' => [$widget(['filter' => 'an'], ['pillar' => $grenzen->id])]]], null, null, null)); + + $this->get('/auswahl')->assertOk()->assertSee('name="saeule"', false)->assertSee('class="shop-rows"', false); + $this->get('/auswahl?ansicht=kacheln')->assertOk()->assertSee('class="shop-tiles"', false); + $this->get('/ohne-auswahl')->assertOk()->assertDontSee('name="saeule"', false)->assertDontSee('role="search"', false); + $this->get('/nur-grenzen')->assertOk()->assertSee('Grenzen setzen im Verein')->assertDontSee('Starterpaket') + ->assertDontSee('name="saeule"', false); + } +} diff --git a/tests/Feature/ShopProductPageTest.php b/tests/Feature/ShopProductPageTest.php index 01f5a22..73d4c75 100644 --- a/tests/Feature/ShopProductPageTest.php +++ b/tests/Feature/ShopProductPageTest.php @@ -47,7 +47,7 @@ public function test_the_shop_search_filters_and_shows_an_empty_state(): void $this->get(route('shop', ['suche' => 'gibt-es-nicht'])) ->assertOk() ->assertSee('Keine Treffer') - ->assertSee('Suche zurücksetzen'); + ->assertSee('Zurücksetzen'); } public function test_the_product_page_shows_content_and_options_with_price_rights_and_term(): void