@php /** @var \App\Models\Product $p */ $productSlug = $p->slug ?? (string) $p->id; $galleryFilenames = $p->productGalleryFilenames(); $galleryUrls = collect($galleryFilenames) ->map(fn ($f) => $f ? asset('images/products/' . $f) : null) ->filter() ->values() ->all(); $primaryFile = $p->primaryProductImageFilename(); $imgUrl = $primaryFile ? asset('images/products/' . $primaryFile) : asset('images/products/no-image.png'); $descShort = \Illuminate\Support\Str::limit(strip_tags($p->note ?? ''), 600); $minPrice = (float) ($p->display_price ?? ($p->price ?? 0)); $variants = $p->relationLoaded('variants') ? $p->variants : collect($p->variants ?? []); $variants = collect($variants); $variantPayload = $variants->map(function($v) use ($currency) { $final = (float) ($v->display_price ?? ($v->price ?? 0)); return [ 'id' => (int) ($v->id ?? 0), 'name' => (string) ($v->name ?? ''), 'price' => (float) ($v->price ?? 0), 'display_price' => $final, 'display_price_formatted' => $currency . number_format($final, 2, '.', ','), 'image' => !empty($v->image) ? asset('images/products/' . $v->image) : null, 'stock' => (int) max(0, $v->stock ?? $v->qty ?? 0), ]; })->values(); $productStock = $variants->isEmpty() ? (int) max(0, $p->stock ?? 0) : null; $isPreorder = (bool) ($p->is_preorder ?? false); $preorderDate = $p->preorder_available_date ? $p->preorder_available_date->format('M d, Y') : null; $allowOverselling = isset($s) ? (bool) ($s->allow_overselling ?? true) : true; $hidePrices = !Auth::guard('store')->check() && isset($s) && ($s->hide_prices_for_guests ?? false); $isPreorderActive = false; if ($isPreorder) { $outOfStock = $variants->isEmpty() ? ($productStock !== null && $productStock <= 0) : !$variantPayload->contains(fn($v) => ($v['stock'] ?? 0) > 0); if ($outOfStock) { $isPreorderActive = true; } } if ($isPreorderActive) { $isAvailable = true; $availabilityLabel = $preorderDate ? __('messages.PreorderAvailableOn', ['date' => $preorderDate]) : __('messages.PreorderAvailable'); $stockDotClass = 'stock-dot-warn'; } elseif ($allowOverselling) { $isAvailable = true; $availabilityLabel = null; $stockDotClass = 'stock-dot-ok'; } else { if ($variants->isEmpty()) { $isAvailable = $productStock !== null && $productStock > 0; $availabilityLabel = $productStock !== null ? ($productStock > 0 ? __('messages.X_in_stock', ['count' => $productStock]) : __('messages.OutOfStock')) : null; } else { $isAvailable = $variantPayload->contains(fn($v) => ($v['stock'] ?? 0) > 0); $availabilityLabel = $isAvailable ? __('messages.InStock') : __('messages.OutOfStock'); } $stockDotClass = $isAvailable ? 'stock-dot-ok' : 'stock-dot-out'; } @endphp
{{ $p->name }} @if($isPreorderActive) {{ __('messages.PreOrder') }} @elseif(!$isAvailable) {{ __('messages.OutOfStock') }} @endif

{{ $p->name }}

@if(empty($hidePrices))
{{ $currency }}{{ number_format($minPrice, 2, '.', ',') }}
@endif @if($availabilityLabel !== null && ($s->show_stock ?? true))
{{ $availabilityLabel }}
@endif @if(empty($hidePrices)) @endif