Mache den Lizenzartikel zur Produktseite und leite die Seite aus dem Angebot ab
CI Feature / test (push) Failing after 3m16s
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:
1 parent
1950dc377b
commit
08f7d0c63d
22 files changed
+544
-275
No files matched your search
@@ -22,7 +22,10 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
/** Komposition, deren öffentliche Seite die Produktseite dieser Lizenzoption ist. */
|
||||
/**
|
||||
* Altbestand: Programmseite, der eine Option mit mehreren Positionen früher von Hand zugeordnet wurde. Neue Optionen
|
||||
* haben genau eine Position; ihre Produktseite ergibt sich aus ihr (Artikel- oder Paketseite) und wird nicht zugeordnet.
|
||||
*/
|
||||
public function composition(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Composition::class);
|
||||
|
||||
@@ -106,9 +106,7 @@ public function activate(Offer $offer, array $lines, array $attributes = []): Of
|
||||
'trainer_count' => null,
|
||||
], $attributes);
|
||||
|
||||
if ($offer->standalone_bundle && (count($lines) !== 1 || ! $lines[0]['target'] instanceof BundleVersion)) {
|
||||
throw new DomainRuleException('Ein Angebot mit eigener Paketseite besteht aus genau einer Paketfassung (Katalog → Pakete). Für einen Lizenzartikel ordnest du das Angebot der Seite eines Programms zu: Das Programm muss als Programm angelegt und zur Anzeige freigegeben sein, ein Modul genügt nicht.');
|
||||
}
|
||||
$this->assertBuyable($lines, $attributes);
|
||||
|
||||
$this->assertAttributes($attributes);
|
||||
[$attributes['licence_scope'], $attributes['trainer_count']] = LicenceScope::normalise($attributes['licence_scope'], $attributes['trainer_count']);
|
||||
@@ -183,21 +181,11 @@ public function end(Offer $offer): OfferVersion
|
||||
}
|
||||
|
||||
/**
|
||||
* Produktzuordnung der Option: Die Komposition bestimmt die öffentliche Produktseite und die Alternativgruppe,
|
||||
* die Bezeichnung benennt die Option auf dieser Seite. Beides sind keine bindenden Konditionen.
|
||||
* Die Bezeichnung der Option auf der Produktseite. Die Seite selbst wird nicht zugeordnet: Sie ist die Seite des
|
||||
* Artikels bzw. des Pakets, das die einzige Position der Fassung verkauft. Die Bezeichnung ist keine bindende Kondition.
|
||||
*/
|
||||
public function assignProduct(Offer $offer, ?int $compositionId, ?string $optionLabel, bool $ownBundlePage = false): Offer
|
||||
public function setOptionLabel(Offer $offer, ?string $optionLabel): Offer
|
||||
{
|
||||
if ($compositionId !== null) {
|
||||
Composition::query()->findOrFail($compositionId);
|
||||
}
|
||||
|
||||
if ($ownBundlePage && $compositionId !== null) {
|
||||
throw new DomainRuleException('Ein Paket hat entweder eine eigene Paketseite oder die Seite eines Programms, nicht beides.');
|
||||
}
|
||||
|
||||
$offer->composition_id = $compositionId;
|
||||
$offer->standalone_bundle = $ownBundlePage;
|
||||
$offer->option_label = filled($optionLabel) ? trim((string) $optionLabel) : null;
|
||||
$offer->save();
|
||||
|
||||
@@ -212,6 +200,29 @@ public function scopeArticleIds(OfferVersion $version): array
|
||||
return $version->resolvedScopes()->orderBy('id')->pluck('license_article_id')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Kauf muss im Shop auffindbar und kaufbar sein, sonst lässt er sich nicht aktivieren: Er verkauft genau einen
|
||||
* Artikel oder ein Paket (das ist die Produktseite) und hat einen Preis. Mehrere Artikel gemeinsam verkauft ein
|
||||
* Paket. Vergaben bei Registrierung oder auf Abruf stehen nie im Shop und sind davon ausgenommen.
|
||||
*
|
||||
* @param list<array{target: LicenseArticle|BundleVersion, rights: RightsProfileVersion}> $lines
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
private function assertBuyable(array $lines, array $attributes): void
|
||||
{
|
||||
if (($attributes['grant_kind'] ?? null) !== 'kauf') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($lines) !== 1) {
|
||||
throw new DomainRuleException('Ein Kauf verkauft genau einen Artikel oder ein Paket. Mehrere Artikel gemeinsam verkaufst du als Paket (Katalog → Pakete).');
|
||||
}
|
||||
|
||||
if (! is_int($attributes['price_cents'] ?? null) || $attributes['price_cents'] <= 0) {
|
||||
throw new DomainRuleException('Ein Kauf braucht einen Preis über 0,00 €.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user