Files
laraundfelix/app/Domain/Cms/NavigationItem.php
LarsandClaude Sonnet 5.5 3d76062097
CI Feature / test (push) Successful in 3m23s
Deploy Test / test (push) Successful in 3m22s
Deploy Test / deploy (push) Successful in 30s
Trenne Shop sichtbar und Checkout offen und kaufe nur noch ueber die Kasse
- Zwei Schalter: Shop::visible (SHOP_PUBLIC) und Shop::checkoutOpen; ist der Shop nur sichtbar,
  fuehren Warenkorb, Kasse und Jetzt kaufen auf eine Hinweisseite (noindex), ohne Warenkorb und Bestellung
- Einzelkauf (Checkout::place, Route member.offers.buy) entfernt; Bestellung nur aus dem Warenkorb
- Jetzt kaufen an der Produktseite oeffnet die Bestellübersicht, Bereits erworben auf der Produktseite
- Menuepunkte in den Shop nur bei sichtbarem Shop, /angebote leitet auf /shop, Seeder fuehrt Shop
- Mitgliederseite Angebote zeigt nur kostenlose Angebote zum Uebernehmen
- Middleware EnsureCheckoutOpen laeuft vor der Anmeldepruefung
- Plan und ADR-53, DEPLOYMENT.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-26 07:17:25 +01:00

139 lines
3.7 KiB
PHP

<?php
namespace App\Domain\Cms;
use App\Domain\Cms\Widgets\Support\SafeUrl;
use App\Domain\Commerce\Shop;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class NavigationItem extends Model
{
/**
* Plätze im globalen Website-Gerüst. Die drei Fußbereichsgruppen ersetzen eine eigene Footer-Verwaltung.
*/
public const PLACEMENTS = [
'header' => 'Kopfzeile (Hauptnavigation)',
'footer' => 'Fußbereich: Service',
'footer_contact' => 'Fußbereich: Kontakt',
'footer_legal' => 'Fußbereich: Rechtliches',
];
/** Spaltenüberschriften im Fußbereich. */
public const FOOTER_GROUPS = [
'footer' => 'Service',
'footer_contact' => 'Kontakt',
'footer_legal' => 'Rechtliches',
];
protected $fillable = [
'label',
'page_id',
'url',
'placement',
'sort_order',
'is_visible',
'parent_id',
];
protected static function booted(): void
{
// Untermenüs gibt es nur in der Hauptnavigation.
static::saving(function (NavigationItem $item): void {
if ($item->placement !== 'header' && $item->getAttribute('parent_id') !== null) {
$item->parent_id = null;
}
});
}
protected function casts(): array
{
return [
'is_visible' => 'boolean',
];
}
public function page(): BelongsTo
{
return $this->belongsTo(Page::class);
}
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order')->orderBy('id');
}
/**
* @param Builder<NavigationItem> $query
*/
public function scopeVisible(Builder $query): void
{
$query->where('is_visible', true);
}
public function href(): ?string
{
// Ein Menüpunkt in den Shop erscheint nicht, solange der Shop nicht sichtbar ist: Er führte ins Leere (404).
if ($this->pointsIntoShop() && ! Shop::visible()) {
return null;
}
if ($this->page !== null) {
return $this->page->path === '/' ? url('/') : url($this->page->path);
}
if ($this->url === null || $this->url === '' || ! SafeUrl::isSafe($this->url)) {
return null;
}
if (str_starts_with($this->url, '/')) {
return url($this->url);
}
return $this->url;
}
/** Ziel ist der Shop selbst oder eine seiner Seiten: Übersicht, Produktseiten, Hinweisseite, Warenkorb, Kasse. */
private function pointsIntoShop(): bool
{
$path = $this->targetPath();
if ($path === null) {
return false;
}
foreach (['/shop', '/warenkorb', '/kasse', '/kauf-noch-nicht-moeglich'] as $prefix) {
if ($path === $prefix || str_starts_with($path, $prefix.'/')) {
return true;
}
}
return false;
}
/**
* Pfad des Ziels innerhalb der Website (für die Kennzeichnung des aktiven Eintrags); null bei externen Zielen.
*/
public function targetPath(): ?string
{
if ($this->page !== null) {
return $this->page->path;
}
if (is_string($this->url) && str_starts_with($this->url, '/') && ! str_starts_with($this->url, '//')) {
$path = parse_url($this->url, PHP_URL_PATH);
return is_string($path) ? '/'.trim($path, '/') : null;
}
return null;
}
}