Gib Paketen eine eigene Produktseite und ergänze Tests zu Nutzerkreis und Verkaufsstart

Ein eigenständig vermarktetes Paket (offers.standalone_bundle) erhält /pakete/{id}
mit seinem tatsächlichen Umfang, Shop-Kachel und Suche. Die Angebotsmaske kennt
Nutzerkreis und Anzahl Trainer. Zwei Bestandstests (CartTest, Vergleich der
Rechte und Erwerbsarten) legen die Vergleichsangebote jetzt als Einzellizenz an,
weil der Nutzerkreis zum identischen Umfang gehört; ihre Aussagen bleiben.
Eine Rechnungs- oder Stripe-Bestellung lässt sich nicht mit der Testzahlung bestätigen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-22 19:47:15 +01:00
1 parent 0154182f3b
commit 1ce2e1e51f
21 files changed
+997 -31

No files matched your search

+8
View File
@@ -12,8 +12,16 @@ class Offer extends Model
'name',
'composition_id',
'option_label',
'standalone_bundle',
];
protected function casts(): array
{
return [
'standalone_bundle' => 'boolean',
];
}
/** Komposition, deren öffentliche Seite die Produktseite dieser Lizenzoption ist. */
public function composition(): BelongsTo
{
+10 -1
View File
@@ -106,6 +106,10 @@ 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. Wähle eine Paketfassung oder ordne das Angebot der Seite eines Programms zu.');
}
$this->assertAttributes($attributes);
[$attributes['licence_scope'], $attributes['trainer_count']] = LicenceScope::normalise($attributes['licence_scope'], $attributes['trainer_count']);
$scope = $this->scopeFor($lines);
@@ -182,13 +186,18 @@ 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.
*/
public function assignProduct(Offer $offer, ?int $compositionId, ?string $optionLabel): Offer
public function assignProduct(Offer $offer, ?int $compositionId, ?string $optionLabel, bool $ownBundlePage = false): 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();
+6 -3
View File
@@ -64,7 +64,10 @@ public function has(Offer $offer): bool
*/
public function alternativeTo(Offer $offer): ?Offer
{
if ($offer->composition_id === null) {
$products = app(ProductOptions::class);
$group = $products->groupKey($offer);
if ($group === null) {
return null;
}
@@ -72,8 +75,8 @@ public function alternativeTo(Offer $offer): ?Offer
return $ids === [] ? null : Offer::query()
->whereIn('id', $ids)
->where('composition_id', $offer->composition_id)
->first();
->get()
->first(fn (Offer $other): bool => $products->groupKey($other) === $group);
}
public function add(Offer $offer): string
+8
View File
@@ -45,6 +45,14 @@ public function blocks(): bool
public function title(): string
{
if ($this->offer->standalone_bundle && $this->version !== null) {
$bundle = app(ProductOptions::class)->bundleOf($this->version);
if ($bundle !== null) {
return (string) $bundle->name;
}
}
$composition = $this->offer->composition;
return $composition !== null
+10
View File
@@ -175,6 +175,7 @@ private function createOrder(User $user, Party $holder, array $pairs, ?CartRevie
public function confirmTestPayment(Order $order, string $reference): Order
{
$this->assertTestDriver();
$this->assertTestOrder($order);
return $this->settle($order, 'test', $reference);
}
@@ -258,6 +259,7 @@ private function settle(Order $order, string $provider, string $reference): Orde
public function failTestPayment(Order $order, string $reference): Order
{
$this->assertTestDriver();
$this->assertTestOrder($order);
return DB::transaction(function () use ($order, $reference): Order {
$order = Order::query()->lockForUpdate()->findOrFail($order->id);
@@ -359,6 +361,14 @@ private function assertActive(User $user): void
}
}
/** Eine Bestellung auf Rechnung oder über Stripe wird nie mit der Testzahlung bestätigt. */
private function assertTestOrder(Order $order): void
{
if (in_array(Order::query()->whereKey($order->id)->value('payment_method'), ['rechnung', 'stripe'], true)) {
throw new DomainRuleException('Diese Bestellung wird nicht mit der Testzahlung bezahlt.');
}
}
private function assertTestDriver(): void
{
if (app()->isProduction() || config('services.payment.driver') !== 'test') {
+120
View File
@@ -2,6 +2,7 @@
namespace App\Domain\Commerce;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\LicenceScope;
@@ -38,6 +39,125 @@ public function forComposition(Composition $composition): array
return $options;
}
/**
* Kaufbare Optionen der eigenen Produktseite eines Pakets: Angebote mit eigener Paketseite, deren aktive Fassung
* dieses Paket verkauft.
*
* @return list<array<string, mixed>>
*/
public function forBundle(Bundle $bundle): array
{
$options = [];
foreach (Offer::query()->where('standalone_bundle', true)->orderBy('id')->get() as $offer) {
$version = $this->offers->purchasableVersion($offer);
if ($version !== null && $this->bundleOf($version)?->id === $bundle->id) {
$options[] = $this->describe($offer, $version);
}
}
return $options;
}
/**
* Das Paket, das die Fassung unmittelbar verkauft (erste Paketposition), sonst null.
*/
public function bundleOf(OfferVersion $version): ?Bundle
{
$version->loadMissing('lines.bundleVersion.bundle');
return $version->lines->first(fn ($line): bool => $line->bundleVersion !== null)?->bundleVersion?->bundle;
}
/** Gruppenschlüssel der Alternativen: Produktseite eines Programms oder eigene Paketseite. */
public function groupKey(Offer $offer): ?string
{
if ($offer->composition_id !== null) {
return 'c:'.$offer->composition_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;
}
/** 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;
}
/**
* Pakete mit eigener Produktseite und kaufbarer Option: Paketkennung => günstigster Preis und Zahl der Optionen.
*
* @return array<int, array{from_cents: int, count: int}>
*/
public function bundleSummaries(): array
{
$summary = [];
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;
}
/**
* Der tatsächliche Umfang einer Paketseite: die Artikel aller Optionen ohne Doppelte, in der Reihenfolge der
* Optionen, mit Name und Kurzbeschreibung aus der Redaktion.
*
* @param list<array<string, mixed>> $options
* @return list<array{title: string, teaser: string}>
*/
public function bundleContents(array $options): array
{
$contents = [];
foreach ($options as $option) {
$option['version']->loadMissing('resolvedScopes.article');
foreach ($option['version']->resolvedScopes as $item) {
$article = $item->article;
if ($article === null || isset($contents[$article->id])) {
continue;
}
$profile = app(EditorialProfileReader::class)->read($article, 'detail');
$contents[$article->id] = [
'title' => $this->articleTitle($article),
'teaser' => trim((string) ($profile->value('teaser') ?? '')),
];
}
}
return array_values($contents);
}
/**
* Zeilen für Shop-Suche und Kacheln: je Komposition die günstigste Option.
*
@@ -7,6 +7,7 @@
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\LicenceScope;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
@@ -45,6 +46,9 @@ class ViewOffer extends ViewRecord
protected static string $resource = OfferResource::class;
/** Wert der Auswahl „Produktseite“ für ein Paket mit eigener Seite. */
private const OWN_BUNDLE_PAGE = '__paket';
public function getTitle(): string|Htmlable
{
return (string) $this->getRecord()->name;
@@ -120,6 +124,16 @@ public function activateAction(): Action
'organisation' => 'Organisationen und Vereine',
])->required()
->helperText('Wähle die Eignung passend zu den Rechten: Organisationslizenzen brauchen institutionelle Rechte. Das System erzwingt diese Kopplung nicht.'),
Select::make('licence_scope')->label('Nutzerkreis')
->options(LicenceScope::options())
->required()
->live()
->helperText('Wie viele Trainer die Inhalte einsetzen dürfen. Das ist unabhängig vom Lizenzinhaber (Person oder Verein), vom Nutzungszweck der Rechte und vom Preis; es wird aus keinem davon abgeleitet. Der Download bleibt zum Start beim bestellenden Konto. Der Wert wird mit der Bestellung festgehalten.'),
TextInput::make('trainer_count')->label('Anzahl Trainer')
->numeric()->minValue(2)->maxValue(LicenceScope::MAX_TRAINERS)->integer()
->required(fn (Get $get): bool => $get('licence_scope') === LicenceScope::MULTI)
->visible(fn (Get $get): bool => $get('licence_scope') === LicenceScope::MULTI)
->helperText('Höchstzahl der Trainer, die die Inhalte einsetzen dürfen, mindestens 2. Eine Einzellizenz gilt immer für genau einen Trainer.'),
Select::make('grant_kind')->label('Vergabe')->options([
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
@@ -201,13 +215,16 @@ public function activateAction(): Action
$version = DB::transaction(function () use ($service, $offer, $data, $lines, $kept, $price) {
$service->assignProduct(
$offer,
filled($data['composition_id'] ?? null) ? (int) $data['composition_id'] : null,
filled($data['composition_id'] ?? null) && $data['composition_id'] !== self::OWN_BUNDLE_PAGE ? (int) $data['composition_id'] : null,
$data['option_label'] ?? null,
($data['composition_id'] ?? null) === self::OWN_BUNDLE_PAGE,
);
return $service->activate($offer, $lines, [
...$kept,
'holder_kind' => $data['holder_kind'],
'licence_scope' => $data['licence_scope'] ?? null,
'trainer_count' => $data['trainer_count'] ?? null,
'grant_kind' => $data['grant_kind'],
'price_cents' => $price,
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
@@ -267,7 +284,7 @@ private function productPages(): array
{
$catalog = app(PublicCatalogReader::class);
return Composition::query()
return [self::OWN_BUNDLE_PAGE => 'Eigene Paketseite · zeigt den Umfang des Pakets (nur für ein Angebot aus genau einer Paketfassung)'] + Composition::query()
->with('editorialContentKind')
->whereNull('archived_at')
->orderBy('designation')
@@ -291,15 +308,17 @@ private function formFromActive(): array
$active = $this->activeVersion();
/** @var Offer $offer */
$offer = $this->getRecord();
$option = ['option_label' => $offer->option_label, 'composition_id' => $offer->composition_id];
$option = ['option_label' => $offer->option_label, 'composition_id' => $offer->standalone_bundle ? self::OWN_BUNDLE_PAGE : $offer->composition_id];
if ($active === null) {
return [...$option, 'holder_kind' => 'person', 'grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
return [...$option, 'holder_kind' => 'person', 'licence_scope' => LicenceScope::SINGLE, 'grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
}
return [
...$option,
'holder_kind' => $active->holder_kind,
'licence_scope' => $active->licence_scope,
'trainer_count' => $active->trainer_count,
'grant_kind' => $active->grant_kind,
'price_euro' => $active->price_cents === null ? null : number_format($active->price_cents / 100, 2, ',', ''),
'lines' => $active->lines->sortBy('position')->map(fn ($line): array => [
@@ -400,6 +419,7 @@ private function optionAbschnitt(Offer $offer, OfferVersion $active): array
->unique()
->implode('; ');
$seite = $offer->composition;
$eigeneSeite = $offer->standalone_bundle;
$kaufbar = app(OfferService::class)->purchasableVersion($offer) !== null;
return [
@@ -409,10 +429,11 @@ private function optionAbschnitt(Offer $offer, OfferVersion $active): array
'zeilen' => [
['text' => 'Preis: '.$option['price'], 'neben' => $active->grant_kind === 'kauf' ? 'Kauf mit Testzahlung' : CatalogLabels::vergabe($active)],
['text' => 'Geeignet für: '.$option['for'], 'neben' => $option['term']],
['text' => 'Nutzerkreis: '.$option['licence'], 'neben' => $option['licence_scope'] === null ? 'Mit „Geänderte Fassung aktivieren“ festlegen.' : 'Lizenzinhaber, Nutzerkreis und Downloadkonto sind getrennte Angaben.'],
['text' => 'Rechte: '.($rechte !== '' ? $rechte : 'keine'), 'neben' => null],
['text' => 'Zugrunde liegender Inhalt: '.($inhalt !== '' ? $inhalt : '–'), 'neben' => null],
['text' => 'Status: '.($kaufbar ? 'Öffentlich kaufbar' : 'Nicht als Kauf angeboten'), 'neben' => $kaufbar ? 'Aktive Fassung '.$active->number : null],
['text' => 'Produktseite: '.($seite !== null ? ($seite->display_title ?: $seite->designation) : 'noch nicht zugeordnet'), 'neben' => $seite !== null ? 'Option „'.$offer->optionName().'“' : 'Mit „Geänderte Fassung aktivieren“ zuordnen.'],
['text' => 'Produktseite: '.($eigeneSeite ? 'eigene Paketseite mit dem Umfang des Pakets' : ($seite !== null ? ($seite->display_title ?: $seite->designation) : 'noch nicht zugeordnet')), 'neben' => $eigeneSeite || $seite !== null ? 'Option „'.$offer->optionName().'“' : 'Mit „Geänderte Fassung aktivieren“ zuordnen.'],
],
];
}
+25 -9
View File
@@ -227,7 +227,8 @@ public function forOffer(Offer $offer): array
$missing = $this->unusableArticles($articleIds);
$buyable = $hasActive && $this->offers->purchasableVersion($offer) !== null;
$page = $offer->composition;
$shown = $page !== null && $this->catalog->shownVersion($page) !== null;
$own = (bool) $offer->standalone_bundle;
$shown = $own || ($page !== null && $this->catalog->shownVersion($page) !== null);
$pageName = $page !== null ? (string) ($page->display_title ?: $page->designation) : '';
$activate = ['label' => $hasActive ? 'Geänderte Fassung aktivieren' : 'Angebot konfigurieren', 'wire' => "mountAction('activate')"];
@@ -258,21 +259,36 @@ public function forOffer(Offer $offer): array
'stand' => $buyable ? 'erledigt' : 'offen',
'aktion' => $buyable ? null : ($hasActive ? $activate : null),
],
[
'titel' => 'Nutzerkreis festlegen',
'text' => ! $hasActive
? 'Wird mit der Fassung festgelegt: Einzellizenz (ein Trainer) oder Mehrfachlizenz (Zahl der Trainer).'
: ($active->licence_scope !== null
? \App\Domain\Catalog\LicenceScope::label($active->licence_scope, $active->trainer_count).'. Der Käufer sieht das auf der Produktseite und in der Bestellung.'
: 'Diese Fassung hat keinen festgelegten Nutzerkreis. Käufer sehen „Nutzerkreis nicht festgelegt“. Lege ihn mit „Geänderte Fassung aktivieren“ fest.'),
'stand' => $hasActive && $active->licence_scope !== null ? 'erledigt' : 'offen',
'aktion' => $hasActive && $active->licence_scope === null ? $activate : null,
'pflicht' => false,
],
[
'titel' => 'Produktseite zuordnen',
'text' => $page !== null
? 'Zugeordnet: „'.$pageName.'“. Optionen derselben Produktseite sind Alternativen im Warenkorb.'
: 'Der Shop zeigt ein Angebot auf der Seite eines Programms. Wähle in der Maske die Produktseite. Ein Paket braucht eine eigene Produktseite, sonst ist es Alternative zu den Einzelangeboten dieser Seite.',
'stand' => $page !== null ? 'erledigt' : 'offen',
'aktion' => $page !== null ? null : $activate,
'text' => $own
? 'Eigene Paketseite: Sie zeigt den Umfang des Pakets. Optionen desselben Pakets sind Alternativen im Warenkorb.'
: ($page !== null
? 'Zugeordnet: „'.$pageName.'“. Optionen derselben Produktseite sind Alternativen im Warenkorb.'
: 'Der Shop zeigt ein Angebot auf der Seite eines Programms. Wähle in der Maske die Produktseite. Ein Paket, das für sich verkauft wird, erhält dort „Eigene Paketseite“ und zeigt seinen Umfang; sonst erscheint es auf der Seite eines fremden Programms.'),
'stand' => $own || $page !== null ? 'erledigt' : 'offen',
'aktion' => $own || $page !== null ? null : $activate,
],
[
'titel' => 'Produktseite öffentlich',
'text' => $page === null
'text' => ! $own && $page === null
? 'Wird geprüft, sobald eine Produktseite zugeordnet ist.'
: ($shown
: ($own
? 'Die eigene Paketseite ist öffentlich, sobald die aktive Fassung ein Kauf mit Preis ist.'
: ($shown
? 'Das Programm ist zur Anzeige freigegeben. Das Angebot erscheint in der Shop-Suche und auf der Produktseite.'
: 'Das Programm „'.$pageName.'“ ist nicht zur Anzeige freigegeben oder kein Programm. Das Angebot ist dort nicht auffindbar.'),
: 'Das Programm „'.$pageName.'“ ist nicht zur Anzeige freigegeben oder kein Programm. Das Angebot ist dort nicht auffindbar.')),
'stand' => $shown ? 'erledigt' : 'offen',
'aktion' => $page === null || $shown ? null : ['label' => 'Programm öffnen', 'href' => EditorialCatalog::editUrl($page)],
],
+6 -6
View File
@@ -7,6 +7,7 @@
use App\Domain\Commerce\Cart;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\OrderHolders;
use App\Domain\Commerce\ProductOptions;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -31,9 +32,8 @@ public function show(Request $request, Cart $cart, OrderHolders $holders): View
public function add(Offer $offer, Cart $cart, PublicCatalogReader $catalog): RedirectResponse
{
$page = $offer->composition;
$result = $page !== null && $catalog->shownVersion($page) !== null
? $cart->add($offer)
: Cart::UNAVAILABLE;
$listed = $offer->standalone_bundle || ($page !== null && $catalog->shownVersion($page) !== null);
$result = $listed ? $cart->add($offer) : Cart::UNAVAILABLE;
$back = $this->productPage($offer);
return match ($result) {
@@ -81,8 +81,8 @@ public function accept(Offer $offer, Cart $cart): RedirectResponse
private function productPage(Offer $offer): RedirectResponse
{
return $offer->composition_id !== null
? redirect()->route('public.program', $offer->composition_id)
: redirect()->route('cart');
$url = app(ProductOptions::class)->pageUrl($offer);
return $url !== null ? redirect()->to($url) : redirect()->route('cart');
}
}
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionStructureReader;
use App\Domain\Cms\Catalog\PublicCatalogReader;
@@ -17,6 +18,25 @@ public function index(PublicCatalogReader $catalog): View
return view('public.programs', ['programs' => $catalog->publicPrograms()]);
}
/**
* Eigene Produktseite eines Pakets, das für sich vermarktet wird: Sie zeigt den tatsächlichen Umfang des Pakets
* (die enthaltenen Artikel) und darunter die kaufbaren Lizenzoptionen. Ohne kaufbare Option gibt es sie nicht.
*/
public function package(Bundle $bundle, ProductOptions $products, Cart $cart): View
{
abort_unless(Shop::enabled(), 404);
$options = $products->forBundle($bundle);
abort_if($options === [], 404);
return view('public.package', [
'bundle' => $bundle,
'contents' => $products->bundleContents($options),
'options' => $options,
'cart' => $cart,
'switchTo' => session('shop.switch'),
]);
}
public function program(Composition $composition, PublicCatalogReader $catalog, ProductOptions $products, Cart $cart): View
{
$version = $catalog->shownVersion($composition);
+22 -1
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Money;
@@ -37,7 +38,7 @@ public function index(Request $request, ProductOptions $products, PublicCatalogR
$summary = $summaries[$composition->id];
$cards[] = [
'composition' => $composition,
'url' => route('public.program', $composition),
'title' => $title,
'teaser' => (string) ($composition->teaser ?: $composition->summary),
'from' => Money::format($summary['from_cents']),
@@ -45,6 +46,26 @@ public function index(Request $request, ProductOptions $products, PublicCatalogR
];
}
// 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]);
}
}