{{-- resources/views/admin/clubs/_store.blade.php --}} {{-- Vista da loja (produtos com stock) --}}
Loja do Clube

@php $hasAnyStock = false; @endphp @foreach($categories as $category) @php $productsForClub = $category->products->filter(function ($p) use ($club, &$hasAnyStock) { // stock deste clube (0 se não existir registo) $stock = optional( $p->clubStocks->firstWhere('club_id', $club->id) )->stock ?? 0; // marcar se existe pelo menos um com stock > 0 (se ainda quiseres a tal mensagem) if ($stock > 0) { $hasAnyStock = true; } // regra: produto é visível se for geral (club_id NULL) ou exclusivo deste clube return $p->club_id === null || $p->club_id === $club->id; }); @endphp @php $productsForClub = $category->products->filter(function ($p) use ($club, &$hasAnyStock) { // stock deste clube (0 se não existir registo) $stock = optional( $p->clubStocks->firstWhere('club_id', $club->id) )->stock ?? 0; // marcar que há pelo menos um com stock > 0 (se ainda usares isto em baixo) if ($stock > 0) { $hasAnyStock = true; } // visível se for produto geral (club_id null) ou exclusivo deste clube return $p->club_id === null || $p->club_id === $club->id; }); @endphp @if($productsForClub->isNotEmpty())
{{ $category->name }}
@foreach($productsForClub as $product) @php $stock = optional( $product->clubStocks->firstWhere('club_id', $club->id) )->stock ?? 0; $isExclusive = ($product->club_id === $club->id); $mainImagePath = $product->image_url ?? optional($product->images->first())->path; $mainImageUrl = $mainImagePath ? asset('storage/' . ltrim($mainImagePath, '/')) : null; @endphp
@if($mainImageUrl) {{ $product->name }} @else
Sem imagem
@endif @if($isExclusive) Exclusivo deste clube @endif
{{ $product->name }}
Ref: {{ $product->sku ?? '—' }}
€ {{ number_format($product->price, 2, ',', ' ') }}
Stock: {{ $stock }}
@endforeach
@endif @endforeach @if(! $hasAnyStock)

Ainda não existe stock definido para este clube. Usa a grelha abaixo para atribuir stock.

@endif {{-- Gestão de stock por produto – mantém aqui a tua grelha existente --}}
{{-- ... formulário de stock que já tinhas ... --}}