Add feature tests for shop functionality and organization purchases
- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation. - Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing. - Add ShopProductPageTest to verify shop product listings, search functionality, and product page details. - Introduce BuildsShop trait for seeding test data related to shop functionality. - Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
This commit is contained in:
1 parent
6c8bbee363
commit
4e0760db1e
106 files changed
+4068
-76
No files matched your search
@@ -64,6 +64,7 @@ protected function catalogRows(): array
|
||||
if ($active !== null) {
|
||||
$chips[] = ['label' => 'Fassung '.$active->number.' aktiv', 'ton' => 'gut'];
|
||||
$chips[] = ['label' => CatalogLabels::vergabe($active), 'ton' => 'neutral'];
|
||||
$chips[] = ['label' => $active->holder_kind === 'organisation' ? 'Für Organisationen' : 'Für Privatpersonen', 'ton' => 'neutral'];
|
||||
$zustand[] = 'aktiv';
|
||||
$text = $active->lines->map(fn ($line): string => ($line->article !== null
|
||||
? 'Lizenzartikel '.$line->article->code
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace App\Filament\Resources\Offers\Pages;
|
||||
|
||||
use App\Domain\Catalog\BundleVersion;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
@@ -11,6 +13,8 @@
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Domain\Catalog\RightsProfileVersion;
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Domain\Commerce\Money;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Filament\Resources\Offers\OfferResource;
|
||||
use App\Filament\Support\CatalogLabels;
|
||||
use App\Filament\Support\CatalogOptions;
|
||||
@@ -25,6 +29,7 @@
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Angebot im gemeinsamen Rahmen. Anlegen und Ändern nutzen dieselbe Maske (FACH-20): „Fassung aktivieren“ legt die
|
||||
@@ -91,22 +96,34 @@ public function activateAction(): Action
|
||||
return Action::make('activate')
|
||||
->label(fn (): string => $this->activeVersion() !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren')
|
||||
->modalHeading(fn (): string => $this->activeVersion() !== null
|
||||
? 'Angebot ändern: Fassung '.$this->nextNumber().' aktivieren'
|
||||
: 'Erste Fassung aktivieren')
|
||||
? 'Option „'.$this->getRecord()->optionName().'“ ändern: Fassung '.$this->nextNumber().' aktivieren'
|
||||
: 'Option „'.$this->getRecord()->optionName().'“: erste Fassung aktivieren')
|
||||
->modalDescription(fn (): string => ($active = $this->activeVersion()) !== null
|
||||
? 'Die Maske ist mit Fassung '.$active->number.' vorbelegt; Inhaberart, Laufzeitregel und Steuerklasse werden übernommen. Beim Aktivieren wird Fassung '.$active->number.' beendet und bleibt unverändert gespeichert; neue Erwerbe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen ändern sich dadurch nicht.'
|
||||
: 'Positionen, Vergabe und Preis bilden die erste Fassung. Nach dem Aktivieren ist sie unveränderlich; Änderungen ergeben eine weitere Fassung.')
|
||||
? 'Betroffen ist nur die Option „'.$this->getRecord()->optionName().'“'.$this->productPageSuffix().'. Die Maske ist mit Fassung '.$active->number.' vorbelegt. Erst „Fassung '.$this->nextNumber().' aktivieren“ schaltet die Änderung öffentlich (auch Bezeichnung und Produktseite, sie erzeugen ebenfalls eine neue Fassung und zeigen offenen Warenkörben „Bedingungen aktualisiert“): Fassung '.$active->number.' wird beendet und bleibt gespeichert, neue Käufe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen und Bestellungen ändern sich nicht. Andere Optionen derselben Produktseite bleiben unverändert kaufbar. „Abbrechen“ verwirft die Eingaben.'
|
||||
: 'Positionen, Vergabe, Eignung und Preis bilden die erste Fassung dieser Option. Erst das Aktivieren macht sie öffentlich; danach ist sie unveränderlich, Änderungen ergeben eine weitere Fassung.')
|
||||
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' aktivieren')
|
||||
->modalWidth('4xl')
|
||||
->fillForm(fn (): array => $this->formFromActive())
|
||||
->schema([
|
||||
TextInput::make('option_label')->label('Bezeichnung der Option')
|
||||
->helperText('So heißt die Option auf der Produktseite, zum Beispiel „Einzellizenz für Privatpersonen“. Sie ist keine bindende Bedingung, wird aber wie die übrigen Angaben erst mit „Fassung aktivieren“ übernommen.')
|
||||
->maxLength(120),
|
||||
Select::make('composition_id')->label('Produktseite')
|
||||
->options(fn (): array => $this->productPages())
|
||||
->searchable()
|
||||
->helperText('Optionen derselben Produktseite sind Alternativen; im Warenkorb liegt nur eine davon. Die Beschreibung der Seite wird zentral an der Komposition gepflegt. Die Zuordnung wird mit „Fassung aktivieren“ übernommen.'),
|
||||
Select::make('holder_kind')->label('Geeignet für')->options([
|
||||
'person' => 'Privatpersonen',
|
||||
'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('grant_kind')->label('Vergabe')->options([
|
||||
'kauf' => 'Kauf',
|
||||
'auf_abruf' => 'Auf Abruf',
|
||||
'bei_registrierung' => 'Bei Registrierung',
|
||||
])->required(),
|
||||
TextInput::make('price_cents')->label('Preis in Cent')->numeric()
|
||||
->helperText('Nur bei einem Kauf. 500 bedeutet 5,00 €.'),
|
||||
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()
|
||||
@@ -147,29 +164,94 @@ public function activateAction(): Action
|
||||
];
|
||||
}
|
||||
|
||||
// Bedingungen, die die Maske nicht zeigt, bleiben bei einer Änderung die der aktiven Fassung; ohne
|
||||
// aktive Fassung gilt wie bisher die Vorgabe (Personen, dauerhaft).
|
||||
// Bedingungen, die die Maske nicht zeigt, bleiben bei einer Änderung die der aktiven Fassung.
|
||||
$active = $this->activeVersion();
|
||||
$kept = $active === null ? ['holder_kind' => 'person'] : [
|
||||
'holder_kind' => $active->holder_kind,
|
||||
$kept = $active === null ? [] : [
|
||||
'term_rule' => $active->term_rule,
|
||||
'tax_class' => $active->tax_class,
|
||||
'dynamic' => (bool) $active->dynamic,
|
||||
];
|
||||
$version = app(OfferService::class)->activate($offer, $lines, [
|
||||
...$kept,
|
||||
'grant_kind' => $data['grant_kind'],
|
||||
'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'],
|
||||
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
|
||||
]);
|
||||
$price = Money::parse($data['price_euro'] ?? null);
|
||||
|
||||
return 'Fassung '.$version->number.' ist aktiv.';
|
||||
if ($data['grant_kind'] === 'kauf' && ($price === null || $price <= 0)) {
|
||||
throw new DomainRuleException('Ein Kauf braucht einen Preis über 0,00 €.');
|
||||
}
|
||||
|
||||
$service = app(OfferService::class);
|
||||
$version = DB::transaction(function () use ($service, $offer, $data, $lines, $kept, $price) {
|
||||
$service->assignProduct(
|
||||
$offer,
|
||||
filled($data['composition_id'] ?? null) ? (int) $data['composition_id'] : null,
|
||||
$data['option_label'] ?? null,
|
||||
);
|
||||
|
||||
return $service->activate($offer, $lines, [
|
||||
...$kept,
|
||||
'holder_kind' => $data['holder_kind'],
|
||||
'grant_kind' => $data['grant_kind'],
|
||||
'price_cents' => $price,
|
||||
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
|
||||
]);
|
||||
});
|
||||
|
||||
return 'Fassung '.$version->number.' ist aktiv. Die Option ist in dieser Fassung öffentlich kaufbar.';
|
||||
}, 'Die Angebotsfassung ist aktiv.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Option aus dem Verkauf nehmen: nur die aktive Fassung dieser Option wird beendet.
|
||||
*/
|
||||
public function endAction(): Action
|
||||
{
|
||||
return Action::make('end')
|
||||
->label('Aus dem Verkauf nehmen')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->modalHeading(fn (): string => 'Option „'.$this->getRecord()->optionName().'“ aus dem Verkauf nehmen?')
|
||||
->modalDescription(fn (): string => 'Betroffen ist nur die Option „'.$this->getRecord()->optionName().'“'.$this->productPageSuffix().'. 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 derselben Produktseite bleiben kaufbar.')
|
||||
->modalSubmitActionLabel('Aus dem Verkauf nehmen')
|
||||
->visible(fn (): bool => $this->activeVersion() !== null)
|
||||
->action(function (): void {
|
||||
$this->report(function (): string {
|
||||
$version = app(OfferService::class)->end($this->getRecord());
|
||||
|
||||
return 'Fassung '.$version->number.' ist beendet. Die Option ist nicht mehr kaufbar.';
|
||||
}, 'Die Option ist aus dem Verkauf genommen.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
/** „ der Produktseite „Titel““ oder leer, wenn die Option noch keiner Produktseite zugeordnet ist. */
|
||||
private function productPageSuffix(): string
|
||||
{
|
||||
$page = $this->getRecord()->composition;
|
||||
|
||||
return $page === null ? '' : ' der Produktseite „'.($page->display_title ?: $page->designation).'“';
|
||||
}
|
||||
|
||||
/**
|
||||
* Produktseiten, die als Ziel wählbar sind: Kompositionen mit Bezeichnung und Art.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function productPages(): array
|
||||
{
|
||||
return Composition::query()
|
||||
->with('editorialContentKind')
|
||||
->whereNull('archived_at')
|
||||
->orderBy('designation')
|
||||
->get()
|
||||
->mapWithKeys(fn (Composition $composition): array => [
|
||||
$composition->id => ($composition->display_title ?: $composition->designation)
|
||||
.' ('.($composition->editorialContentKind?->label ?? 'Zusammenstellung').')',
|
||||
])
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vorbelegung aus der aktiven Fassung; ohne aktive Fassung eine leere Position.
|
||||
*
|
||||
@@ -178,14 +260,19 @@ public function activateAction(): Action
|
||||
private function formFromActive(): array
|
||||
{
|
||||
$active = $this->activeVersion();
|
||||
/** @var Offer $offer */
|
||||
$offer = $this->getRecord();
|
||||
$option = ['option_label' => $offer->option_label, 'composition_id' => $offer->composition_id];
|
||||
|
||||
if ($active === null) {
|
||||
return ['grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
|
||||
return [...$option, 'holder_kind' => 'person', 'grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
|
||||
}
|
||||
|
||||
return [
|
||||
...$option,
|
||||
'holder_kind' => $active->holder_kind,
|
||||
'grant_kind' => $active->grant_kind,
|
||||
'price_cents' => $active->price_cents,
|
||||
'price_euro' => $active->price_cents === null ? null : number_format($active->price_cents / 100, 2, ',', ''),
|
||||
'lines' => $active->lines->sortBy('position')->map(fn ($line): array => [
|
||||
'kind' => $line->license_article_id !== null ? 'article' : 'bundle',
|
||||
'article_id' => $line->license_article_id,
|
||||
@@ -220,13 +307,21 @@ private function angebotDaten(): array
|
||||
'status' => $active !== null
|
||||
? ['text' => 'Fassung '.$active->number.' aktiv · '.$vergabe, 'ton' => 'gut']
|
||||
: ['text' => 'Noch keine aktive Fassung. Ein Angebot ohne aktive Fassung kann niemand erwerben.', 'ton' => 'offen'],
|
||||
'aktionen' => [[
|
||||
'label' => $active !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren',
|
||||
'wire' => "mountAction('activate')",
|
||||
'art' => 'primary',
|
||||
]],
|
||||
'aktionen' => [
|
||||
[
|
||||
'label' => $active !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren',
|
||||
'wire' => "mountAction('activate')",
|
||||
'art' => 'primary',
|
||||
],
|
||||
...($active !== null ? [[
|
||||
'label' => 'Aus dem Verkauf nehmen',
|
||||
'wire' => "mountAction('end')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
],
|
||||
],
|
||||
'haupt' => [
|
||||
...($active !== null ? [$this->optionAbschnitt($offer, $active)] : []),
|
||||
[
|
||||
'titel' => 'Positionen',
|
||||
'zusatz' => $active !== null ? 'Fassung '.$active->number : null,
|
||||
@@ -261,6 +356,37 @@ private function angebotDaten(): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Option auf einen Blick: Preis in Euro, Eignung, Rechte, zugrunde liegender Inhalt, Status und Produktseite.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function optionAbschnitt(Offer $offer, OfferVersion $active): array
|
||||
{
|
||||
$option = app(ProductOptions::class)->describe($offer, $active);
|
||||
$inhalt = collect($option['scope'])->pluck('article')->unique()->implode(', ');
|
||||
$rechte = collect($option['scope'])
|
||||
->map(fn (array $item): string => $item['purpose'].($item['rights'] === [] ? '' : ': '.implode(', ', $item['rights'])))
|
||||
->unique()
|
||||
->implode('; ');
|
||||
$seite = $offer->composition;
|
||||
$kaufbar = app(OfferService::class)->purchasableVersion($offer) !== null;
|
||||
|
||||
return [
|
||||
'titel' => 'Die Option auf einen Blick',
|
||||
'zusatz' => 'Fassung '.$active->number,
|
||||
'hilfe' => 'So erscheint die Option auf der öffentlichen Produktseite und im Warenkorb. Die Angaben dieser Fassung sind unveränderlich.',
|
||||
'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' => '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.'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aufgelöster Leistungsumfang in lesbaren Fähigkeiten (dieselben Bezeichnungen wie beim Rechteprofil).
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user