resetPage();
}
public function updatedStatusFilter(): void
{
$this->resetPage();
}
public function updatedCategoryFilter(): void
{
$this->resetPage();
}
public function updatedProductTypeFilter(): void
{
$this->resetPage();
}
public function archiveProduct(int $productId): void
{
$product = Product::findOrFail($productId);
$this->authorize('delete', $product);
$product->update(['status' => ProductStatus::Archived]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'archived',
'note' => null,
]);
session()->flash('message', __('Produkt ":name" wurde archiviert.', ['name' => $product->name]));
}
public function markAsSold(int $productId): void
{
$product = Product::findOrFail($productId);
$this->authorize('update', $product);
$product->update(['status' => ProductStatus::Sold]);
$product->activities()->create([
'user_id' => auth()->id(),
'action' => 'sold',
'note' => null,
]);
session()->flash('message', __('Produkt ":name" wurde als verkauft markiert.', ['name' => $product->name]));
}
public function with(): array
{
$user = Auth::user();
$isAdmin = $user->hasAnyRole(['Admin', 'Super-Admin']);
$isCustomer = $user->hasRole('Customer');
$query = Product::query()
->with(['brand', 'categories', 'partner', 'media'])
->when($this->search, fn($q) => $q->where('name', 'like', "%{$this->search}%"))
->when($this->statusFilter, fn($q) => $q->where('status', $this->statusFilter))
->when($this->categoryFilter, fn($q) => $q->whereHas('categories', fn($q) => $q->where('categories.id', $this->categoryFilter)))
->when($this->productTypeFilter, fn($q) => $q->where('product_type', $this->productTypeFilter));
if ($isAdmin) {
// Admin sieht alle Produkte
} elseif ($isCustomer) {
// Kunden sehen nur freigegebene, aktive Produkte aus ihrem Hub
$query->where('status', ProductStatus::Active)->where('is_curated', true)->where('is_available', true)->when($user->hub_id, fn($q) => $q->where('hub_id', $user->hub_id));
} else {
// Händler/Hersteller sehen nur eigene Produkte
$query->when($user->partner_id, fn($q) => $q->where('partner_id', $user->partner_id));
}
$products = $query->orderBy($this->sortBy, $this->sortDirection)->paginate(20);
$categories = Category::orderBy('name')->get();
return [
'products' => $products,
'categories' => $categories,
'isAdmin' => $isAdmin,
'isCustomer' => $isCustomer,
];
}
}; ?>
{{-- Header --}}
{{ __('Produkte') }}
{{ __('Produktübersicht und Local Feed') }}
@if (
!$isCustomer &&
auth()->user()->hasAnyRole(['Retailer', 'Manufacturer', 'Admin', 'Super-Admin']))
{{ __('Neues Teaser-Produkt') }}
{{ __('Neues Standard-Produkt') }}
@endif
@if (session()->has('message'))
{{ session('message') }}
@endif
{{-- Filter & Suche --}}
{{ __('Suche') }}
@if (!$isCustomer)
{{ __('Status') }}
{{ __('Alle Status') }}
{{ __('In Prüfung') }}
{{ __('Korrektur nötig') }}
{{ __('Freigegeben') }}
{{ __('Entwurf') }}
{{ __('Archiviert') }}
{{ __('Verkauft') }}
@endif
{{ __('Produkttyp') }}
{{ __('Alle Typen') }}
{{ __('Teaser (Local Express)') }}
{{ __('Standard (Smart Club)') }}
{{ __('Kategorie') }}
{{ __('Alle Kategorien') }}
@foreach ($categories as $category)
{{ $category->name }}
@endforeach
{{-- Produkttabelle --}}
{{ __('Produkt') }}
@if ($isAdmin)
{{ __('Händler') }}
@endif
@if ($isCustomer)
{{ __('Händler') }}
@else
{{ __('Kategorie') }}
@endif
{{ __('Preis') }}
{{ __('Status') }}
@if ($isAdmin)
{{ __('Kuration') }}
@endif
{{ __('Erstellt') }}
@forelse($products as $product)
{{-- Produkt --}}
@php
$thumbnail = $product->media->sortBy('order_column')->first();
@endphp
@if ($thumbnail)
 }})
@else
@endif
{{ $product->name }}
{{ $product->product_type?->label() ?? '–' }}
{{-- Händler (nur Admin) --}}
@if ($isAdmin)
{{ $product->partner?->company_name ?? '–' }}
@endif
{{-- Händler (Customer) oder Kategorie (Partner) --}}
@if ($isCustomer)
{{ $product->partner?->company_name ?? '–' }}
@else
{{ $product->categories->first()?->name ?? '–' }}
@endif
{{-- Preis --}}
@if ($product->price_type?->value === 'on_request')
{{ __('Auf Anfrage') }}
@elseif($product->price_display_text)
{{ $product->price_display_text }}
@elseif($product->price)
{{ number_format($product->price, 2, ',', '.') }} €
@else
–
@endif
{{-- Status --}}
{{ $product->status?->label() ?? '–' }}
{{-- Kuration (nur Admin) --}}
@if ($isAdmin)
@if ($product->is_curated)
{{ __('Freigegeben') }}
@else
{{ __('Ausstehend') }}
@endif
@endif
{{-- Erstellt --}}
{{ $product->created_at?->format('d.m.Y') }}
{{-- Aktionen --}}
@if (!$isCustomer)
@if (!in_array($product->status, [ProductStatus::Archived, ProductStatus::Sold]))
{{ __('Als verkauft') }}
{{ __('Archivieren') }}
@endif
@endif
@empty
{{ __('Keine Produkte gefunden') }}
@endforelse
@if ($products->hasPages())
{{ $products->links() }}
@endif