Merge remote-tracking branch 'origin/develop' into feature/merkmale-symbol-seite
This commit is contained in:
commit
fbe4226347
32 files changed
+1640
-43
No files matched your search
@@ -13,6 +13,8 @@ class Offer extends Model
|
||||
'composition_id',
|
||||
'option_label',
|
||||
'standalone_bundle',
|
||||
'claim_access',
|
||||
'claim_requires_article_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -31,6 +33,12 @@ public function composition(): BelongsTo
|
||||
return $this->belongsTo(Composition::class);
|
||||
}
|
||||
|
||||
/** Freigaben einzelner Konten für den Abruf (nur bei Vergabe „auf Abruf“ mit der Regel „freigeschaltete Konten“). */
|
||||
public function releases(): HasMany
|
||||
{
|
||||
return $this->hasMany(OfferRelease::class);
|
||||
}
|
||||
|
||||
/** Bezeichnung der Option auf der Produktseite. */
|
||||
public function optionName(): string
|
||||
{
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Freigabe eines Kontos für ein Angebot „auf Abruf“ (ADR-56). Gilt je Angebot und Konto, wird nie gelöscht, nur entzogen.
|
||||
*/
|
||||
class OfferRelease extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'offer_id',
|
||||
'user_id',
|
||||
'granted_by',
|
||||
'granted_at',
|
||||
'valid_until',
|
||||
'revoked_by',
|
||||
'revoked_at',
|
||||
'reason',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'granted_at' => 'datetime',
|
||||
'valid_until' => 'datetime',
|
||||
'revoked_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function offer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Offer::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function grantor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'granted_by');
|
||||
}
|
||||
|
||||
public function isActiveAt(CarbonInterface $now): bool
|
||||
{
|
||||
return $this->revoked_at === null
|
||||
&& $this->granted_at->lessThanOrEqualTo($now)
|
||||
&& ($this->valid_until === null || $this->valid_until->greaterThan($now));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use App\Domain\Commerce\Shop;
|
||||
use App\Domain\Commerce\ShopCatalog;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
/**
|
||||
* Shop-Produkte (ADR-55): die kaufbaren Produkte als Kacheln, aus derselben Datenquelle wie die Shopseite (ShopCatalog).
|
||||
*
|
||||
* Gespeichert werden nur Darstellungswahl und Filter (Säule, Materialart); Titel, Bild, Preis und Marker kommen zur
|
||||
* Laufzeit aus den Fachdaten. Das Widget zeigt nichts, solange der Shop nicht sichtbar ist (Schalter „Shop sichtbar“).
|
||||
* Eine Kachel begründet keine Berechtigung. Anders als Programm- und Modulkarten trägt es Preise und führt zur Produktseite.
|
||||
*/
|
||||
class ShopProductsWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'shop_products';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Shop-Produkte';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Die kaufbaren Produkte des Shops als Kacheln mit Bild, Marker und Preis; optional gefiltert und sortiert.';
|
||||
}
|
||||
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return [2, 3, 4];
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Die Kacheln stehen untereinander; ab etwa 17 rem Kachelbreite mehrere nebeneinander.';
|
||||
}
|
||||
|
||||
public function stages(): array
|
||||
{
|
||||
return [
|
||||
'narrow' => 'eine Kachel je Zeile',
|
||||
'wide' => 'mehrere Kacheln nebeneinander ab 17 rem Kachelbreite',
|
||||
];
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-shopping-bag';
|
||||
}
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[2, 4, 17, 28, 'line'], [21, 4, 17, 28, 'line'], [40, 4, 17, 28, 'line'], [4, 6, 13, 10, 'image'], [23, 6, 13, 10, 'image'], [42, 6, 13, 10, 'image'], [4, 19, 11, 3, 'ink'], [23, 19, 11, 3, 'ink'], [42, 19, 11, 3, 'ink'], [4, 26, 7, 3, 'accent'], [23, 26, 7, 3, 'accent'], [42, 26, 7, 3, 'accent']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [
|
||||
'kacheln' => 'Kacheln mit Bild',
|
||||
];
|
||||
}
|
||||
|
||||
public function settings(): array
|
||||
{
|
||||
return [
|
||||
'sort' => ['name' => 'Alphabetisch', 'neu' => 'Neueste zuerst', 'preis' => 'Preis aufsteigend'],
|
||||
'limit' => ['alle' => 'Alle Produkte', 'n3' => '3 Produkte', 'n6' => '6 Produkte', 'n9' => '9 Produkte', 'n12' => '12 Produkte', 'n24' => '24 Produkte'],
|
||||
'search' => ['aus' => 'Ohne Suchfeld', 'an' => 'Mit Suchfeld'],
|
||||
];
|
||||
}
|
||||
|
||||
public function settingLabels(): array
|
||||
{
|
||||
return [
|
||||
'sort' => ['Reihenfolge', 'Ohne Wahl gilt die Reihenfolge der Shopseite: Altbestand, Artikel, Pakete.'],
|
||||
'limit' => ['Anzahl', 'Wie viele Produkte höchstens erscheinen. Ohne Wahl erscheinen alle.'],
|
||||
'search' => ['Suchfeld', 'Ein Suchfeld über den Kacheln. Es wirkt auf der Shopseite; auf anderen Seiten führt die Suche in den Shop.'],
|
||||
];
|
||||
}
|
||||
|
||||
public function settingGroups(): array
|
||||
{
|
||||
return ['Auswahl' => ['sort', 'limit', 'search']];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'heading' => ['nullable', 'string', 'max:160'],
|
||||
'intro' => ['nullable', 'string', 'max:400'],
|
||||
'pillar' => ['nullable', 'integer'],
|
||||
'kind' => ['nullable', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('heading')->label('Abschnittsüberschrift (optional)')->maxLength(160),
|
||||
Textarea::make('intro')->label('Einleitung (optional)')->rows(2)->maxLength(400),
|
||||
Select::make('pillar')
|
||||
->label('Nur Produkte einer Säule (optional)')
|
||||
->helperText('Nur veröffentlichte Säulen sind wählbar. Ohne Wahl erscheinen alle Produkte.')
|
||||
->options(fn (): array => Pillar::query()->published()->pluck('name', 'id')->all())
|
||||
->placeholder('Alle Säulen')
|
||||
->native(false),
|
||||
Select::make('kind')
|
||||
->label('Nur eine Materialart (optional)')
|
||||
->options(fn (): array => EditorialContentKind::query()->where('is_active', true)->orderBy('sort_order')->get()
|
||||
->filter(fn (EditorialContentKind $kind): bool => in_array('lizenzartikel', (array) ($kind->contexts ?? []), true))
|
||||
->pluck('label', 'id')->all())
|
||||
->placeholder('Alle Materialarten')
|
||||
->native(false),
|
||||
];
|
||||
}
|
||||
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
foreach (['heading', 'intro'] as $key) {
|
||||
$data[$key] = filled($data[$key] ?? null) ? trim((string) $data[$key]) : null;
|
||||
}
|
||||
|
||||
$pillar = filled($data['pillar'] ?? null) ? (int) $data['pillar'] : null;
|
||||
|
||||
if ($pillar !== null && ! Pillar::query()->published()->whereKey($pillar)->exists()) {
|
||||
$errors->add('data.pillar', 'Diese Säule gibt es nicht oder sie ist nicht veröffentlicht.');
|
||||
$pillar = null;
|
||||
}
|
||||
|
||||
$kind = filled($data['kind'] ?? null) ? (int) $data['kind'] : null;
|
||||
|
||||
if ($kind !== null && ! EditorialContentKind::query()->whereKey($kind)->exists()) {
|
||||
$errors->add('data.kind', 'Diese Materialart gibt es nicht.');
|
||||
$kind = null;
|
||||
}
|
||||
|
||||
$data['pillar'] = $pillar;
|
||||
$data['kind'] = $kind;
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
if (! Shop::visible()) {
|
||||
return ['cards' => [], 'term' => '', 'shopVisible' => false];
|
||||
}
|
||||
|
||||
$settings = is_array($widget['settings'] ?? null) ? $widget['settings'] : [];
|
||||
$search = ($settings['search'] ?? 'aus') === 'an';
|
||||
$term = $search && ! $context->preview ? trim((string) request()->query('suche', '')) : '';
|
||||
$limit = preg_match('/^n(\d+)$/', (string) ($settings['limit'] ?? ''), $match) === 1 ? (int) $match[1] : null;
|
||||
|
||||
return [
|
||||
'cards' => app(ShopCatalog::class)->cards($term, [
|
||||
'pillar' => $widget['data']['pillar'] ?? null,
|
||||
'kind' => $widget['data']['kind'] ?? null,
|
||||
'sort' => $settings['sort'] ?? null,
|
||||
'limit' => $limit,
|
||||
]),
|
||||
'term' => $term,
|
||||
'shopVisible' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
$heading = $widget['data']['heading'] ?? null;
|
||||
|
||||
return trim(($heading ? $heading.' · ' : '').'Shop-Produkte');
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,16 @@ public function __construct(
|
||||
private readonly ShopMarkers $markers,
|
||||
) {}
|
||||
|
||||
public const SORTS = ['name' => 'Alphabetisch', 'neu' => 'Neueste zuerst', 'preis' => 'Preis aufsteigend'];
|
||||
|
||||
/**
|
||||
* @param array{pillar?: int|null, kind?: int|null, sort?: string|null, limit?: int|null} $options Filter nach Säule
|
||||
* und Materialart, Sortierung (name, neu, preis) und Höchstzahl
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function cards(string $term = ''): array
|
||||
public function cards(string $term = '', array $options = []): array
|
||||
{
|
||||
$term = mb_strtolower(trim($term));
|
||||
$term = mb_strtolower(mb_substr(trim($term), 0, 100));
|
||||
$cards = [];
|
||||
|
||||
// Altbestand: Angebote mit mehreren Positionen auf einer freigegebenen Programmseite.
|
||||
@@ -54,6 +58,8 @@ public function cards(string $term = ''): array
|
||||
$teaser = (string) ($composition->teaser ?: FormattedText::plain($composition->summary));
|
||||
$pillars = $this->pillarNames($composition->pillars);
|
||||
$card = $this->card('c:'.$composition->id, 'programm', route('public.program', $composition), $title, $teaser, $summaries[$composition->id], 'Programm', null, $pillars, [], $this->image($composition));
|
||||
$card['pillar_ids'] = $composition->pillars->pluck('id')->map(fn ($id): int => (int) $id)->all();
|
||||
$card['kind_id'] = $composition->editorial_content_kind_id !== null ? (int) $composition->editorial_content_kind_id : null;
|
||||
|
||||
if ($this->matches($term, $title.' '.$teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms.' '.implode(' ', $pillars))) {
|
||||
$cards[] = $card;
|
||||
@@ -74,6 +80,9 @@ public function cards(string $term = ''): array
|
||||
'a:'.$article->id, 'artikel', route('shop.article', $article), $title, $teaser, $articleSummaries[$article->id],
|
||||
(string) ($kind?->label ?? ''), $this->symbol($kind?->symbol), $pillars, $this->markers->visible($article, $offerIds), $this->image($article),
|
||||
);
|
||||
$card['pillar_ids'] = $article->pillars->pluck('id')->map(fn ($id): int => (int) $id)->all();
|
||||
$card['kind_id'] = $kind !== null ? (int) $kind->id : null;
|
||||
$card['since'] = $this->markers->firstOffered($offerIds)?->getTimestamp() ?? 0;
|
||||
|
||||
if ($this->matches($term, $title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms.' '.($kind?->label ?? '').' '.implode(' ', $pillars))) {
|
||||
$cards[] = $card;
|
||||
@@ -94,7 +103,42 @@ public function cards(string $term = ''): array
|
||||
}
|
||||
}
|
||||
|
||||
return $cards;
|
||||
return $this->arrange($cards, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter, Sortierung und Höchstzahl der Kacheln (Widget und Shopseite). Ohne Angabe bleibt die Reihenfolge der
|
||||
* Datenquelle.
|
||||
*
|
||||
* @param list<array<string, mixed>> $cards
|
||||
* @param array<string, mixed> $options
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function arrange(array $cards, array $options): array
|
||||
{
|
||||
$pillar = isset($options['pillar']) ? (int) $options['pillar'] : 0;
|
||||
$kind = isset($options['kind']) ? (int) $options['kind'] : 0;
|
||||
|
||||
if ($pillar > 0) {
|
||||
$cards = array_filter($cards, fn (array $card): bool => in_array($pillar, $card['pillar_ids'] ?? [], true));
|
||||
}
|
||||
|
||||
if ($kind > 0) {
|
||||
$cards = array_filter($cards, fn (array $card): bool => ($card['kind_id'] ?? null) === $kind);
|
||||
}
|
||||
|
||||
$cards = array_values($cards);
|
||||
|
||||
match ($options['sort'] ?? null) {
|
||||
'name' => usort($cards, fn (array $a, array $b): int => strcmp(mb_strtolower($a['title']), mb_strtolower($b['title']))),
|
||||
'neu' => usort($cards, fn (array $a, array $b): int => [$b['since'] ?? 0, mb_strtolower($a['title'])] <=> [$a['since'] ?? 0, mb_strtolower($b['title'])]),
|
||||
'preis' => usort($cards, fn (array $a, array $b): int => [$a['from_cents'], mb_strtolower($a['title'])] <=> [$b['from_cents'], mb_strtolower($b['title'])]),
|
||||
default => null,
|
||||
};
|
||||
|
||||
$limit = isset($options['limit']) ? (int) $options['limit'] : 0;
|
||||
|
||||
return $limit > 0 ? array_slice($cards, 0, $limit) : $cards;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,6 +164,9 @@ private function card(string $key, string $kind, string $url, string $title, str
|
||||
'symbol' => $symbol,
|
||||
'pillars' => $pillars,
|
||||
'markers' => $markers,
|
||||
'pillar_ids' => [],
|
||||
'kind_id' => null,
|
||||
'since' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public function visible(LicenseArticle $article, array $offerIds, ?Carbon $now =
|
||||
}
|
||||
|
||||
/** Zeitpunkt der ersten Fassung eines Angebots als Kauf. */
|
||||
private function firstOffered(array $offerIds): ?Carbon
|
||||
public function firstOffered(array $offerIds): ?Carbon
|
||||
{
|
||||
if ($offerIds === []) {
|
||||
return null;
|
||||
|
||||
@@ -28,6 +28,11 @@ public function claim(User $user, Offer $offer): Acquisition
|
||||
throw new DomainRuleException('Dieses Angebot richtet sich nicht an Personen.');
|
||||
}
|
||||
|
||||
// Wer ein Angebot auf Abruf übernehmen darf, bestimmt seine Regel (ADR-56); „bei Registrierung“ kennt keine.
|
||||
if ($version->grant_kind === 'auf_abruf') {
|
||||
app(OfferAccess::class)->assertMayClaim($user, $offer);
|
||||
}
|
||||
|
||||
return $this->issue($user, $version, AcquisitionType::FreierAbruf, 'offer', $offer->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Entitlement;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Neue Stände zu Artikeln, die das Konto bereits besitzt („Neu für dich“, ADR-56).
|
||||
*
|
||||
* Nach der Updatepolitik (ADR-09, OPEN-01) stehen alle später veröffentlichten Stände desselben Artikels dem Inhaber
|
||||
* ohne Aufpreis zu, solange die Lizenz gilt. Sie erscheinen von selbst in der Bibliothek; diese Liste macht sie nur
|
||||
* sichtbar. Es wird nichts vergeben und nichts übernommen.
|
||||
*/
|
||||
class NewStands
|
||||
{
|
||||
/** So lange (in Tagen) nach der Veröffentlichung erscheint ein neuer Stand in der Liste. */
|
||||
public const DAYS = 90;
|
||||
|
||||
/**
|
||||
* @return Collection<int, array{grant: Grant, title: string, number: int, since: CarbonInterface}>
|
||||
*/
|
||||
public function forUser(User $user): Collection
|
||||
{
|
||||
if ($user->party_id === null) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$limit = now()->subDays(self::DAYS);
|
||||
$titles = app(ProductOptions::class);
|
||||
|
||||
return Grant::query()
|
||||
->with(['article.currentRelease', 'releaseAtGrant'])
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', now()))
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
||||
->whereHas('article', fn ($query) => $query->whereNull('archived_at'))
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->filter(function (Grant $grant) use ($limit): bool {
|
||||
$current = $grant->article?->currentRelease;
|
||||
$had = $grant->releaseAtGrant;
|
||||
|
||||
return $current instanceof ArticleRelease
|
||||
&& $had instanceof ArticleRelease
|
||||
&& (int) $current->number > (int) $had->number
|
||||
&& $current->created_at !== null
|
||||
&& $current->created_at->greaterThanOrEqualTo($limit);
|
||||
})
|
||||
->unique('license_article_id')
|
||||
->map(fn (Grant $grant): array => [
|
||||
'grant' => $grant,
|
||||
'title' => $titles->articleTitle($grant->article),
|
||||
'number' => (int) $grant->article->currentRelease->number,
|
||||
'since' => $grant->article->currentRelease->created_at,
|
||||
])
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Entitlement;
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferRelease;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Wer ein Angebot „auf Abruf“ in die Bibliothek übernehmen darf (ADR-56). Drei Regeln, serverseitig beim Abruf geprüft:
|
||||
* alle angemeldeten Mitglieder, nur ausdrücklich freigeschaltete Konten (Freigabe je Angebot und Konto, wie bei
|
||||
* Rabattcodes, nie gelöscht, nur entzogen) oder Mitglieder, die einen bestimmten anderen Artikel besitzen.
|
||||
*
|
||||
* Die Regel gilt nur für Vergaben „auf Abruf“. „Bei Registrierung“ geht automatisch an neue Konten; Kauf ist Sache der
|
||||
* Kasse. Die Regel begründet keinen Zugang, sie begrenzt nur den freien Abruf.
|
||||
*/
|
||||
class OfferAccess
|
||||
{
|
||||
public const ALL = 'alle';
|
||||
|
||||
public const RELEASED = 'konten';
|
||||
|
||||
public const OWNERS = 'besitz';
|
||||
|
||||
public const OPTIONS = [
|
||||
self::ALL => 'Alle angemeldeten Mitglieder',
|
||||
self::RELEASED => 'Nur freigeschaltete Konten',
|
||||
self::OWNERS => 'Mitglieder, die einen bestimmten Artikel besitzen',
|
||||
];
|
||||
|
||||
public function __construct(private readonly OfferService $offers) {}
|
||||
|
||||
/**
|
||||
* Die Regel eines Angebots festlegen. Der Artikel ist nur bei „besitzt einen Artikel“ gesetzt.
|
||||
*/
|
||||
public function setRule(Offer $offer, string $access, ?int $articleId = null): void
|
||||
{
|
||||
if (! array_key_exists($access, self::OPTIONS)) {
|
||||
throw new DomainRuleException('Diese Regel für den Abruf gibt es nicht.');
|
||||
}
|
||||
|
||||
if ($access === self::OWNERS) {
|
||||
$article = $articleId === null ? null : LicenseArticle::query()->whereNull('archived_at')->find($articleId);
|
||||
|
||||
if ($article === null) {
|
||||
throw new DomainRuleException('Für diese Regel braucht es einen vorhandenen, nicht archivierten Lizenzartikel.');
|
||||
}
|
||||
} else {
|
||||
$articleId = null;
|
||||
}
|
||||
|
||||
$offer->claim_access = $access;
|
||||
$offer->claim_requires_article_id = $articleId;
|
||||
$offer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Warum das Konto das Angebot nicht abrufen darf; null, wenn es das darf. Regeln gelten nur für Vergaben „auf Abruf“.
|
||||
*/
|
||||
public function refusal(User $user, Offer $offer, ?CarbonInterface $now = null): ?string
|
||||
{
|
||||
$now ??= now();
|
||||
$version = $this->activeVersion($offer);
|
||||
|
||||
if ($version === null || ! in_array($version->grant_kind, ['auf_abruf', 'bei_registrierung'], true) || $version->holder_kind !== 'person') {
|
||||
return 'Dieses Angebot wird nicht frei vergeben.';
|
||||
}
|
||||
|
||||
if ($user->party_id === null) {
|
||||
return 'Nur ein Mitgliedskonto kann ein Angebot abrufen.';
|
||||
}
|
||||
|
||||
// „Bei Registrierung“ geht automatisch an neue Konten und kennt keine Regel.
|
||||
if ($version->grant_kind !== 'auf_abruf') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match ((string) $offer->claim_access) {
|
||||
self::RELEASED => $this->activeRelease($offer, $user, $now) === null ? 'Dieses Angebot ist für dein Konto nicht freigeschaltet.' : null,
|
||||
self::OWNERS => $offer->claim_requires_article_id !== null && $this->owns($user, (int) $offer->claim_requires_article_id, $now) ? null : 'Dieses Angebot steht für dein Konto nicht zur Verfügung.',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function mayClaim(User $user, Offer $offer, ?CarbonInterface $now = null): bool
|
||||
{
|
||||
return $this->refusal($user, $offer, $now) === null;
|
||||
}
|
||||
|
||||
public function assertMayClaim(User $user, Offer $offer): void
|
||||
{
|
||||
$reason = $this->refusal($user, $offer);
|
||||
|
||||
if ($reason !== null) {
|
||||
throw new DomainRuleException($reason);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Angebote auf Abruf, die das Konto jetzt übernehmen darf und noch nicht übernommen hat.
|
||||
*
|
||||
* @return Collection<int, Offer>
|
||||
*/
|
||||
public function claimable(User $user): Collection
|
||||
{
|
||||
if ($user->party_id === null) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$taken = Acquisition::query()
|
||||
->where('party_id', $user->party_id)
|
||||
->where('type', AcquisitionType::FreierAbruf)
|
||||
->where('reference_type', 'offer')
|
||||
->pluck('reference_id')
|
||||
->all();
|
||||
|
||||
return Offer::query()
|
||||
->whereHas('versions', fn ($query) => $query->where('status', OfferStatus::Aktiv)->where('holder_kind', 'person')->whereIn('grant_kind', ['auf_abruf', 'bei_registrierung']))
|
||||
->whereNotIn('id', $taken)
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->filter(fn (Offer $offer): bool => $this->mayClaim($user, $offer))
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Konto für ein Angebot freischalten (Regel „nur freigeschaltete Konten“).
|
||||
*/
|
||||
public function release(Offer $offer, User $member, ?User $actor, ?CarbonInterface $until = null, ?string $reason = null): OfferRelease
|
||||
{
|
||||
if ($offer->claim_access !== self::RELEASED) {
|
||||
throw new DomainRuleException('Freigaben gibt es nur bei der Regel „nur freigeschaltete Konten“.');
|
||||
}
|
||||
|
||||
if ($member->party_id === null) {
|
||||
throw new DomainRuleException('Nur ein Mitgliedskonto kann für ein Angebot freigeschaltet werden.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($offer, $member, $actor, $until, $reason): OfferRelease {
|
||||
Offer::query()->whereKey($offer->id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
if ($this->activeRelease($offer, $member) !== null) {
|
||||
throw new DomainRuleException('Dieses Konto ist für das Angebot bereits freigeschaltet.');
|
||||
}
|
||||
|
||||
if ($until !== null && $until->lessThanOrEqualTo(now())) {
|
||||
throw new DomainRuleException('Das Ende der Freigabe liegt in der Vergangenheit.');
|
||||
}
|
||||
|
||||
return OfferRelease::query()->create([
|
||||
'offer_id' => $offer->id,
|
||||
'user_id' => $member->id,
|
||||
'granted_by' => $actor?->id,
|
||||
'granted_at' => now(),
|
||||
'valid_until' => $until,
|
||||
'reason' => filled($reason) ? trim((string) $reason) : null,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Entzieht die Freigabe. Sie bleibt mit Zeitpunkt, Person und Begründung gespeichert; bereits übernommene Angebote
|
||||
* bleiben in der Bibliothek.
|
||||
*/
|
||||
public function revoke(OfferRelease $release, ?User $actor, ?string $reason = null): OfferRelease
|
||||
{
|
||||
return DB::transaction(function () use ($release, $actor, $reason): OfferRelease {
|
||||
$release = OfferRelease::query()->lockForUpdate()->findOrFail($release->id);
|
||||
|
||||
if ($release->revoked_at !== null) {
|
||||
throw new DomainRuleException('Diese Freigabe ist bereits entzogen.');
|
||||
}
|
||||
|
||||
$release->forceFill([
|
||||
'revoked_at' => now(),
|
||||
'revoked_by' => $actor?->id,
|
||||
'reason' => filled($reason) ? trim((string) $reason) : $release->reason,
|
||||
])->save();
|
||||
|
||||
return $release;
|
||||
});
|
||||
}
|
||||
|
||||
public function activeRelease(Offer $offer, User $member, ?CarbonInterface $now = null): ?OfferRelease
|
||||
{
|
||||
$now ??= now();
|
||||
|
||||
return OfferRelease::query()
|
||||
->where('offer_id', $offer->id)
|
||||
->where('user_id', $member->id)
|
||||
->whereNull('revoked_at')
|
||||
->where('granted_at', '<=', $now)
|
||||
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', $now))
|
||||
->first();
|
||||
}
|
||||
|
||||
/** Das Konto besitzt den Artikel, wenn seine Person eine aktive, gültige Berechtigung darauf hat. */
|
||||
public function owns(User $user, int $articleId, ?CarbonInterface $now = null): bool
|
||||
{
|
||||
$now ??= now();
|
||||
|
||||
if ($user->party_id === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Grant::query()
|
||||
->where('license_article_id', $articleId)
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->where(fn ($query) => $query->whereNull('valid_from')->orWhere('valid_from', '<=', $now))
|
||||
->where(fn ($query) => $query->whereNull('valid_until')->orWhere('valid_until', '>', $now))
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function activeVersion(Offer $offer): ?OfferVersion
|
||||
{
|
||||
return $offer->versions()->where('status', OfferStatus::Aktiv)->orderByDesc('number')->first();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
use App\Domain\Catalog\LicenceScope;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferRelease;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
@@ -17,6 +18,7 @@
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Domain\Commerce\Money;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Domain\Entitlement\OfferAccess;
|
||||
use App\Filament\Pages\Zahlungsjournal;
|
||||
use App\Filament\Resources\Offers\OfferResource;
|
||||
use App\Filament\Support\CatalogLabels;
|
||||
@@ -24,9 +26,12 @@
|
||||
use App\Filament\Support\PublicationReadiness;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Filament\Support\ShopAccess;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
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;
|
||||
@@ -34,6 +39,7 @@
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
@@ -243,6 +249,175 @@ public function endAction(): Action
|
||||
});
|
||||
}
|
||||
|
||||
/** Ein Angebot auf Abruf: nur dafür gibt es Regeln, wer es übernehmen darf (ADR-56). */
|
||||
private function isOnDemand(): bool
|
||||
{
|
||||
return $this->activeVersion()?->grant_kind === 'auf_abruf';
|
||||
}
|
||||
|
||||
/**
|
||||
* Wer das Angebot übernehmen darf: alle Mitglieder, nur freigeschaltete Konten oder wer einen Artikel besitzt.
|
||||
*/
|
||||
public function claimRuleAction(): Action
|
||||
{
|
||||
return Action::make('claimRule')
|
||||
->label('Regel für den Abruf')
|
||||
->modalHeading(fn (): string => 'Wer darf „'.$this->getRecord()->name.'“ abrufen?')
|
||||
->modalDescription('Die Regel gilt für den kostenlosen Abruf in die Bibliothek und wird beim Abruf geprüft. Sie begrenzt nur den Abruf; sie vergibt nichts. Bereits übernommene Angebote bleiben in der Bibliothek.')
|
||||
->modalSubmitActionLabel('Regel speichern')
|
||||
->visible(fn (): bool => $this->isOnDemand())
|
||||
->fillForm(fn (): array => [
|
||||
'claim_access' => (string) ($this->getRecord()->claim_access ?: OfferAccess::ALL),
|
||||
'claim_requires_article_id' => $this->getRecord()->claim_requires_article_id,
|
||||
])
|
||||
->schema([
|
||||
Select::make('claim_access')->label('Wer darf abrufen')
|
||||
->options(OfferAccess::OPTIONS)
|
||||
->required()->live()->native(false)
|
||||
->helperText('„Nur freigeschaltete Konten“: Du schaltest einzelne Konten auf dieser Seite frei und entziehst die Freigabe wieder. Sie gilt nur für dieses Angebot.'),
|
||||
Select::make('claim_requires_article_id')->label('Artikel, den das Konto besitzen muss')
|
||||
->options(fn (): array => LicenseArticle::query()->whereNull('archived_at')->orderBy('code')->get()
|
||||
->mapWithKeys(fn (LicenseArticle $article): array => [$article->id => app(ProductOptions::class)->articleTitle($article)])->all())
|
||||
->searchable()
|
||||
->required(fn (Get $get): bool => $get('claim_access') === OfferAccess::OWNERS)
|
||||
->visible(fn (Get $get): bool => $get('claim_access') === OfferAccess::OWNERS)
|
||||
->helperText('Das Konto muss eine gültige Berechtigung auf diesen Artikel haben, zum Beispiel durch einen Kauf.'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): string {
|
||||
app(OfferAccess::class)->setRule($this->getRecord(), (string) $data['claim_access'], filled($data['claim_requires_article_id'] ?? null) ? (int) $data['claim_requires_article_id'] : null);
|
||||
|
||||
return 'Die Regel für den Abruf ist gespeichert.';
|
||||
}, 'Die Regel ist gespeichert.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
public function releaseAction(): Action
|
||||
{
|
||||
return Action::make('release')
|
||||
->label('Konto freischalten')
|
||||
->modalHeading(fn (): string => 'Konto für „'.$this->getRecord()->name.'“ freischalten')
|
||||
->modalDescription('Das Konto darf genau dieses Angebot abrufen, solange Freigabe und Angebot gelten. Die Freigabe gilt nicht für andere Angebote und bleibt mit dem Entzug im Verlauf stehen.')
|
||||
->modalSubmitActionLabel('Konto freischalten')
|
||||
->visible(fn (): bool => $this->isOnDemand() && $this->getRecord()->claim_access === OfferAccess::RELEASED)
|
||||
->schema([
|
||||
Select::make('user_id')->label('Mitgliedskonto')->required()->searchable()
|
||||
->getSearchResultsUsing(fn (string $search): array => $this->searchMembers($search))
|
||||
->getOptionLabelUsing(fn ($value): ?string => ($user = User::query()->find($value)) === null ? null : $user->name.' ('.$user->email.')')
|
||||
->helperText('Suche nach Name oder E-Mail-Adresse. Nur Konten mit Mitgliedsprofil.'),
|
||||
DatePicker::make('valid_until')->label('Freigabe gültig bis einschließlich')->native(false)->displayFormat('d.m.Y')
|
||||
->helperText('Leer: ohne Ende.'),
|
||||
Textarea::make('reason')->label('Grundlage der Freigabe')->rows(2)->maxLength(500)
|
||||
->helperText('Zum Beispiel „Teilnahme am Seminar am 12.11.2026“. Bleibt im Verlauf stehen.'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): string {
|
||||
$member = User::query()->findOrFail($data['user_id']);
|
||||
$until = filled($data['valid_until'] ?? null) ? Carbon::parse((string) $data['valid_until'], config('app.timezone'))->endOfDay() : null;
|
||||
app(OfferAccess::class)->release($this->getRecord(), $member, auth('staff')->user() ?? auth()->user(), $until, $data['reason'] ?? null);
|
||||
|
||||
return 'Das Konto von '.$member->name.' ist für das Angebot freigeschaltet.';
|
||||
}, 'Das Konto ist freigeschaltet.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
public function revokeAction(): Action
|
||||
{
|
||||
return Action::make('revoke')
|
||||
->label('Freigabe entziehen')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Freigabe entziehen?')
|
||||
->modalDescription('Das Konto kann das Angebot danach nicht mehr abrufen. Bereits übernommene Angebote bleiben in der Bibliothek. Die Freigabe bleibt mit dem Entzug im Verlauf stehen.')
|
||||
->modalSubmitActionLabel('Freigabe entziehen')
|
||||
->schema([
|
||||
Textarea::make('reason')->label('Grund')->rows(2)->maxLength(500),
|
||||
])
|
||||
->action(function (array $data, array $arguments): void {
|
||||
$this->report(function () use ($data, $arguments): string {
|
||||
$release = OfferRelease::query()->where('offer_id', $this->getRecord()->id)->findOrFail((int) ($arguments['release'] ?? 0));
|
||||
app(OfferAccess::class)->revoke($release, auth('staff')->user() ?? auth()->user(), $data['reason'] ?? null);
|
||||
|
||||
return 'Die Freigabe ist entzogen.';
|
||||
}, 'Die Freigabe ist entzogen.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function searchMembers(string $search): array
|
||||
{
|
||||
$like = '%'.mb_strtolower(trim($search)).'%';
|
||||
|
||||
return User::query()
|
||||
->whereNotNull('party_id')
|
||||
->where(fn ($query) => $query->whereRaw('LOWER(name) LIKE ?', [$like])->orWhereRaw('LOWER(email) LIKE ?', [$like]))
|
||||
->orderBy('name')
|
||||
->limit(20)
|
||||
->get()
|
||||
->mapWithKeys(fn (User $user): array => [$user->id => $user->name.' ('.$user->email.')'])
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abschnitte „Wer darf abrufen“ und „Freigeschaltete Konten“ für ein Angebot auf Abruf.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function abrufAbschnitte(Offer $offer): array
|
||||
{
|
||||
$date = fn ($value): string => $value?->format('d.m.Y') ?? '';
|
||||
$access = (string) ($offer->claim_access ?: OfferAccess::ALL);
|
||||
$article = $offer->claim_requires_article_id !== null ? LicenseArticle::query()->find($offer->claim_requires_article_id) : null;
|
||||
$releases = $offer->releases()->with(['user', 'grantor'])->orderByDesc('id')->get();
|
||||
$active = $releases->filter(fn (OfferRelease $release): bool => $release->revoked_at === null);
|
||||
$past = $releases->filter(fn (OfferRelease $release): bool => $release->revoked_at !== null);
|
||||
$sections = [[
|
||||
'titel' => 'Wer darf abrufen',
|
||||
'hilfe' => 'Diese Regel gilt für den kostenlosen Abruf in die Bibliothek (Mitgliederbereich → Angebote). Sie wird beim Abruf geprüft, nicht nur in der Anzeige.',
|
||||
'zeilen' => [[
|
||||
'text' => OfferAccess::OPTIONS[$access] ?? $access,
|
||||
'neben' => $access === OfferAccess::OWNERS
|
||||
? 'Erforderlich: '.($article !== null ? app(ProductOptions::class)->articleTitle($article) : 'ein Artikel fehlt (Regel prüfen)')
|
||||
: ($access === OfferAccess::RELEASED ? 'Mit „Konto freischalten“ gibst du einzelne Konten frei.' : 'Jedes angemeldete Mitgliedskonto sieht das Angebot und kann es übernehmen.'),
|
||||
]],
|
||||
]];
|
||||
|
||||
if ($access === OfferAccess::RELEASED) {
|
||||
$sections[] = [
|
||||
'titel' => 'Freigeschaltete Konten',
|
||||
'zusatz' => $active->count().' aktiv',
|
||||
'hilfe' => 'Nur diese Konten sehen das Angebot im Mitgliederbereich und können es übernehmen.',
|
||||
'zeilen' => $active->map(fn (OfferRelease $release): array => [
|
||||
'text' => ($release->user?->name ?? 'Konto').' ('.($release->user?->email ?? '').')',
|
||||
'neben' => 'freigeschaltet am '.$date($release->granted_at).($release->grantor ? ' von '.$release->grantor->name : '').($release->valid_until ? ', gültig bis einschließlich '.$date($release->valid_until) : '').(filled($release->reason) ? ' · '.$release->reason : ''),
|
||||
'aktion' => ['label' => 'Entziehen', 'wire' => "mountAction('revoke', { release: ".$release->id.' })'],
|
||||
])->values()->all(),
|
||||
'leer' => ['titel' => 'Noch kein Konto freigeschaltet', 'text' => 'Mit „Konto freischalten“ gibst du ein Konto für dieses Angebot frei.'],
|
||||
];
|
||||
|
||||
if ($past->isNotEmpty()) {
|
||||
$sections[] = [
|
||||
'titel' => 'Entzogene Freigaben',
|
||||
'hilfe' => 'Der Verlauf bleibt erhalten.',
|
||||
'zeilen' => $past->map(fn (OfferRelease $release): array => [
|
||||
'text' => $release->user?->name ?? 'Konto',
|
||||
'neben' => 'entzogen am '.$date($release->revoked_at).(filled($release->reason) ? ' · '.$release->reason : ''),
|
||||
])->values()->all(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/** „ der Produktseite „Titel““ oder leer, wenn die Option (noch) keine Produktseite hat. */
|
||||
private function productPageSuffix(): string
|
||||
{
|
||||
@@ -330,6 +505,16 @@ private function angebotDaten(): array
|
||||
'wire' => "mountAction('end')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
...($this->isOnDemand() ? [[
|
||||
'label' => 'Regel für den Abruf',
|
||||
'wire' => "mountAction('claimRule')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
...($this->isOnDemand() && $offer->claim_access === OfferAccess::RELEASED ? [[
|
||||
'label' => 'Konto freischalten',
|
||||
'wire' => "mountAction('release')",
|
||||
'art' => 'line',
|
||||
]] : []),
|
||||
...(ShopAccess::allowed() ? [[
|
||||
'label' => 'Zahlungen zu diesem Angebot',
|
||||
'href' => Zahlungsjournal::getUrl(['angebot' => $offer->id, 'zeitraum' => 'jahr', 'betrieb' => 'alle']),
|
||||
@@ -340,6 +525,7 @@ private function angebotDaten(): array
|
||||
'voraussetzungen' => app(PublicationReadiness::class)->forOffer($offer),
|
||||
'haupt' => [
|
||||
...($active !== null ? [$this->optionAbschnitt($offer, $active)] : []),
|
||||
...($this->isOnDemand() ? $this->abrufAbschnitte($offer) : []),
|
||||
[
|
||||
'titel' => 'Positionen',
|
||||
'zusatz' => $active !== null ? 'Fassung '.$active->number : null,
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Commerce\Cart;
|
||||
use App\Domain\Commerce\Checkout;
|
||||
use App\Domain\Commerce\LedgerEntry;
|
||||
@@ -12,9 +11,12 @@
|
||||
use App\Domain\Commerce\OrderHolders;
|
||||
use App\Domain\Commerce\SalesTerms;
|
||||
use App\Domain\Commerce\Shop;
|
||||
use App\Domain\Commerce\ShopCatalog;
|
||||
use App\Domain\Commerce\StaleOverview;
|
||||
use App\Domain\Commerce\Stripe\StripeGateway;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Domain\Entitlement\NewStands;
|
||||
use App\Domain\Entitlement\OfferAccess;
|
||||
use App\Domain\Identity\PartyType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -24,18 +26,21 @@
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Angebote für das Konto: was sich ohne Kauf in die Bibliothek übernehmen lässt (Vergabe „auf Abruf“ oder „bei
|
||||
* Registrierung“). Gekauft wird ausschließlich im Shop über Warenkorb oder „Jetzt kaufen“ und die Kasse.
|
||||
* Angebote für das Konto: was sich ohne Kauf in die Bibliothek übernehmen lässt (Regel des Angebots, ADR-56) und
|
||||
* neue Stände zu bereits besessenen Artikeln. Gekauft wird ausschließlich im Shop über Warenkorb oder „Jetzt kaufen“
|
||||
* und die Kasse.
|
||||
*/
|
||||
public function offers(): View
|
||||
public function offers(Request $request, OfferAccess $access, NewStands $stands): View
|
||||
{
|
||||
$offers = Offer::query()
|
||||
->whereHas('versions', fn ($query) => $query->where('status', OfferStatus::Aktiv)->where('holder_kind', 'person')->whereIn('grant_kind', ['auf_abruf', 'bei_registrierung']))
|
||||
->with(['versions' => fn ($query) => $query->where('status', OfferStatus::Aktiv)->orderByDesc('number')])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
$user = $request->user();
|
||||
$shop = Shop::visible();
|
||||
|
||||
return view('member.offers', ['offers' => $offers, 'shop' => Shop::visible()]);
|
||||
return view('member.offers', [
|
||||
'offers' => $access->claimable($user),
|
||||
'stands' => $stands->forUser($user),
|
||||
'shop' => $shop,
|
||||
'cards' => $shop ? app(ShopCatalog::class)->cards('', ['sort' => 'neu', 'limit' => 6]) : [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function claim(Request $request, Offer $offer, GrantIssuer $issuer): RedirectResponse
|
||||
|
||||
@@ -35,6 +35,12 @@ public function offers(): View|RedirectResponse
|
||||
return Shop::visible() ? redirect()->route('shop') : $this->show('angebote');
|
||||
}
|
||||
|
||||
/** Eine veröffentlichte CMS-Seite unter einer festen App-Adresse (der Shop unter /shop). */
|
||||
public function showPage(Page $page): View
|
||||
{
|
||||
return $this->render($page, preview: false);
|
||||
}
|
||||
|
||||
public function preview(PageRevision $revision): View
|
||||
{
|
||||
$page = $revision->page;
|
||||
@@ -60,7 +66,9 @@ public function devices(PageRevision $revision): View
|
||||
|
||||
public function sitemap(): Response
|
||||
{
|
||||
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get();
|
||||
// Der Shop gehört nicht in die Sitemap, solange man dort nicht kaufen kann (die Seiten sind dann noindex).
|
||||
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get()
|
||||
->reject(fn (Page $page): bool => $page->path === '/shop' && ! Shop::checkoutOpen());
|
||||
$themes = Pillar::query()->published()->get();
|
||||
|
||||
return response()
|
||||
|
||||
@@ -2,15 +2,19 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Commerce\Shop;
|
||||
use App\Domain\Commerce\ShopCatalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* Durchsuchbarer Shop: macht kaufbare Produkte auffindbar. Treffer öffnen dieselbe öffentliche Produktseite wie die
|
||||
* Programmkacheln. Gelistet wird nur, was mindestens eine kaufbare Option hat; die Kacheln bildet ShopCatalog.
|
||||
*
|
||||
* Gibt es in der Webpräsenz eine veröffentlichte Seite „shop“, bestimmt sie den Aufbau (Banner, Grafiken, Texte und das
|
||||
* Widget „Shop-Produkte“); sonst zeigt die Anwendung die Standardseite mit Suche und Kacheln (ADR-55).
|
||||
*/
|
||||
class ShopController extends Controller
|
||||
{
|
||||
@@ -23,8 +27,14 @@ public function closed(): View|RedirectResponse
|
||||
return Shop::checkoutOpen() ? redirect()->route('shop') : view('shop.closed');
|
||||
}
|
||||
|
||||
public function index(Request $request, ShopCatalog $catalog): View
|
||||
public function index(Request $request, ShopCatalog $catalog, PageController $pages): View
|
||||
{
|
||||
$page = Page::query()->where('path', '/shop')->whereNotNull('published_revision_id')->first();
|
||||
|
||||
if ($page !== null) {
|
||||
return $pages->showPage($page);
|
||||
}
|
||||
|
||||
$term = trim((string) $request->query('suche', ''));
|
||||
|
||||
return view('shop.index', ['cards' => $catalog->cards($term), 'term' => $term]);
|
||||
|
||||
Reference in new issue
Block a user