Shopsystem + Widges #15

Merged
Lars merged 12 commits from develop into main 2026-11-26 11:16:53 +01:00
18 changed files with 991 additions and 88 deletions
Showing only changes of commit 0ac70884cc - Show all commits

No files matched your search

@@ -42,6 +42,7 @@ class EditorialContentKind extends Model
protected $fillable = [
'slug',
'label',
'symbol',
'sort_order',
'is_active',
'contexts',
+2
View File
@@ -22,12 +22,14 @@ class LicenseArticle extends Model
'successor_of_id',
'current_release_id',
'archived_at',
'shop_markers',
];
protected function casts(): array
{
return [
'archived_at' => 'datetime',
'shop_markers' => 'array',
];
}
+27
View File
@@ -4,6 +4,7 @@
use App\Domain\Media\ThumbnailRef;
use App\Domain\Media\WebsiteMedia;
use App\Domain\Media\WebsitePresentation;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
@@ -430,6 +431,32 @@ public function coverElementId(Model $subject): ?int
return null;
}
/**
* Das öffentlich zeigbare Titelbild: das erste Titel- oder Galeriebild in der Reihenfolge der Rollen, das für die
* Website freigegeben ist (WebsiteMedia). Ein nicht freigegebenes Bild wird übersprungen, nie ausgeliefert.
*/
public function coverPresentation(Model $subject): ?WebsitePresentation
{
$assignments = PresentationAssignment::query()
->with('role')
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->orderBy('position')
->get();
foreach (PresentationRole::COVER_ROLES as $slug) {
foreach ($assignments->filter(fn (PresentationAssignment $row): bool => $row->role?->slug === $slug) as $row) {
$presentation = $this->website->present((int) $row->content_element_id);
if ($presentation !== null && $presentation->kind === 'bild') {
return $presentation;
}
}
}
return null;
}
private function owned(Model $subject, int $assignmentId): PresentationAssignment
{
$assignment = PresentationAssignment::query()
+157
View File
@@ -0,0 +1,157 @@
<?php
namespace App\Domain\Commerce;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\FormattedText;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PresentationMedia;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Support\Brand\SymbolCatalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
/**
* Die Produkte des Shops als Kacheln: eine Datenquelle für die Shopseite (und später das Widget).
*
* Gelistet wird, was mindestens eine kaufbare Option hat (Artikel, Pakete mit eigener Seite, Altbestand mit
* Programmseite). Jede Kachel trägt nur öffentlich Zeigbares: Titel und Kurztext aus der Redaktion, das Titelbild nur mit
* Website-Freigabe, Säulen nur, wenn sie veröffentlicht sind, die Materialart mit ihrem Symbol, die Marker und den
* niedrigsten Preis. Nichts davon begründet eine Berechtigung (ADR-52, ADR-54).
*
* @phpstan-type Card array{key: string, kind: string, url: string, title: string, teaser: string, from: string, from_cents: int, count: int, image: ?array{url: string, alt: string}, kind_label: string, symbol: ?string, pillars: list<string>, markers: list<array{key: string, label: string}>}
*/
class ShopCatalog
{
public function __construct(
private readonly ProductOptions $products,
private readonly PublicCatalogReader $catalog,
private readonly EditorialProfileReader $profiles,
private readonly PresentationMedia $presentation,
private readonly ShopMarkers $markers,
) {}
/**
* @return list<array<string, mixed>>
*/
public function cards(string $term = ''): array
{
$term = mb_strtolower(trim($term));
$cards = [];
// Altbestand: Angebote mit mehreren Positionen auf einer freigegebenen Programmseite.
$summaries = $this->products->summaries();
foreach (Composition::query()->with(['editorialContentKind', 'pillars'])->whereIn('id', array_keys($summaries))->orderBy('designation')->get() as $composition) {
if ($this->catalog->shownVersion($composition) === null) {
continue;
}
$title = (string) ($composition->display_title ?: $composition->designation);
$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));
if ($this->matches($term, $title.' '.$teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms.' '.implode(' ', $pillars))) {
$cards[] = $card;
}
}
// Lizenzartikel mit kaufbarer Option.
$articleSummaries = $this->products->articleSummaries();
foreach (LicenseArticle::query()->with(['editorialContentKind', 'pillars', 'currentRelease'])->whereIn('id', array_keys($articleSummaries))->whereNull('archived_at')->orderBy('code')->get() as $article) {
$profile = $this->profiles->read($article, 'kachel');
$title = $this->products->articleTitle($article);
$teaser = (string) ($profile->value('teaser') ?: $profile->value('summary'));
$kind = $article->editorialContentKind;
$pillars = $this->pillarNames($article->pillars);
$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),
);
if ($this->matches($term, $title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms.' '.($kind?->label ?? '').' '.implode(' ', $pillars))) {
$cards[] = $card;
}
}
// Pakete mit eigener Produktseite.
$bundleSummaries = $this->products->bundleSummaries();
foreach (Bundle::query()->whereIn('id', array_keys($bundleSummaries))->orderBy('name')->get() as $bundle) {
$contents = $this->products->bundleContents($this->products->forBundle($bundle));
$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));
if ($this->matches($term, $bundle->name.' '.$names)) {
$cards[] = $card;
}
}
return $cards;
}
/**
* @param array{from_cents: int, count: int} $summary
* @param list<string> $pillars
* @param list<array{key: string, label: string}> $markers
* @param array{url: string, alt: string}|null $image
* @return array<string, mixed>
*/
private function card(string $key, string $kind, string $url, string $title, string $teaser, array $summary, string $kindLabel, ?string $symbol, array $pillars, array $markers, ?array $image): array
{
return [
'key' => $key,
'kind' => $kind,
'url' => $url,
'title' => $title,
'teaser' => $teaser,
'from' => Money::format($summary['from_cents']),
'from_cents' => (int) $summary['from_cents'],
'count' => (int) $summary['count'],
'image' => $image,
'kind_label' => $kindLabel,
'symbol' => $symbol,
'pillars' => $pillars,
'markers' => $markers,
];
}
private function matches(string $term, string $haystack): bool
{
return $term === '' || str_contains(mb_strtolower($haystack), $term);
}
/**
* Nur veröffentlichte Säulen sind öffentlich (Säulenverwaltung).
*
* @param Collection<int, Pillar> $pillars
* @return list<string>
*/
private function pillarNames(Collection $pillars): array
{
return $pillars->filter(fn (Pillar $pillar): bool => $pillar->published_at !== null)->map(fn (Pillar $pillar): string => (string) $pillar->name)->values()->all();
}
/** Ein Symbol zeigt nur, was die Symbolbibliothek kennt (die Auswahl wird an der Materialart geprüft, hier noch einmal). */
private function symbol(?string $key): ?string
{
return is_string($key) && $key !== '' && array_key_exists($key, SymbolCatalog::options()) ? $key : null;
}
/**
* @return array{url: string, alt: string}|null
*/
private function image(Model $subject): ?array
{
$presentation = $this->presentation->coverPresentation($subject);
return $presentation === null ? null : ['url' => $presentation->url, 'alt' => $presentation->alt];
}
}
+122
View File
@@ -0,0 +1,122 @@
<?php
namespace App\Domain\Commerce;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\OfferVersion;
use Illuminate\Support\Carbon;
/**
* Produktmarker „Neu“, „Aktualisiert“ und „Beliebt“ an einer Kachel (ADR-54).
*
* „Neu“ und „Aktualisiert“ folgen automatisch den Daten (erstes Angebot als Kauf, neuer Stand), jeweils für eine feste
* Zahl Tage (`shop.marker_days`); die Redaktion kann sie auch fest an- oder abschalten. „Beliebt“ setzt die Redaktion
* von Hand, solange es keine Verkaufszahlen gibt. Ein Marker trägt immer sein Wort, nie nur Farbe oder Symbol.
*/
class ShopMarkers
{
public const KEYS = ['neu' => 'Neu', 'aktualisiert' => 'Aktualisiert', 'beliebt' => 'Beliebt'];
/** Erlaubte Einstellungen je Marker; der erste Wert ist die Vorgabe. */
public const CHOICES = [
'neu' => ['auto' => 'Automatisch (zeitlich begrenzt nach dem ersten Angebot)', 'an' => 'Immer anzeigen', 'aus' => 'Nie anzeigen'],
'aktualisiert' => ['auto' => 'Automatisch (zeitlich begrenzt nach einem neuen Stand)', 'an' => 'Immer anzeigen', 'aus' => 'Nie anzeigen'],
'beliebt' => ['aus' => 'Nicht anzeigen', 'an' => 'Anzeigen'],
];
/**
* Die Einstellungen des Artikels mit den Vorgaben für fehlende oder ungültige Werte.
*
* @return array{neu: string, aktualisiert: string, beliebt: string}
*/
public function settings(LicenseArticle $article): array
{
$stored = is_array($article->shop_markers) ? $article->shop_markers : [];
$settings = [];
foreach (self::CHOICES as $key => $choices) {
$value = $stored[$key] ?? null;
$settings[$key] = is_string($value) && array_key_exists($value, $choices) ? $value : array_key_first($choices);
}
return $settings;
}
/**
* @param array<string, mixed> $choices
*/
public function save(LicenseArticle $article, array $choices): void
{
$settings = [];
foreach (self::CHOICES as $key => $allowed) {
$value = $choices[$key] ?? array_key_first($allowed);
if (! is_string($value) || ! array_key_exists($value, $allowed)) {
throw new DomainRuleException('Der Marker „'.self::KEYS[$key].'“ hat eine unzulässige Einstellung.');
}
$settings[$key] = $value;
}
$article->shop_markers = $settings;
$article->save();
}
/**
* Die anzuzeigenden Marker in fester Reihenfolge.
*
* @param list<int> $offerIds Angebote dieses Artikels (Optionen)
* @return list<array{key: string, label: string}>
*/
public function visible(LicenseArticle $article, array $offerIds, ?Carbon $now = null): array
{
$now ??= now();
$settings = $this->settings($article);
$days = max(1, (int) config('shop.marker_days', 30));
$limit = $now->copy()->subDays($days);
$isNew = match ($settings['neu']) {
'an' => true,
'aus' => false,
default => $this->firstOffered($offerIds)?->greaterThanOrEqualTo($limit) ?? false,
};
$isUpdated = match ($settings['aktualisiert']) {
'an' => true,
'aus' => false,
default => ! $isNew && $this->updatedAt($article)?->greaterThanOrEqualTo($limit) === true,
};
$markers = [];
foreach (['neu' => $isNew, 'aktualisiert' => $isUpdated, 'beliebt' => $settings['beliebt'] === 'an'] as $key => $shown) {
if ($shown) {
$markers[] = ['key' => $key, 'label' => self::KEYS[$key]];
}
}
return $markers;
}
/** Zeitpunkt der ersten Fassung eines Angebots als Kauf. */
private function firstOffered(array $offerIds): ?Carbon
{
if ($offerIds === []) {
return null;
}
$first = OfferVersion::query()->whereIn('offer_id', $offerIds)->where('grant_kind', 'kauf')->min('created_at');
return $first === null ? null : Carbon::parse($first);
}
/** Zeitpunkt des neuesten Stands, sofern es nicht der erste ist. */
private function updatedAt(LicenseArticle $article): ?Carbon
{
$release = $article->currentRelease;
return $release !== null && (int) $release->number > 1 && $release->created_at !== null ? Carbon::parse($release->created_at) : null;
}
}
@@ -14,6 +14,8 @@
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Resources\Pillars\PillarResource;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\SymbolField;
use App\Support\Brand\SymbolCatalog;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Forms\Components\Checkbox;
@@ -261,6 +263,8 @@ private function formular(?Model $record): array
];
if ($this->istMaterialart()) {
$felder[] = SymbolField::make('symbol', 'Symbol im Shop')
->helperText('Optional. Das Symbol steht auf der Shopkachel bei Artikeln dieser Materialart, auch wenn kein Bild gepflegt ist.');
$system = $record instanceof EditorialContentKind && $record->isSystem();
$felder[] = CheckboxList::make('contexts')
->label('Zulässig für')
@@ -325,6 +329,7 @@ private function bearbeitenAction(): Action
->schema(fn (Model $record): array => $this->formular($record))
->fillForm(fn (Model $record): array => [
'label' => $record->label,
'symbol' => $record instanceof EditorialContentKind ? $record->symbol : null,
'contexts' => $record instanceof EditorialContentKind ? (array) ($record->contexts ?? []) : [],
])
->modalSubmitActionLabel('Speichern')
@@ -337,11 +342,21 @@ private function bearbeitenAction(): Action
$record->contexts = $this->kontexte((array) $data['contexts']);
}
if ($record instanceof EditorialContentKind) {
$record->symbol = $this->symbol($data['symbol'] ?? null);
}
$record->save();
Notification::make()->success()->title('Gespeichert')->body('Die neue Bezeichnung gilt sofort in Redaktion, Filtern und Picker.')->send();
});
}
/** Ein Symbol wird nur gespeichert, wenn die Symbolbibliothek es kennt; sonst bleibt die Materialart ohne Symbol. */
private function symbol(mixed $value): ?string
{
return is_string($value) && array_key_exists($value, SymbolCatalog::options()) ? $value : null;
}
private function anlegen(array $data): void
{
$label = trim((string) $data['label']);
@@ -354,6 +369,7 @@ private function anlegen(array $data): void
'sort_order' => (int) EditorialContentKind::query()->max('sort_order') + 10,
'is_active' => true,
'contexts' => $this->kontexte((array) ($data['contexts'] ?? [])),
'symbol' => $this->symbol($data['symbol'] ?? null),
]);
} else {
$dimension = $this->dimension();
@@ -22,6 +22,7 @@
use App\Domain\Catalog\StatusValue;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
use App\Domain\Commerce\ShopMarkers;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Resources\Offers\OfferResource;
@@ -554,6 +555,50 @@ public function optionAction(): Action
});
}
/** Die Marker, die die Kachel im Shop gerade zeigt (Wort je Marker), mit der Einstellung der Redaktion. */
public function markerRows(): array
{
/** @var LicenseArticle $article */
$article = $this->getRecord();
$markers = app(ShopMarkers::class);
$offerIds = array_map(fn (Offer $offer): int => (int) $offer->id, app(ProductOptions::class)->offersOfArticle($article));
return [
'sichtbar' => array_column($markers->visible($article, $offerIds), 'label'),
'einstellung' => $markers->settings($article),
];
}
/**
* Marker für die Kachel im Shop: „Neu“ und „Aktualisiert“ folgen automatisch den Daten und lassen sich fest an- oder
* abschalten, „Beliebt“ setzt die Redaktion von Hand. Die Aktion speichert nur die Marker, sonst nichts (nicht die
* Redaktion des Artikels).
*/
public function markersAction(): Action
{
return Action::make('markers')
->modalWidth('lg')
->modalHeading('Marker für die Kachel im Shop')
->modalDescription('Marker erscheinen mit ihrem Wort auf der Kachel des Artikels. „Neu“ und „Aktualisiert“ richten sich automatisch nach den Daten; hier kannst du sie fest an- oder abschalten. „Beliebt“ setzt du von Hand, bis es Verkaufszahlen gibt.')
->modalSubmitActionLabel('Marker speichern')
->fillForm(fn (): array => $this->markerRows()['einstellung'])
->schema(collect(ShopMarkers::CHOICES)->map(fn (array $choices, string $key): Select => Select::make($key)
->label(ShopMarkers::KEYS[$key])
->options($choices)
->required()
->native(false))->values()->all())
->action(function (array $data): void {
$this->report(function () use ($data): string {
/** @var LicenseArticle $article */
$article = $this->getRecord();
app(ShopMarkers::class)->save($article, $data);
return 'Die Marker sind gespeichert.';
}, 'Die Marker sind gespeichert.');
$this->refreshRecord();
});
}
/** Eine Option aus dem Verkauf nehmen: nur die aktive Fassung dieser Option wird beendet. */
public function optionEndAction(): Action
{
+5 -81
View File
@@ -2,22 +2,15 @@
namespace App\Http\Controllers;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\FormattedText;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
use App\Domain\Commerce\Shop;
use App\Domain\Commerce\ShopCatalog;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
/**
* Durchsuchbarer Shop (Etappe 1): macht kaufbare Produkte auffindbar. Treffer öffnen dieselbe öffentliche Produktseite
* wie die Programmkacheln. Gelistet wird nur, was zur Anzeige freigegeben ist und mindestens eine kaufbare Option hat.
* 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.
*/
class ShopController extends Controller
{
@@ -30,79 +23,10 @@ public function closed(): View|RedirectResponse
return Shop::checkoutOpen() ? redirect()->route('shop') : view('shop.closed');
}
public function index(Request $request, ProductOptions $products, PublicCatalogReader $catalog): View
public function index(Request $request, ShopCatalog $catalog): View
{
$term = trim((string) $request->query('suche', ''));
$summaries = $products->summaries();
$cards = [];
foreach (Composition::query()->whereIn('id', array_keys($summaries))->orderBy('designation')->get() as $composition) {
$version = $catalog->shownVersion($composition);
if ($version === null) {
continue;
}
$title = (string) ($composition->display_title ?: $composition->designation);
$haystack = mb_strtolower($title.' '.$composition->teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms);
if ($term !== '' && ! str_contains($haystack, mb_strtolower($term))) {
continue;
}
$summary = $summaries[$composition->id];
$cards[] = [
'url' => route('public.program', $composition),
'title' => $title,
'teaser' => (string) ($composition->teaser ?: FormattedText::plain($composition->summary)),
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
// Lizenzartikel mit kaufbarer Option: Titel und Kurztext aus der Redaktion des Artikels (sonst seines Inhalts).
$articleSummaries = $products->articleSummaries();
foreach (LicenseArticle::query()->whereIn('id', array_keys($articleSummaries))->whereNull('archived_at')->orderBy('code')->get() as $article) {
$profile = app(EditorialProfileReader::class)->read($article, 'kachel');
$title = $products->articleTitle($article);
$teaser = (string) ($profile->value('teaser') ?: $profile->value('summary'));
$haystack = mb_strtolower($title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms);
if ($term !== '' && ! str_contains($haystack, mb_strtolower($term))) {
continue;
}
$summary = $articleSummaries[$article->id];
$cards[] = [
'url' => route('shop.article', $article),
'title' => $title,
'teaser' => $teaser,
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
// Pakete mit eigener Produktseite: gelistet mit Name und enthaltenen Artikeln.
foreach (Bundle::query()->whereIn('id', array_keys($products->bundleSummaries()))->orderBy('name')->get() as $bundle) {
$options = $products->forBundle($bundle);
$contents = $products->bundleContents($options);
$names = implode(', ', array_column($contents, 'title'));
if ($term !== '' && ! str_contains(mb_strtolower($bundle->name.' '.$names), mb_strtolower($term))) {
continue;
}
$summary = $products->bundleSummaries()[$bundle->id];
$cards[] = [
'url' => route('public.package', $bundle),
'title' => (string) $bundle->name,
'teaser' => 'Paket mit '.count($contents).' '.(count($contents) === 1 ? 'Inhalt' : 'Inhalten').($names !== '' ? ': '.$names : ''),
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
return view('shop.index', ['cards' => $cards, 'term' => $term]);
return view('shop.index', ['cards' => $catalog->cards($term), 'term' => $term]);
}
}
+7
View File
@@ -26,6 +26,13 @@
'public' => (bool) env('SHOP_PUBLIC', false),
/*
| Produktmarker „Neu“ und „Aktualisiert“ erscheinen automatisch für diese Zahl Tage (ShopMarkers). Eine Einstellung
| der Redaktion am Lizenzartikel hat Vorrang.
*/
'marker_days' => 30,
/*
| 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
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Shopdarstellung (ADR-54), rein ergänzend: ein Symbol je Materialart (Schlüssel der Symbolbibliothek) und die Marker
* „Neu“, „Aktualisiert“, „Beliebt“ je Lizenzartikel. Beide Spalten sind leer zulässig; ein Rollback des Codes lässt sie
* unbenutzt liegen.
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('editorial_content_kinds', function (Blueprint $table): void {
$table->string('symbol', 60)->nullable()->after('label');
});
Schema::table('license_articles', function (Blueprint $table): void {
$table->json('shop_markers')->nullable();
});
}
public function down(): void
{
Schema::table('license_articles', function (Blueprint $table): void {
$table->dropColumn('shop_markers');
});
Schema::table('editorial_content_kinds', function (Blueprint $table): void {
$table->dropColumn('symbol');
});
}
};
+2 -2
View File
@@ -24,8 +24,8 @@ ## Phasen
| Phase | Inhalt | Stand |
|---|---|---|
| 1 | Aufräumen: Einzelkauf entfernen, zwei Schalter mit Hinweisseite, „Jetzt kaufen“, Menüpunkt „Shop“ nur bei sichtbarem Shop, `/angebote` leitet auf `/shop`, Mitgliederseite ohne Kauf | in Arbeit |
| 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 | offen |
| 1 | Aufräumen: Einzelkauf entfernen, zwei Schalter mit Hinweisseite, „Jetzt kaufen“, Menüpunkt „Shop“ nur bei sichtbarem Shop, `/angebote` leitet auf `/shop`, Mitgliederseite ohne Kauf | umgesetzt und auf `luf-test` abgenommen (ADR-53) |
| 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 um die Liste, Widget „Shop-Produkte“, Mitgliederseite „Für dich“ mit dem Widget darunter | offen |
| 4 | Regelmodell für freie Artikel: für alle, besitzt einen Artikel, bestimmte Konten (Freigabe je Angebot und Konto, wie bei Rabattcodes) | offen |
| 5 | Viele Produkte: Listenansicht, Filter, Sortierung, Seiten | offen |
@@ -797,3 +797,16 @@ ## ADR-53 – Shop: zwei Schalter in Produktion, Kauf nur über die Kasse, „Je
**Alternativen.** Ein Schalter mit drei Stufen (verworfen: zwei unabhängige Bedingungen lassen sich einzeln testen und einzeln dokumentieren). Der Einzelkauf bleibt als Abkürzung (verworfen: er umgeht die Pflichtangaben).
**Folgen.** Kein Schemawechsel. Auf Prod bleibt ohne neue Einstellung alles aus. `SHOP_PUBLIC=true` macht den Shop sichtbar, ohne dass gekauft werden kann. **Offene Bestellungen**, die der alte Einzelkauf auf Prod angelegt hat, bleiben bestehen; Lesen und Löschen entscheidet Lars. Bis zu den Regeln für freie Artikel (Phase 4) kann jedes angemeldete Konto jedes Abrufangebot übernehmen.
**Quelle.** Anfrage von Lars vom 26.11.2026; ADR-42, ADR-47, ADR-52.
## ADR-54 – Shopkachel: Titelbild, Säulen, Materialart mit Symbol und Marker aus einer Datenquelle
**Status am 26.11.2026:** Umgesetzt auf `feature/shop-aufraeumen` (Phase 2 des Plans `docs/analysen/shop-umbauplan-2026-11-26.md`); Abnahme auf luf-test siehe `docs/ux/verwaltung/abnahme/etappe-1.md`, Abschnitt „Shopkachel“. Die Produktivfreigabe bleibt bei Lars.
**Kontext.** Die Kachel im Shop zeigte nur Titel, Kurztext und „ab Preis“. Die gepflegten Titelbilder, die Säulen, die Materialart und Marker fehlten, und die Kachelbildung stand dreifach im Controller.
**Entscheidung (Auftrag von Lars, 26.11.2026).**
- **Eine Datenquelle.** `App\Domain\Commerce\ShopCatalog::cards()` liefert die Kacheln für Artikel, Pakete mit eigener Seite und den Altbestand mit Programmseite. Die Shopseite nutzt sie, das Widget (Phase 3) nutzt dieselbe. Die Kachel ist `shop/kachel.blade.php`.
- **Titelbild nur mit Website-Freigabe.** `PresentationMedia::coverPresentation` nimmt das erste Titel- oder Galeriebild in der Reihenfolge der Rollen, das über `WebsiteMedia` freigegeben ist, und überspringt nicht freigegebene (nie ausgeliefert, nie verlinkt). Es gelten nur Bilder, keine Filme. Das Bild ist schmückend (leeres `alt`), der Titel ist der Link. Ohne Bild trägt eine helle Tafel das Symbol der Materialart.
- **Gruppen aus dem Bestand.** Säulen (`PillarService`), nur veröffentlichte, bis zu drei je Kachel; die Suche findet auch über Säule und Materialart. Es gibt keine neue Taxonomie.
- **Symbol je Materialart.** Neue Spalte `editorial_content_kinds.symbol` (Schlüssel der Symbolbibliothek, nur wenn der Katalog ihn kennt), gepflegt unter „Redaktionelle Stammdaten“ mit dem Symbolwähler.
- **Marker.** Neue Spalte `license_articles.shop_markers`. „Neu“ (erstes Angebot als Kauf) und „Aktualisiert“ (neuer Stand, nie zusammen mit „Neu“) folgen automatisch für `shop.marker_days` (30) Tage und lassen sich am Artikel fest an- oder abschalten; „Beliebt“ setzt die Redaktion von Hand, bis es Verkaufszahlen gibt. Ein Marker trägt immer sein Wort. Die Aktion „Marker ändern“ im Abschnitt „Im Shop verkaufen“ speichert nur die Marker, nicht die Redaktion des Artikels. Sterne und Kundenbewertungen folgen später und sind nicht vorbereitet.
**Folgen.** Zwei neue, leer zulässige Spalten; ein Rollback des Codes lässt sie unbenutzt liegen. Ohne Pflege erscheint die Kachel wie bisher, nur mit Platzhalter statt Bild.
**Quelle.** Anfrage von Lars vom 26.11.2026; ADR-30, ADR-40, ADR-52, ADR-53.
+2
View File
@@ -184,6 +184,8 @@ ## Verkaufsstart: Freigabe und Betrieb (Stand 24.11.2026, vorbereitet, nicht fre
Außerhalb der Produktion sind beide Schalter an, sobald `PAYMENT_DRIVER` `test` oder `stripe` (Testschlüssel) ist. Die Umgebungsdatei ändert nur Lars; nach einer Änderung den letzten Lauf des Deploy-Workflows erneut starten (siehe „Env-Datei ändern“). Die Verwaltungsseite „Verkauf → Verkaufsstart“ zeigt beide Schalter.
**Shopkachel (ADR-54):** Migration `2026_12_01_100000_add_shop_presentation_fields`, rein ergänzend (Spalten `editorial_content_kinds.symbol` und `license_articles.shop_markers`, beide leer zulässig; bei einem Rollback des Codes bleiben sie ungenutzt liegen). Titelbilder erscheinen nur mit Website-Freigabe des Mediums.
Weitere Einstellungen: `SHOP_INVOICE` (Standard **aus**: Kauf auf Rechnung für Organisationen wird Mitgliedern erst angeboten, wenn der Prozess vollständig ist; die Umsetzung bleibt erhalten, vorhandene Rechnungsbestellungen bleiben in der Verwaltung bearbeitbar; `true` schaltet die Option im Checkout ein), `SHOP_PRICE_NOTE` (Preis- und Steuerhinweis im Warenkorb, Standard „Alle Preise in Euro.“), `STRIPE_TAX_RATE_ID` (im Preis enthaltener Steuersatz; Steuerstatus offen, OPEN-06). Die Verwaltungsseite **Verkauf → Verkaufsstart** zeigt den Zustand ohne Schlüssel.
- **Erstattung bei Stripe:** `Checkout::refund` ruft vor dem Entzug der Rechte `POST /v1/refunds` (Vollbetrag, Idempotenzschlüssel `luf-refund-<Bestellung>-<Zahlung>`) auf; schlägt das fehl, bleibt die Bestellung unverändert. Dafür muss der API-Schlüssel das Recht „Refunds: write“ haben (bei eingeschränktem Schlüssel `rk_…` prüfen). Die Zahlungsabsicht (`payment_intent`) wird aus der signierten Meldung gespeichert, sonst bei Stripe abgefragt.
+142
View File
@@ -421,3 +421,145 @@ .mb-withdraw textarea {
width: 100%;
margin: var(--space-2) 0 var(--space-3);
}
/*
* Produktkachel (ADR-54): Titelbild oder Platzhalter mit Symbol der Materialart, Marker mit Wort, Art, Titel, Kurztext,
* Themen und Preis. Bilder erscheinen nur mit Website-Freigabe; ohne Bild trägt eine helle Tafel das Symbol.
*/
.shop-tile {
padding: 0;
display: flex;
flex-direction: column;
overflow: hidden;
}
.shop-tile-media {
position: relative;
aspect-ratio: 16 / 9;
background: var(--color-surface-subtle);
display: flex;
align-items: center;
justify-content: center;
border-bottom: 1px solid var(--color-border);
}
.shop-tile-media img {
inline-size: 100%;
block-size: 100%;
object-fit: cover;
display: block;
}
.shop-tile-symbol {
--sym-s: 4.5rem;
}
.shop-tile-body {
padding: var(--space-4) var(--space-5) var(--space-5);
display: flex;
flex-direction: column;
flex: 1;
}
.shop-tile-kind {
display: flex;
align-items: center;
gap: var(--space-2);
margin: 0 0 var(--space-2);
color: var(--color-text-muted);
font-size: var(--text-small);
font-weight: 600;
}
.shop-tile-kind-symbol {
--sym-s: 1.25rem;
}
.shop-tile-body h2 {
margin: 0 0 var(--space-2);
}
.shop-tile-body h2 a {
color: inherit;
text-decoration: none;
}
.shop-tile-body h2 a:hover,
.shop-tile-body h2 a:focus-visible {
text-decoration: underline;
}
/* Die ganze Kachel ist klickbar; der Link im Titel bleibt der einzige Tabstopp. */
.shop-tile {
position: relative;
}
.shop-tile-body h2 a::after {
content: '';
position: absolute;
inset: 0;
}
.shop-tile-teaser {
margin: 0 0 var(--space-3);
color: var(--color-text);
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.shop-tile-pillars {
list-style: none;
margin: 0 0 var(--space-3);
padding: 0;
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
}
.shop-tile-pillars li {
padding: 0.1rem 0.6rem;
border: 1px solid var(--color-border-strong);
border-radius: var(--radius-pill);
font-size: var(--text-small);
color: var(--color-text-muted);
}
.shop-tile-price {
margin-top: auto;
padding-top: var(--space-3);
}
.shop-markers {
position: absolute;
inset-block-start: var(--space-3);
inset-inline-start: var(--space-3);
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
}
.shop-marker {
padding: 0.15rem 0.7rem;
border-radius: var(--radius-pill);
border: 2px solid var(--lf-navy);
background: var(--color-surface);
color: var(--lf-navy);
font-weight: 700;
font-size: var(--text-small);
}
.shop-marker-neu {
background: var(--color-accent);
}
.shop-marker-aktualisiert {
background: var(--color-info-surface);
}
.shop-marker-beliebt {
background: var(--color-success-surface);
border-color: var(--color-success);
color: var(--color-success);
}
@@ -108,6 +108,12 @@
</ul>
@endif
<div><button type="button" class="vw-btn is-line" wire:click="mountAction('option')">@include('filament.verwaltung.icon', ['name' => 'plus'])Option hinzufügen</button></div>
@php($marker = $this->markerRows())
<div class="vw-spalte-kopf">
<h3 id="artikel-marker">Marker auf der Kachel</h3>
<span class="vw-feld-hilfe">Zurzeit: {{ $marker['sichtbar'] === [] ? 'kein Marker' : implode(', ', $marker['sichtbar']) }}. „Neu“ und „Aktualisiert“ richten sich automatisch nach den Daten, „Beliebt“ setzt du von Hand.</span>
<span class="vw-zeilenaktionen"><button type="button" class="vw-link" wire:click="mountAction('markers')">Marker ändern</button></span>
</div>
@endif
</section>
</div>
+1 -5
View File
@@ -24,11 +24,7 @@
<p class="shop-count" role="status">{{ count($cards) }} {{ count($cards) === 1 ? 'Produkt' : 'Produkte' }}</p>
<ul class="shop-tiles">
@foreach ($cards as $card)
<li class="shop-tile">
<h2><a href="{{ $card['url'] }}">{{ $card['title'] }}</a></h2>
@if ($card['teaser'] !== '')<p>{{ $card['teaser'] }}</p>@endif
<p class="shop-tile-price">ab {{ $card['from'] }} · {{ $card['count'] }} {{ $card['count'] === 1 ? 'Lizenzoption' : 'Lizenzoptionen' }}</p>
</li>
@include('shop.kachel', ['card' => $card])
@endforeach
</ul>
@endif
+42
View File
@@ -0,0 +1,42 @@
{{--
Eine Produktkachel des Shops. Parameter: $card (ShopCatalog). Die Kachel trägt nur Öffentliches: Titelbild nur mit
Website-Freigabe, Säulen nur veröffentlicht, die Materialart mit ihrem Symbol, die Marker mit Wort. Das Bild ist
schmückend (leeres alt), der Titel ist der Link.
--}}
<li class="shop-tile">
<div class="shop-tile-media @if ($card['image'] === null) is-placeholder @endif" aria-hidden="true">
@if ($card['image'] !== null)
<img src="{{ $card['image']['url'] }}" alt="" loading="lazy" decoding="async">
@elseif ($card['symbol'] !== null)
<x-brand.symbol :name="$card['symbol']" class="shop-tile-symbol" />
@endif
@if ($card['markers'] !== [])
<span class="shop-markers">
@foreach ($card['markers'] as $marker)
<span class="shop-marker shop-marker-{{ $marker['key'] }}">{{ $marker['label'] }}</span>
@endforeach
</span>
@endif
</div>
<div class="shop-tile-body">
@if ($card['markers'] !== [])
<p class="sr-only">{{ implode(', ', array_column($card['markers'], 'label')) }}</p>
@endif
@if ($card['kind_label'] !== '')
<p class="shop-tile-kind">
@if ($card['symbol'] !== null && $card['image'] !== null)<x-brand.symbol :name="$card['symbol']" class="shop-tile-kind-symbol" aria-hidden="true" />@endif
<span>{{ $card['kind_label'] }}</span>
</p>
@endif
<h2><a href="{{ $card['url'] }}">{{ $card['title'] }}</a></h2>
@if ($card['teaser'] !== '')<p class="shop-tile-teaser">{{ $card['teaser'] }}</p>@endif
@if ($card['pillars'] !== [])
<ul class="shop-tile-pillars" aria-label="Themen">
@foreach (array_slice($card['pillars'], 0, 3) as $pillar)
<li>{{ $pillar }}</li>
@endforeach
</ul>
@endif
<p class="shop-tile-price">ab {{ $card['from'] }} · {{ $card['count'] }} {{ $card['count'] === 1 ? 'Lizenzoption' : 'Lizenzoptionen' }}</p>
</div>
</li>
+366
View File
@@ -0,0 +1,366 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\PillarService;
use App\Domain\Catalog\PresentationAssignment;
use App\Domain\Catalog\PresentationRole;
use App\Domain\Commerce\ShopCatalog;
use App\Domain\Commerce\ShopMarkers;
use App\Filament\Pages\RedaktionelleStammdaten;
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
use App\Models\User;
use App\Support\Brand\SymbolCatalog;
use Filament\Actions\Testing\TestAction;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\Support\BuildsShop;
use Tests\TestCase;
/**
* Shopkachel (ADR-54): Titelbild nur mit Website-Freigabe, Säulen nur veröffentlicht, Materialart mit Symbol, Marker mit
* Wort, eine Datenquelle für die Shopseite.
*/
class ShopTilesTest extends TestCase
{
use BuildsShop;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
Storage::fake('media_public');
$this->seedShop();
}
private function konflikte(): LicenseArticle
{
return $this->article('shop-konflikte');
}
/** Ein Bildelement, optional für die Website freigegeben (Ableitung liegt im öffentlichen Speicher). */
private function image(string $title, bool $released): ContentElement
{
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
$element->display_title = $title;
$element->save();
if ($released) {
$path = 'website/'.$element->id.'/datei.jpg';
Storage::disk('media_public')->put($path, 'bild');
$element->forceFill(['website_released_at' => now(), 'website_public_path' => $path, 'website_alt' => 'Alt '.$title])->save();
}
return $element->fresh();
}
private function cover(LicenseArticle $article, ContentElement $element, string $role = 'titelbild', int $position = 1): void
{
PresentationAssignment::query()->create([
'subject_type' => $article->getMorphClass(),
'subject_id' => $article->id,
'content_element_id' => $element->id,
'presentation_role_id' => PresentationRole::query()->where('slug', $role)->value('id'),
'position' => $position,
]);
}
private function card(string $key = 'a:'): array
{
$cards = app(ShopCatalog::class)->cards();
$found = array_values(array_filter($cards, fn (array $card): bool => $card['key'] === $key.$this->konflikte()->id));
$this->assertCount(1, $found);
return $found[0];
}
/** Zahl der Bilder in den Kachelflächen (das Logo im Kopf zählt nicht). */
private function tileImages(string $html): int
{
return preg_match_all('#<div class="shop-tile-media[^"]*"[^>]*>\s*<img#', $html);
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
private function keeper(): User
{
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
// ---- Bild ---------------------------------------------------------------------------------------------------------
public function test_without_a_released_cover_the_tile_has_no_image_and_a_placeholder(): void
{
$this->assertNull($this->card()['image']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('is-placeholder', $html);
$this->assertSame(0, $this->tileImages($html));
}
public function test_a_cover_without_website_release_is_never_shown_or_linked(): void
{
$private = $this->image('Privates Titelbild', released: false);
$this->cover($this->konflikte(), $private);
$this->assertNull($this->card()['image']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertSame(0, $this->tileImages($html));
$this->assertStringNotContainsString('website-medien/'.$private->id, $html);
$this->assertStringNotContainsString('originals', $html);
$this->assertStringNotContainsString('Privates Titelbild', $html);
}
public function test_a_released_cover_appears_on_the_tile_as_a_decorative_lazy_image(): void
{
$released = $this->image('Freigegebenes Titelbild', released: true);
$this->cover($this->konflikte(), $released);
$this->assertSame(route('website.media', $released), $this->card()['image']['url']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('src="'.route('website.media', $released).'"', $html);
$this->assertMatchesRegularExpression('#<img src="[^"]+website-medien/'.$released->id.'" alt="" loading="lazy"#', $html, 'Das Bild ist schmückend, der Titel ist der Link.');
}
public function test_an_unreleased_first_cover_is_skipped_for_the_next_released_one(): void
{
$this->cover($this->konflikte(), $this->image('Nicht freigegeben', released: false), 'titelbild', 1);
$gallery = $this->image('Galeriebild freigegeben', released: true);
$this->cover($this->konflikte(), $gallery, 'galerie', 2);
$this->assertSame(route('website.media', $gallery), $this->card()['image']['url']);
}
public function test_a_film_is_not_used_as_a_cover(): void
{
$film = app(ContentService::class)->createElement('film', 'film', 'Ein Film');
$path = 'website/'.$film->id.'/datei.mp4';
Storage::disk('media_public')->put($path, 'film');
$film->forceFill(['website_released_at' => now(), 'website_public_path' => $path])->save();
$this->cover($this->konflikte(), $film->fresh());
$this->assertNull($this->card()['image']);
}
// ---- Gruppen, Materialart, Symbol ---------------------------------------------------------------------------------
public function test_only_published_pillars_appear_and_the_search_finds_a_tile_by_pillar_or_kind(): void
{
$service = app(PillarService::class);
$open = $service->create('Wertschätzung im Alltag');
$service->present($open, 'Wertschätzung im Alltag', 'wertschaetzung-im-alltag', 'Kurz', true, 10);
$hidden = $service->create('Interne Säule');
$service->present($hidden, 'Interne Säule', 'interne-saeule', null, false, 20);
$service->assign($this->konflikte(), [$open->id, $hidden->id]);
$card = $this->card();
$this->assertSame(['Wertschätzung im Alltag'], $card['pillars']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('Wertschätzung im Alltag', $html);
$this->assertStringNotContainsString('Interne Säule', $html);
$this->get(route('shop', ['suche' => 'Wertschätzung']))->assertOk()->assertSee('Konflikte im Training')->assertDontSee('Grenzen setzen im Verein');
$this->get(route('shop', ['suche' => 'Interne']))->assertOk()->assertSee('Keine Treffer');
}
public function test_the_tile_shows_the_kind_and_its_symbol_when_there_is_no_image(): void
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$article = $this->konflikte();
$article->editorial_content_kind_id = $kind->id;
$article->save();
$key = array_key_first(SymbolCatalog::options());
$kind->forceFill(['symbol' => $key])->save();
$card = $this->card();
$this->assertSame($kind->label, $card['kind_label']);
$this->assertSame($key, $card['symbol']);
$this->get(route('shop'))->assertOk()->assertSee($kind->label)->assertSee('shop-tile-symbol', false);
}
public function test_an_unknown_symbol_key_is_ignored(): void
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$article = $this->konflikte();
$article->editorial_content_kind_id = $kind->id;
$article->save();
$kind->forceFill(['symbol' => '../etc/passwd'])->save();
$this->assertNull($this->card()['symbol']);
$this->get(route('shop'))->assertOk()->assertDontSee('shop-tile-symbol', false)->assertDontSee('passwd');
}
public function test_a_symbol_is_stored_with_the_kind_in_the_master_data_and_an_invalid_one_is_dropped(): void
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$key = array_key_first(SymbolCatalog::options());
Livewire::actingAs($this->editor(), 'staff')
->test(RedaktionelleStammdaten::class)
->call('zeigeGruppe', 'materialart')
->callAction(TestAction::make('bearbeiten')->table($kind), ['label' => $kind->label, 'symbol' => $key, 'contexts' => $kind->contexts])
->assertHasNoActionErrors();
$this->assertSame($key, $kind->fresh()->symbol);
Livewire::actingAs($this->editor(), 'staff')
->test(RedaktionelleStammdaten::class)
->call('zeigeGruppe', 'materialart')
->callAction(TestAction::make('bearbeiten')->table($kind), ['label' => $kind->label, 'symbol' => 'gibt-es-nicht', 'contexts' => $kind->contexts]);
$this->assertNotSame('gibt-es-nicht', $kind->fresh()->symbol);
}
// ---- Marker -------------------------------------------------------------------------------------------------------
private function labels(): array
{
return array_column($this->card()['markers'], 'label');
}
public function test_new_is_automatic_for_a_limited_time_after_the_first_offer(): void
{
$this->assertSame(['Neu'], $this->labels());
$this->travel(29)->days();
$this->assertSame(['Neu'], $this->labels());
$this->travel(2)->days();
$this->assertSame([], $this->labels(), 'Nach 30 Tagen verschwindet „Neu“ von selbst.');
}
public function test_updated_appears_for_a_new_stand_and_never_together_with_new(): void
{
$article = $this->konflikte();
$this->travel(40)->days();
$this->assertSame([], $this->labels());
ArticleRelease::query()->whereKey($article->current_release_id)->update(['number' => 2, 'created_at' => now()->subDay()]);
$this->assertSame(['Aktualisiert'], $this->labels());
$this->travel(31)->days();
$this->assertSame([], $this->labels());
}
public function test_the_editorial_setting_overrides_the_automatic_markers_and_popular_is_manual(): void
{
$article = $this->konflikte();
$markers = app(ShopMarkers::class);
$this->travel(60)->days();
$this->assertSame([], $this->labels());
$markers->save($article, ['neu' => 'an', 'aktualisiert' => 'an', 'beliebt' => 'an']);
$this->assertSame(['Neu', 'Aktualisiert', 'Beliebt'], $this->labels());
$markers->save($article->fresh(), ['neu' => 'aus', 'aktualisiert' => 'aus', 'beliebt' => 'aus']);
$this->assertSame([], $this->labels());
$markers->save($article->fresh(), ['neu' => 'auto', 'aktualisiert' => 'auto', 'beliebt' => 'an']);
$this->assertSame(['Beliebt'], $this->labels());
}
public function test_an_unknown_marker_setting_is_refused_and_defaults_apply(): void
{
$article = $this->konflikte();
try {
app(ShopMarkers::class)->save($article, ['neu' => 'vielleicht', 'aktualisiert' => 'auto', 'beliebt' => 'aus']);
$this->fail('Eine unbekannte Einstellung wird abgelehnt.');
} catch (DomainRuleException $exception) {
$this->assertStringContainsString('Neu', $exception->getMessage());
}
$article->forceFill(['shop_markers' => ['neu' => 'kaputt', 'beliebt' => ['x']]])->save();
$this->assertSame(['neu' => 'auto', 'aktualisiert' => 'auto', 'beliebt' => 'aus'], app(ShopMarkers::class)->settings($article->fresh()));
}
public function test_markers_carry_their_word_on_the_tile_and_for_screen_readers(): void
{
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('shop-marker shop-marker-neu', $html);
$this->assertStringContainsString('>Neu</span>', $html);
$this->assertMatchesRegularExpression('#<p class="sr-only">Neu</p>#', $html);
}
public function test_the_article_page_sets_markers_without_touching_the_editorial(): void
{
$article = $this->konflikte();
$article->forceFill(['teaser' => 'Eigener Kurztext bleibt'])->save();
Livewire::actingAs($this->keeper(), 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->assertSee('Marker auf der Kachel')
->callAction('markers', ['neu' => 'aus', 'aktualisiert' => 'auto', 'beliebt' => 'an'])
->assertHasNoActionErrors();
$article->refresh();
$this->assertSame(['neu' => 'aus', 'aktualisiert' => 'auto', 'beliebt' => 'an'], $article->shop_markers);
$this->assertSame('Eigener Kurztext bleibt', $article->teaser);
$this->assertSame(['Beliebt'], $this->labels());
}
public function test_only_the_catalog_keeper_can_reach_the_marker_action(): void
{
$article = $this->konflikte();
foreach ([User::factory()->create(), $this->editor()] as $user) {
Livewire::actingAs($user, 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->assertForbidden();
}
$this->assertNull($article->fresh()->shop_markers);
}
// ---- Eine Datenquelle ---------------------------------------------------------------------------------------------
public function test_the_shop_page_and_the_catalog_list_the_same_products_in_the_same_order(): void
{
$titles = array_column(app(ShopCatalog::class)->cards(), 'title');
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertNotSame([], $titles);
$last = -1;
foreach ($titles as $title) {
$position = mb_strpos($html, e($title));
$this->assertNotFalse($position, $title.' fehlt auf der Shopseite.');
$this->assertGreaterThan($last, $position);
$last = $position;
}
$this->assertStringContainsString(count($titles).' Produkte', $html);
}
public function test_an_archived_article_and_an_article_without_an_option_are_not_listed(): void
{
$service = app(ArticleService::class);
$draft = $service->create('ohne-option');
$titles = array_column(app(ShopCatalog::class)->cards(), 'key');
$this->assertNotContains('a:'.$draft->id, $titles);
$article = $this->konflikte();
$article->forceFill(['archived_at' => now()])->save();
$this->assertNotContains('a:'.$article->id, array_column(app(ShopCatalog::class)->cards(), 'key'));
}
}