Zeige auf der Shopkachel Titelbild, Saeulen, Materialart mit Symbol und Marker
- ShopCatalog als gemeinsame Datenquelle der Kacheln, shop/kachel als Partial - Titelbild nur mit Website-Freigabe (PresentationMedia::coverPresentation), schmueckend mit leerem alt - Symbol je Materialart (Stammdaten), Marker Neu, Aktualisiert, Beliebt mit Einstellung am Artikel - Migration 2026_12_01_100000, rein ergaenzend - ADR-54, Plan, DEPLOYMENT.md Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
db3a6ba779
commit
0ac70884cc
18 files changed
+991
-88
No files matched your search
@@ -42,6 +42,7 @@ class EditorialContentKind extends Model
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'label',
|
||||
'symbol',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
'contexts',
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user