Binde den Shop ins CMS ein: Seite shop, Widget Shop-Produkte, Kacheln auf der Mitgliederseite
CI Feature / test (push) Successful in 5m29s

- Eine veroeffentlichte CMS-Seite mit dem Pfad /shop bestimmt den Aufbau von /shop, sonst gilt die Standardseite
- Widget shop_products mit Filter (Saeule, Materialart), Reihenfolge, Anzahl und Suchfeld; leer, solange der Shop nicht sichtbar ist
- ShopCatalog mit Filter, Sortierung und Limit; Suchbegriff auf 100 Zeichen gekuerzt
- Sitemap ohne /shop, solange nicht gekauft werden kann
- Mitgliederseite Angebote zeigt die neuesten Produkte als Kacheln
- ADR-55, Widget-Register

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-26 08:12:45 +01:00
1 parent 1af462e1d6
commit 61c65595e1
14 files changed
+569 -12

No files matched your search

+50 -3
View File
@@ -34,12 +34,16 @@ public function __construct(
private readonly ShopMarkers $markers,
) {}
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
* @return list<array<string, mixed>>
*/
public function cards(string $term = ''): array
public function cards(string $term = '', array $options = []): array
{
$term = mb_strtolower(trim($term));
$term = mb_strtolower(mb_substr(trim($term), 0, 100));
$cards = [];
// Altbestand: Angebote mit mehreren Positionen auf einer freigegebenen Programmseite.
@@ -54,6 +58,8 @@ public function cards(string $term = ''): array
$teaser = (string) ($composition->teaser ?: FormattedText::plain($composition->summary));
$pillars = $this->pillarNames($composition->pillars);
$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['kind_id'] = $composition->editorial_content_kind_id !== null ? (int) $composition->editorial_content_kind_id : null;
if ($this->matches($term, $title.' '.$teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms.' '.implode(' ', $pillars))) {
$cards[] = $card;
@@ -74,6 +80,9 @@ public function cards(string $term = ''): array
'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['kind_id'] = $kind !== null ? (int) $kind->id : null;
$card['since'] = $this->markers->firstOffered($offerIds)?->getTimestamp() ?? 0;
if ($this->matches($term, $title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms.' '.($kind?->label ?? '').' '.implode(' ', $pillars))) {
$cards[] = $card;
@@ -94,7 +103,42 @@ public function cards(string $term = ''): array
}
}
return $cards;
return $this->arrange($cards, $options);
}
/**
* Filter, Sortierung und Höchstzahl der Kacheln (Widget und Shopseite). Ohne Angabe bleibt die Reihenfolge der
* Datenquelle.
*
* @param list<array<string, mixed>> $cards
* @param array<string, mixed> $options
* @return list<array<string, mixed>>
*/
private function arrange(array $cards, array $options): array
{
$pillar = isset($options['pillar']) ? (int) $options['pillar'] : 0;
$kind = isset($options['kind']) ? (int) $options['kind'] : 0;
if ($pillar > 0) {
$cards = array_filter($cards, fn (array $card): bool => in_array($pillar, $card['pillar_ids'] ?? [], true));
}
if ($kind > 0) {
$cards = array_filter($cards, fn (array $card): bool => ($card['kind_id'] ?? null) === $kind);
}
$cards = array_values($cards);
match ($options['sort'] ?? null) {
'name' => usort($cards, fn (array $a, array $b): int => strcmp(mb_strtolower($a['title']), mb_strtolower($b['title']))),
'neu' => usort($cards, fn (array $a, array $b): int => [$b['since'] ?? 0, mb_strtolower($a['title'])] <=> [$a['since'] ?? 0, mb_strtolower($b['title'])]),
'preis' => usort($cards, fn (array $a, array $b): int => [$a['from_cents'], mb_strtolower($a['title'])] <=> [$b['from_cents'], mb_strtolower($b['title'])]),
default => null,
};
$limit = isset($options['limit']) ? (int) $options['limit'] : 0;
return $limit > 0 ? array_slice($cards, 0, $limit) : $cards;
}
/**
@@ -120,6 +164,9 @@ private function card(string $key, string $kind, string $url, string $title, str
'symbol' => $symbol,
'pillars' => $pillars,
'markers' => $markers,
'pillar_ids' => [],
'kind_id' => null,
'since' => 0,
];
}