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

@@ -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');
}
}
+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,
];
}
+1 -1
View File
@@ -101,7 +101,7 @@ public function visible(LicenseArticle $article, array $offerIds, ?Carbon $now =
}
/** Zeitpunkt der ersten Fassung eines Angebots als Kauf. */
private function firstOffered(array $offerIds): ?Carbon
public function firstOffered(array $offerIds): ?Carbon
{
if ($offerIds === []) {
return null;
@@ -12,6 +12,7 @@
use App\Domain\Commerce\OrderHolders;
use App\Domain\Commerce\SalesTerms;
use App\Domain\Commerce\Shop;
use App\Domain\Commerce\ShopCatalog;
use App\Domain\Commerce\StaleOverview;
use App\Domain\Commerce\Stripe\StripeGateway;
use App\Domain\Entitlement\GrantIssuer;
@@ -35,7 +36,13 @@ public function offers(): View
->orderBy('name')
->get();
return view('member.offers', ['offers' => $offers, 'shop' => Shop::visible()]);
$shop = Shop::visible();
return view('member.offers', [
'offers' => $offers,
'shop' => $shop,
'cards' => $shop ? app(ShopCatalog::class)->cards('', ['sort' => 'neu', 'limit' => 6]) : [],
]);
}
public function claim(Request $request, Offer $offer, GrantIssuer $issuer): RedirectResponse
+9 -1
View File
@@ -35,6 +35,12 @@ public function offers(): View|RedirectResponse
return Shop::visible() ? redirect()->route('shop') : $this->show('angebote');
}
/** Eine veröffentlichte CMS-Seite unter einer festen App-Adresse (der Shop unter /shop). */
public function showPage(Page $page): View
{
return $this->render($page, preview: false);
}
public function preview(PageRevision $revision): View
{
$page = $revision->page;
@@ -60,7 +66,9 @@ public function devices(PageRevision $revision): View
public function sitemap(): Response
{
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get();
// Der Shop gehört nicht in die Sitemap, solange man dort nicht kaufen kann (die Seiten sind dann noindex).
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get()
->reject(fn (Page $page): bool => $page->path === '/shop' && ! Shop::checkoutOpen());
$themes = Pillar::query()->published()->get();
return response()
+12 -2
View File
@@ -2,15 +2,19 @@
namespace App\Http\Controllers;
use App\Domain\Cms\Page;
use App\Domain\Commerce\Shop;
use App\Domain\Commerce\ShopCatalog;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
/**
* Durchsuchbarer Shop: macht kaufbare Produkte auffindbar. Treffer öffnen dieselbe öffentliche Produktseite wie die
* Programmkacheln. Gelistet wird nur, was mindestens eine kaufbare Option hat; die Kacheln bildet ShopCatalog.
*
* Gibt es in der Webpräsenz eine veröffentlichte Seite „shop“, bestimmt sie den Aufbau (Banner, Grafiken, Texte und das
* Widget „Shop-Produkte“); sonst zeigt die Anwendung die Standardseite mit Suche und Kacheln (ADR-55).
*/
class ShopController extends Controller
{
@@ -23,8 +27,14 @@ public function closed(): View|RedirectResponse
return Shop::checkoutOpen() ? redirect()->route('shop') : view('shop.closed');
}
public function index(Request $request, ShopCatalog $catalog): View
public function index(Request $request, ShopCatalog $catalog, PageController $pages): View
{
$page = Page::query()->where('path', '/shop')->whereNotNull('published_revision_id')->first();
if ($page !== null) {
return $pages->showPage($page);
}
$term = trim((string) $request->query('suche', ''));
return view('shop.index', ['cards' => $catalog->cards($term), 'term' => $term]);