Mache den Lizenzartikel zur Produktseite und leite die Seite aus dem Angebot ab
CI Feature / test (push) Failing after 3m16s

Die Produktseite ist die Seite des Artikels (/shop/{id}), den die Option als einzige
Position verkauft, oder die Paketseite. Sie wird nicht mehr einem Programm zugeordnet.
Ein Kauf braucht genau eine Position und einen Preis, sonst lässt er sich nicht aktivieren.
Module und Programme werden dadurch nicht öffentlich (Karten und /programme unverändert).

Tests: Die Tests, die eine Programmseite als Produktseite voraussetzten, prüfen jetzt die
Artikelseite; die Zuordnung „eigene Paketseite oder Programmseite“ entfällt (ADR-52).
Ein Altbestandstest sichert die Programmseite für Angebote mit mehreren Positionen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-25 17:39:20 +01:00
1 parent 1950dc377b
commit 08f7d0c63d
22 files changed
+544 -275

No files matched your search

+11 -3
View File
@@ -45,10 +45,18 @@ public function blocks(): bool
public function title(): string
{
if ($this->offer->standalone_bundle && $this->version !== null) {
$bundle = app(ProductOptions::class)->bundleOf($this->version);
$products = app(ProductOptions::class);
if ($bundle !== null) {
if ($this->version !== null) {
$article = $products->articleOf($this->version);
if ($article !== null) {
return $products->articleTitle($article);
}
$bundle = $products->bundleOf($this->version);
if ($bundle !== null && $this->version->lines->count() === 1) {
return (string) $bundle->name;
}
}
+173 -82
View File
@@ -4,12 +4,14 @@
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionStructureReader;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\LicenceScope;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\StructureNode;
use App\Filament\Support\CatalogLabels;
/**
@@ -22,42 +24,82 @@ class ProductOptions
public function __construct(private readonly OfferService $offers) {}
/**
* Optionen der Produktseite eines Lizenzartikels: Angebote, deren einzige Position dieser Artikel ist.
*
* @return list<array<string, mixed>>
*/
public function forComposition(Composition $composition): array
public function forArticle(LicenseArticle $article): array
{
$options = [];
foreach (Offer::query()->where('composition_id', $composition->id)->orderBy('id')->get() as $offer) {
$version = $this->offers->purchasableVersion($offer);
if ($version !== null) {
$options[] = $this->describe($offer, $version);
}
}
return $options;
return $this->optionsFor('a:'.$article->id);
}
/**
* Kaufbare Optionen der eigenen Produktseite eines Pakets: Angebote mit eigener Paketseite, deren aktive Fassung
* dieses Paket verkauft.
* Kaufbare Optionen der Produktseite eines Pakets: Angebote, deren einzige Position eine Fassung dieses Pakets ist.
*
* @return list<array<string, mixed>>
*/
public function forBundle(Bundle $bundle): array
{
$options = [];
return $this->optionsFor('b:'.$bundle->id);
}
foreach (Offer::query()->where('standalone_bundle', true)->orderBy('id')->get() as $offer) {
$version = $this->offers->purchasableVersion($offer);
/**
* Altbestand: Angebote mit mehreren Positionen, die einer Programmseite zugeordnet wurden. Neue Angebote
* haben immer genau eine Position und damit eine Artikel- oder Paketseite.
*
* @return list<array<string, mixed>>
*/
public function forComposition(Composition $composition): array
{
return $this->optionsFor('c:'.$composition->id);
}
if ($version !== null && $this->bundleOf($version)?->id === $bundle->id) {
$options[] = $this->describe($offer, $version);
}
}
/**
* Der Artikel, den die Fassung als einzige Position verkauft, sonst null.
*/
public function articleOf(OfferVersion $version): ?LicenseArticle
{
$version->loadMissing('lines.article');
return $options;
return $version->lines->count() === 1 ? $version->lines->first()->article : null;
}
/**
* Aufbau des Inhalts, den der aktuelle Stand des Artikels liefert (Rolle und Titel der Bestandteile). Ein Artikel
* mit einem einzelnen Medium als Wurzel hat keine Struktur. Dateien und Lehrtexte kommen hier nie vor.
*
* @return list<StructureNode>
*/
public function articleStructure(LicenseArticle $article): array
{
$version = $article->currentRelease?->rootCompositionVersion;
return $version === null ? [] : app(CompositionStructureReader::class)->tree($version);
}
/** Lernziel des Inhalts im aktuellen Stand des Artikels, wie es schon die öffentliche Programmseite zeigt. */
public function articleGoal(LicenseArticle $article): ?string
{
$goal = $article->currentRelease?->rootCompositionVersion?->learning_goal;
return filled($goal) ? (string) $goal : null;
}
/**
* Artikel mit kaufbarer Option, deren Inhalt diese Komposition ist: Die Programmseite verweist auf sie.
*
* @return list<LicenseArticle>
*/
public function articlesOf(Composition $composition): array
{
return LicenseArticle::query()
->whereNull('archived_at')
->whereHas('currentRelease.rootCompositionVersion', fn ($query) => $query->where('composition_id', $composition->id))
->orderBy('code')
->get()
->filter(fn (LicenseArticle $article): bool => $this->forArticle($article) !== [])
->values()
->all();
}
/**
@@ -70,60 +112,135 @@ public function bundleOf(OfferVersion $version): ?Bundle
return $version->lines->first(fn ($line): bool => $line->bundleVersion !== null)?->bundleVersion?->bundle;
}
/** Gruppenschlüssel der Alternativen: Produktseite eines Programms oder eigene Paketseite. */
/**
* Schlüssel der Produktseite, auf der die Option angeboten wird: Artikelseite (`a:`), Paketseite (`b:`) oder, nur
* im Altbestand mit mehreren Positionen, die Programmseite (`c:`). Die Seite ergibt sich aus der Angebotsfassung
* und wird nirgends von Hand zugeordnet.
*/
public function groupKey(Offer $offer): ?string
{
if ($offer->composition_id !== null) {
return 'c:'.$offer->composition_id;
$version = $this->offers->purchasableVersion($offer) ?? $offer->versions()->orderByDesc('number')->first();
return $this->keyFor($offer, $version);
}
private function keyFor(Offer $offer, ?OfferVersion $version): ?string
{
if ($version !== null && $version->lines()->count() === 1) {
$article = $this->articleOf($version);
if ($article !== null) {
return 'a:'.$article->id;
}
$bundle = $this->bundleOf($version);
if ($bundle !== null) {
return 'b:'.$bundle->id;
}
}
if ($offer->standalone_bundle) {
$version = $this->offers->purchasableVersion($offer) ?? $offer->versions()->orderByDesc('number')->first();
$bundle = $version === null ? null : $this->bundleOf($version);
return $bundle === null ? null : 'b:'.$bundle->id;
}
return null;
return $offer->composition_id !== null ? 'c:'.$offer->composition_id : null;
}
/** Adresse der Produktseite, auf der die Option angeboten wird, sonst null. */
public function pageUrl(Offer $offer): ?string
{
if ($offer->composition_id !== null) {
return route('public.program', $offer->composition_id);
}
$key = $this->groupKey($offer);
return $key !== null && str_starts_with($key, 'b:') ? route('public.package', (int) substr($key, 2)) : null;
if ($key === null) {
return null;
}
$id = (int) substr($key, 2);
return match ($key[0]) {
'a' => route('shop.article', $id),
'b' => route('public.package', $id),
default => route('public.program', $id),
};
}
/**
* Pakete mit eigener Produktseite und kaufbarer Option: Paketkennung => günstigster Preis und Zahl der Optionen.
* Kaufbare Optionen je Produktseite: Seitenschlüssel => Angebot und Fassung in der Reihenfolge der Angebote.
*
* @return array<string, list<array{offer: Offer, version: OfferVersion}>>
*/
private function purchasable(): array
{
$pages = [];
foreach (Offer::query()->orderBy('id')->get() as $offer) {
$version = $this->offers->purchasableVersion($offer);
$key = $version === null ? null : $this->keyFor($offer, $version);
if ($key !== null) {
$pages[$key][] = ['offer' => $offer, 'version' => $version];
}
}
return $pages;
}
/**
* @return list<array<string, mixed>>
*/
private function optionsFor(string $key): array
{
return array_map(fn (array $row): array => $this->describe($row['offer'], $row['version']), $this->purchasable()[$key] ?? []);
}
/**
* Günstigster Preis und Zahl der Optionen je Seite einer Art ('a', 'b' oder 'c'): Kennung => Zusammenfassung.
*
* @return array<int, array{from_cents: int, count: int}>
*/
private function summariesOf(string $kind): array
{
$summary = [];
foreach ($this->purchasable() as $key => $rows) {
if ($key[0] !== $kind) {
continue;
}
$summary[(int) substr($key, 2)] = [
'from_cents' => min(array_map(fn (array $row): int => (int) $row['version']->price_cents, $rows)),
'count' => count($rows),
];
}
return $summary;
}
/**
* Artikel mit kaufbarer Option: Artikelkennung => günstigster Preis und Zahl der Optionen.
*
* @return array<int, array{from_cents: int, count: int}>
*/
public function articleSummaries(): array
{
return $this->summariesOf('a');
}
/**
* Pakete mit kaufbarer Option: Paketkennung => günstigster Preis und Zahl der Optionen.
*
* @return array<int, array{from_cents: int, count: int}>
*/
public function bundleSummaries(): array
{
$summary = [];
return $this->summariesOf('b');
}
foreach (Offer::query()->where('standalone_bundle', true)->orderBy('id')->get() as $offer) {
$version = $this->offers->purchasableVersion($offer);
$bundle = $version === null ? null : $this->bundleOf($version);
if ($bundle === null) {
continue;
}
$current = $summary[$bundle->id] ?? ['from_cents' => PHP_INT_MAX, 'count' => 0];
$summary[$bundle->id] = [
'from_cents' => min($current['from_cents'], (int) $version->price_cents),
'count' => $current['count'] + 1,
];
}
return $summary;
/**
* Altbestand: Programmseiten mit kaufbaren Optionen (Angebote mit mehreren Positionen).
*
* @return array<int, array{from_cents: int, count: int}>
*/
public function summaries(): array
{
return $this->summariesOf('c');
}
/**
@@ -158,32 +275,6 @@ public function bundleContents(array $options): array
return array_values($contents);
}
/**
* Zeilen für Shop-Suche und Kacheln: je Komposition die günstigste Option.
*
* @return array<int, array{from_cents: int, count: int}>
*/
public function summaries(): array
{
$summary = [];
foreach (Offer::query()->whereNotNull('composition_id')->orderBy('id')->get() as $offer) {
$version = $this->offers->purchasableVersion($offer);
if ($version === null) {
continue;
}
$current = $summary[$offer->composition_id] ?? ['from_cents' => PHP_INT_MAX, 'count' => 0];
$summary[$offer->composition_id] = [
'from_cents' => min($current['from_cents'], (int) $version->price_cents),
'count' => $current['count'] + 1,
];
}
return $summary;
}
/**
* @return array<string, mixed>
*/