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

+4 -1
View File
@@ -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);
+27 -16
View File
@@ -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
*/
+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>
*/
@@ -2,6 +2,7 @@
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\BundleService;
use App\Domain\Catalog\BundleVersion;
use App\Domain\Catalog\Composition;
@@ -15,7 +16,6 @@
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Catalog\StatusValue;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
use App\Filament\Pages\Zahlungsjournal;
@@ -48,9 +48,6 @@ 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;
@@ -117,10 +114,6 @@ public function activateAction(): Action
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',
@@ -215,12 +208,7 @@ public function activateAction(): Action
$service = app(OfferService::class);
$version = DB::transaction(function () use ($service, $offer, $data, $lines, $kept, $price) {
$service->assignProduct(
$offer,
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,
);
$service->setOptionLabel($offer, $data['option_label'] ?? null);
return $service->activate($offer, $lines, [
...$kept,
@@ -269,47 +257,23 @@ public function endAction(): Action
});
}
/** „ der Produktseite „Titel““ oder leer, wenn die Option noch keiner Produktseite zugeordnet ist. */
/** „ der Produktseite „Titel““ oder leer, wenn die Option (noch) keine Produktseite hat. */
private function productPageSuffix(): string
{
$page = $this->getRecord()->composition;
$key = app(ProductOptions::class)->groupKey($this->getRecord());
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
{
$catalog = app(PublicCatalogReader::class);
return [self::OWN_BUNDLE_PAGE => 'Eigene Paketseite · nur für ein Angebot aus genau einer Paketfassung (Katalog → Pakete), nicht für einen Lizenzartikel'] + Composition::query()
->with('editorialContentKind')
->whereNull('archived_at')
->orderBy('designation')
->get()
->sortBy(fn (Composition $composition): int => $catalog->shownVersion($composition) !== null ? 0 : (in_array($composition->editorialContentKind?->slug, PublicCatalogReader::PUBLIC_KINDS, true) ? 1 : 2))
->mapWithKeys(fn (Composition $composition): array => [
$composition->id => ($composition->display_title ?: $composition->designation)
.' ('.($composition->editorialContentKind?->label ?? 'Zusammenstellung').')'
.self::pageHint($catalog, $composition),
])
->all();
}
/** Sagt bei jeder Auswahl, ob die Seite im Shop auffindbar ist und was fehlt, wenn nicht. */
private static function pageHint(PublicCatalogReader $catalog, Composition $composition): string
{
if ($catalog->shownVersion($composition) !== null) {
return ' · im Shop auffindbar';
if ($key === null) {
return '';
}
return in_array($composition->editorialContentKind?->slug, PublicCatalogReader::PUBLIC_KINDS, true)
? ' · noch nicht zur Anzeige freigegeben, im Shop nicht auffindbar'
: ' · kein Programm, im Shop nicht auffindbar (der Shop zeigt nur Programme)';
$id = (int) substr($key, 2);
$title = match ($key[0]) {
'a' => app(ProductOptions::class)->articleTitle(LicenseArticle::query()->find($id)),
'b' => (string) Bundle::query()->whereKey($id)->value('name'),
default => ($page = Composition::query()->find($id)) === null ? '' : (string) ($page->display_title ?: $page->designation),
};
return $title === '' ? '' : ' der Produktseite „'.$title.'“';
}
/**
@@ -322,7 +286,7 @@ private function formFromActive(): array
$active = $this->activeVersion();
/** @var Offer $offer */
$offer = $this->getRecord();
$option = ['option_label' => $offer->option_label, 'composition_id' => $offer->standalone_bundle ? self::OWN_BUNDLE_PAGE : $offer->composition_id];
$option = ['option_label' => $offer->option_label];
if ($active === null) {
return [...$option, 'holder_kind' => 'person', 'licence_scope' => LicenceScope::SINGLE, 'grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
@@ -437,8 +401,8 @@ private function optionAbschnitt(Offer $offer, OfferVersion $active): array
->map(fn (array $item): string => $item['purpose'].($item['rights'] === [] ? '' : ': '.implode(', ', $item['rights'])))
->unique()
->implode('; ');
$seite = $offer->composition;
$eigeneSeite = $offer->standalone_bundle;
$key = app(ProductOptions::class)->groupKey($offer);
$seite = $key === null ? null : app(ProductOptions::class)->pageUrl($offer);
$kaufbar = app(OfferService::class)->purchasableVersion($offer) !== null;
return [
@@ -452,7 +416,7 @@ private function optionAbschnitt(Offer $offer, OfferVersion $active): array
['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: '.($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.'],
['text' => 'Produktseite: '.($kaufbar && $seite !== null ? 'öffentlich unter '.parse_url($seite, PHP_URL_PATH) : 'keine, solange die Option kein Kauf mit Preis ist'), 'neben' => $kaufbar ? 'Option „'.$offer->optionName().'“; Optionen desselben Artikels sind Alternativen im Warenkorb.' : null],
],
];
}
+10 -26
View File
@@ -15,7 +15,6 @@
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\ReleaseStatus;
use App\Domain\Catalog\StatusValue;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
@@ -35,7 +34,6 @@ class PublicationReadiness
public function __construct(
private readonly BundleService $bundles,
private readonly OfferService $offers,
private readonly PublicCatalogReader $catalog,
) {}
/** Ein Artikel ist verwendbar, wenn sein aktueller Stand veröffentlicht ist. */
@@ -227,10 +225,7 @@ public function forOffer(Offer $offer): array
$articleIds = $hasActive ? $active->resolvedScopes()->pluck('license_article_id')->map(fn ($id): int => (int) $id)->all() : [];
$missing = $this->unusableArticles($articleIds);
$buyable = $hasActive && $this->offers->purchasableVersion($offer) !== null;
$page = $offer->composition;
$own = (bool) $offer->standalone_bundle;
$shown = $own || ($page !== null && $this->catalog->shownVersion($page) !== null);
$pageName = $page !== null ? (string) ($page->display_title ?: $page->designation) : '';
$pageUrl = app(ProductOptions::class)->pageUrl($offer);
$activate = ['label' => $hasActive ? 'Geänderte Fassung aktivieren' : 'Angebot konfigurieren', 'wire' => "mountAction('activate')"];
return $this->result([
@@ -272,26 +267,15 @@ public function forOffer(Offer $offer): array
'pflicht' => false,
],
[
'titel' => 'Produktseite zuordnen',
'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 (Katalog → Pakete), das für sich verkauft wird, erhält dort „Eigene Paketseite“ und zeigt seinen Umfang; ein Lizenzartikel braucht dagegen ein Programm, das unter „Programme“ angelegt und zur Anzeige freigegeben ist. Ein Modul kann keine Produktseite sein.'),
'stand' => $own || $page !== null ? 'erledigt' : 'offen',
'aktion' => $own || $page !== null ? null : $activate,
],
[
'titel' => 'Produktseite öffentlich',
'text' => ! $own && $page === null
? 'Wird geprüft, sobald eine Produktseite zugeordnet ist.'
: ($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.')),
'stand' => $shown ? 'erledigt' : 'offen',
'aktion' => $page === null || $shown ? null : ['label' => 'Programm öffnen', 'href' => EditorialCatalog::editUrl($page)],
'titel' => 'Produktseite im Shop',
'text' => match (true) {
! $hasActive => 'Die Produktseite ergibt sich aus der Fassung: Sie ist die Seite des Artikels (oder des Pakets), den die Option verkauft. Du ordnest sie nicht zu.',
$pageUrl !== null && $buyable => 'Die Option erscheint auf der Produktseite '.parse_url($pageUrl, PHP_URL_PATH).' und im Shop. Optionen desselben Artikels sind Alternativen im Warenkorb.',
$pageUrl !== null => 'Sobald die Option ein Kauf mit Preis ist, erscheint sie auf '.parse_url($pageUrl, PHP_URL_PATH).'.',
default => 'Diese Fassung hat mehrere Positionen und damit keine Produktseite. Verkauft wird genau ein Artikel oder ein Paket; mehrere Artikel gemeinsam verkaufst du als Paket.',
},
'stand' => $buyable && $pageUrl !== null ? 'erledigt' : 'offen',
'aktion' => $hasActive && $pageUrl === null ? $activate : null,
],
]);
}
+6 -1
View File
@@ -31,8 +31,13 @@ public function show(Request $request, Cart $cart, OrderHolders $holders): View
public function add(Offer $offer, Cart $cart, PublicCatalogReader $catalog): RedirectResponse
{
$key = app(ProductOptions::class)->groupKey($offer);
$page = $offer->composition;
$listed = $offer->standalone_bundle || ($page !== null && $catalog->shownVersion($page) !== null);
$listed = match (true) {
$key === null => false,
$key[0] === 'c' => $page !== null && $catalog->shownVersion($page) !== null,
default => true,
};
$result = $listed ? $cart->add($offer) : Cart::UNAVAILABLE;
$back = $this->productPage($offer);
@@ -5,6 +5,8 @@
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionStructureReader;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Cart;
use App\Domain\Commerce\ProductOptions;
@@ -37,6 +39,28 @@ public function package(Bundle $bundle, ProductOptions $products, Cart $cart): V
]);
}
/**
* Produktseite eines Lizenzartikels: Titel und Beschreibung aus der Redaktion des Artikels (sonst aus seinem Inhalt),
* der Aufbau des verkauften Inhalts und darunter die kaufbaren Lizenzoptionen. Ohne kaufbare Option gibt es sie nicht.
*/
public function article(LicenseArticle $article, ProductOptions $products, Cart $cart): View
{
abort_unless(Shop::enabled() && $article->archived_at === null, 404);
$options = $products->forArticle($article);
abort_if($options === [], 404);
return view('public.article', [
'article' => $article,
'title' => $products->articleTitle($article),
'profile' => app(EditorialProfileReader::class)->read($article, 'detail'),
'goal' => $products->articleGoal($article),
'nodes' => $products->articleStructure($article),
'options' => $options,
'cart' => $cart,
'switchTo' => session('shop.switch'),
]);
}
public function program(Composition $composition, PublicCatalogReader $catalog, ProductOptions $products, Cart $cart): View
{
$version = $catalog->shownVersion($composition);
@@ -47,6 +71,7 @@ public function program(Composition $composition, PublicCatalogReader $catalog,
'version' => $version,
'nodes' => app(CompositionStructureReader::class)->tree($version),
'options' => Shop::enabled() ? $products->forComposition($composition) : [],
'articles' => Shop::enabled() ? $products->articlesOf($composition) : [],
'cart' => $cart,
'switchTo' => session('shop.switch'),
]);
+25
View File
@@ -4,7 +4,9 @@
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\FormattedText;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
@@ -47,6 +49,29 @@ public function index(Request $request, ProductOptions $products, PublicCatalogR
];
}
// Lizenzartikel mit kaufbarer Option: Titel und Kurztext aus der Redaktion des Artikels (sonst seines Inhalts).
$articleSummaries = $products->articleSummaries();
foreach (LicenseArticle::query()->whereIn('id', array_keys($articleSummaries))->whereNull('archived_at')->orderBy('code')->get() as $article) {
$profile = app(EditorialProfileReader::class)->read($article, 'kachel');
$title = $products->articleTitle($article);
$teaser = (string) ($profile->value('teaser') ?: $profile->value('summary'));
$haystack = mb_strtolower($title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms);
if ($term !== '' && ! str_contains($haystack, mb_strtolower($term))) {
continue;
}
$summary = $articleSummaries[$article->id];
$cards[] = [
'url' => route('shop.article', $article),
'title' => $title,
'teaser' => $teaser,
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
// 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);