Biete Lizenzartikel mit mehreren Optionen direkt am Artikel an
CI Feature / test (push) Successful in 3m32s
Deploy Test / test (push) Successful in 3m23s
Deploy Test / deploy (push) Successful in 28s

Am Lizenzartikel gibt es den Abschnitt "Im Shop verkaufen": Er listet die
Optionen mit Preis, Rechten, Nutzerkreis und Zustand. "Option hinzufuegen"
fragt nur Rechteprofil, Preis, Eignung, Nutzerkreis und eine Bezeichnung ab;
Artikel, Inhalt und Vergabe stehen fest. Aendern und Aus dem Verkauf nehmen
laufen am selben Ort.

OfferService::offerArticle legt Angebot und erste Fassung in einer
Transaktion an, damit eine fehlgeschlagene Pruefung kein leeres Angebot
hinterlaesst. reviseArticleOption aktiviert die naechste Fassung und lehnt
Optionen anderer Artikel ab. Aus der Angebotsmaske entfaellt die Auswahl
"Programmfassung, die abgedeckt sein muss"; die Pruefung bleibt im Dienst.
Pakete und der Altbestand behalten die Angebotsmaske.
This commit is contained in:
Lars committed 2026-11-25 22:23:14 +01:00
1 parent 93ae01c986
commit 3b0b4c955e
9 files changed
+673 -18

No files matched your search

@@ -13,20 +13,32 @@
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\LicenceScope;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Catalog\StatusValue;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\AssignsPillars;
use App\Filament\Support\CatalogLabels;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\ManagesEditorialSurface;
use App\Filament\Support\ManagesRichFields;
use App\Filament\Support\PublicationReadiness;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\Utilities\Get;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
@@ -409,6 +421,201 @@ public function withdrawAction(): Action
});
}
/**
* Die Optionen dieses Artikels im Shop: Bezeichnung, Preis, Rechte, Nutzerkreis und Zustand je Option. Gelesen wird
* die aktive, sonst die letzte Fassung.
*
* @return list<array<string, mixed>>
*/
public function optionRows(): array
{
/** @var LicenseArticle $article */
$article = $this->getRecord();
$options = app(ProductOptions::class);
$offers = app(OfferService::class);
$rows = [];
foreach ($options->offersOfArticle($article) as $offer) {
$version = $offers->purchasableVersion($offer)
?? $offer->versions()->where('status', OfferStatus::Aktiv)->orderByDesc('number')->first()
?? $offer->versions()->orderByDesc('number')->first();
if ($version === null) {
continue;
}
$version->loadMissing('lines.rights.profile');
$active = StatusValue::of($version->status) === OfferStatus::Aktiv->value;
$buyable = $active && $offers->purchasableVersion($offer) !== null;
$rows[] = [
'offer' => $offer->id,
'name' => $offer->optionName(),
'price' => $version->price_cents === null ? 'kein Preis' : Money::format((int) $version->price_cents),
'licence' => LicenceScope::label($version->licence_scope, $version->trainer_count),
'for' => $version->holder_kind === 'organisation' ? 'Organisationen und Vereine' : 'Privatpersonen',
'rights' => (string) ($version->lines->first()?->rights?->profile?->name ?? '–'),
'number' => $version->number,
'active' => $active,
'buyable' => $buyable,
'zustand' => match (true) {
$buyable => ['label' => 'Im Shop', 'ton' => 'gut'],
$active => ['label' => CatalogLabels::vergabe($version).' · nicht im Shop', 'ton' => 'neutral'],
default => ['label' => 'Nicht im Verkauf', 'ton' => 'leise'],
},
'page' => $buyable ? parse_url((string) $options->pageUrl($offer), PHP_URL_PATH) : null,
'url' => OfferResource::getUrl('view', ['record' => $offer]),
];
}
return $rows;
}
/** Ein Artikel lässt sich anbieten, wenn sein aktueller Stand veröffentlicht ist. */
public function canOffer(): bool
{
return app(PublicationReadiness::class)->articleUsable($this->getRecord());
}
/**
* Option hinzufügen oder ändern: Rechteprofil, Preis, Nutzerkreis und Eignung. Der Artikel steht fest, es gibt keine
* Auswahl von Artikel oder Inhalt. Mit dem Argument `offer` ändert die Aktion eine bestehende Option (nächste Fassung).
*/
public function optionAction(): Action
{
return Action::make('option')
->modalWidth('2xl')
->modalHeading(fn (array $arguments): string => isset($arguments['offer'])
? 'Option „'.$this->optionOf($arguments)->optionName().'“ ändern'
: 'Option hinzufügen: so wird der Artikel verkauft')
->modalDescription(fn (array $arguments): string => isset($arguments['offer'])
? 'Die Maske ist mit der letzten Fassung vorbelegt. Erst „Speichern und anbieten“ schaltet die Änderung öffentlich: Die bisherige Fassung wird beendet und bleibt gespeichert, neue Käufe nutzen die neue. Bereits begründete Berechtigungen und Bestellungen ändern sich nicht. „Abbrechen“ verwirft die Eingaben.'
: 'Eine Option ist eine Lizenz mit Rechteprofil und Preis. Der Artikel kann mehrere Optionen haben, zum Beispiel für Privatpersonen und für Vereine. Sie erscheinen gemeinsam auf der Produktseite des Artikels. „Abbrechen“ verwirft die Eingaben.')
->modalSubmitActionLabel('Speichern und anbieten')
->fillForm(fn (array $arguments): array => $this->optionForm($arguments))
->schema([
Select::make('rights_id')->label('Rechteprofil')
->options(fn (): array => CatalogOptions::rights())
->required()
->helperText('Was Käufer mit dem Artikel tun dürfen (ansehen, herunterladen, Nutzungszweck).'),
TextInput::make('price_euro')->label('Preis in Euro')->suffix('€')->required()
->helperText('Zum Beispiel 49,00. Ein Kauf braucht einen Preis über 0,00 €.'),
Select::make('holder_kind')->label('Geeignet für')->options([
'person' => 'Privatpersonen',
'organisation' => 'Organisationen und Vereine',
])->required()->live()
->helperText('Wähle die Eignung passend zum Rechteprofil: Organisationslizenzen brauchen institutionelle Rechte.'),
Select::make('licence_scope')->label('Nutzerkreis')
->options(LicenceScope::options())
->required()->live()
->helperText('Wie viele Trainer die Inhalte einsetzen dürfen. Der Download bleibt beim bestellenden Konto.'),
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)
->live(),
TextInput::make('option_label')->label('Bezeichnung der Option')
->maxLength(120)
->placeholder(fn (Get $get): string => OfferService::defaultOptionLabel($get('holder_kind'), $get('licence_scope'), $get('trainer_count')))
->helperText('So heißt die Option auf der Produktseite. Leer lassen übernimmt den grauen Vorschlag.'),
])
->action(function (array $data, array $arguments): void {
$this->report(function () use ($data, $arguments): string {
/** @var LicenseArticle $article */
$article = $this->getRecord();
$rights = RightsProfileVersion::query()->findOrFail($data['rights_id']);
$price = Money::parse($data['price_euro'] ?? null);
$label = filled($data['option_label'] ?? null)
? trim((string) $data['option_label'])
: OfferService::defaultOptionLabel($data['holder_kind'], $data['licence_scope'], $data['trainer_count'] ?? null);
$attributes = [
'holder_kind' => $data['holder_kind'],
'licence_scope' => $data['licence_scope'],
'trainer_count' => $data['trainer_count'] ?? null,
'price_cents' => $price,
];
$service = app(OfferService::class);
if (isset($arguments['offer'])) {
$offer = $this->optionOf($arguments);
$version = $service->reviseArticleOption($offer, $article, $rights, $attributes, $label);
} else {
$name = app(ProductOptions::class)->articleTitle($article).': '.$label;
$version = $service->offerArticle($article, $rights, $attributes, $name, $label);
$offer = $version->offer;
}
$page = app(ProductOptions::class)->pageUrl($offer);
return 'Die Option „'.$offer->optionName().'“ ist als Fassung '.$version->number.' aktiv und im Shop kaufbar'
.($page !== null ? ' unter '.parse_url($page, PHP_URL_PATH) : '').'.';
}, 'Die Option ist aktiv.');
$this->refreshRecord();
});
}
/** Eine Option aus dem Verkauf nehmen: nur die aktive Fassung dieser Option wird beendet. */
public function optionEndAction(): Action
{
return Action::make('optionEnd')
->color('danger')
->requiresConfirmation()
->modalHeading(fn (array $arguments): string => 'Option „'.$this->optionOf($arguments)->optionName().'“ aus dem Verkauf nehmen?')
->modalDescription('Die aktive Fassung wird beendet und bleibt gespeichert. Die Option ist danach nicht mehr kaufbar; in vorhandenen Warenkörben bleibt sie mit Hinweis sichtbar und blockiert den Abschluss, bis der Käufer sie entfernt. Bestehende Berechtigungen und Bestellungen ändern sich nicht. Andere Optionen des Artikels bleiben kaufbar.')
->modalSubmitActionLabel('Aus dem Verkauf nehmen')
->action(function (array $arguments): void {
$this->report(function () use ($arguments): string {
$offer = $this->optionOf($arguments);
$version = app(OfferService::class)->end($offer);
return 'Die Option „'.$offer->optionName().'“ ist aus dem Verkauf genommen (Fassung '.$version->number.' beendet).';
}, 'Die Option ist aus dem Verkauf genommen.');
$this->refreshRecord();
});
}
/**
* Die Option aus den Argumenten der Aktion, nur wenn sie zu diesem Artikel gehört.
*
* @param array<string, mixed> $arguments
*/
private function optionOf(array $arguments): Offer
{
/** @var LicenseArticle $article */
$article = $this->getRecord();
$offer = collect(app(ProductOptions::class)->offersOfArticle($article))->first(fn (Offer $offer): bool => $offer->id === (int) ($arguments['offer'] ?? 0));
return $offer ?? abort(404);
}
/**
* @param array<string, mixed> $arguments
* @return array<string, mixed>
*/
private function optionForm(array $arguments): array
{
if (! isset($arguments['offer'])) {
$rights = array_keys(CatalogOptions::rights());
return [
'holder_kind' => 'person',
'licence_scope' => LicenceScope::SINGLE,
'rights_id' => count($rights) === 1 ? $rights[0] : null,
];
}
$offer = $this->optionOf($arguments);
$version = $offer->versions()->with('lines')->orderByDesc('number')->firstOrFail();
return [
'rights_id' => $version->lines->first()?->rights_profile_version_id,
'price_euro' => $version->price_cents === null ? null : number_format($version->price_cents / 100, 2, ',', ''),
'holder_kind' => $version->holder_kind,
'licence_scope' => $version->licence_scope,
'trainer_count' => $version->trainer_count,
'option_label' => $offer->option_label,
];
}
private function isFirstStand(): bool
{
return ! $this->getRecord()->releases()->exists();
@@ -24,7 +24,7 @@ class ListOffers extends ListRecords
public function getSubheading(): string|Htmlable|null
{
return 'Ein Angebot verbindet Artikel oder eine Paketfassung mit einem Rechteprofil. Die aufgelösten Berechtigungen stehen auf der Angebotsseite.';
return 'Ein Angebot ist eine Option zum Kauf: ein Artikel oder eine Paketfassung mit Rechteprofil und Preis. Optionen eines einzelnen Artikels legst du am Lizenzartikel an („Im Shop verkaufen“); hier stehen alle Angebote, auch die der Pakete.';
}
protected function getHeaderActions(): array
@@ -6,7 +6,6 @@
use App\Domain\Catalog\BundleService;
use App\Domain\Catalog\BundleVersion;
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;
@@ -136,18 +135,6 @@ public function activateAction(): Action
])->required(),
TextInput::make('price_euro')->label('Preis in Euro')->suffix('€')
->helperText('Nur bei einem Kauf, zum Beispiel 49,00.'),
Select::make('composition_version_id')->label('Programmfassung, die abgedeckt sein muss')
->options(function (): array {
return CompositionVersion::query()
->where('status', 'bereit')
->with('composition.editorialContentKind')
->orderByDesc('id')
->get()
->mapWithKeys(fn (CompositionVersion $version): array => [$version->id => CatalogOptions::compositionLabel($version)])
->all();
})
->searchable()
->helperText('Wenn gewählt, lässt sich die Fassung nur aktivieren, wenn jeder Bestandteil in den Artikeln enthalten ist.'),
Repeater::make('lines')->label('Positionen')->schema([
Select::make('kind')->label('Ziel')->options([
'article' => 'Lizenzartikel',
@@ -217,7 +204,6 @@ public function activateAction(): Action
'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,
]);
});