@php $source = (string) ($s['source'] ?? 'featured'); $limit = max(1, (int) ($s['limit'] ?? 8)); $categoryId = (int) ($s['category_id'] ?? 0); $query = \App\Models\Product::query()->active()->with('category'); match ($source) { 'latest' => $query->latest(), 'sale' => $query->onSale()->orderBy('sort_order'), 'category' => $query->where('category_id', $categoryId)->orderBy('sort_order'), default => $query->featured()->orderBy('sort_order'), }; $products = $query->limit($limit)->get(); $style = $s['style'] ?? 'cream'; $sectionClass = match ($style) { 'sand' => 'section bg-sand', 'white' => 'section bg-white', 'dark' => 'section bg-ink', default => 'section', }; // Card appearance chosen in the editor. Values are clamped so blocks saved // by an older release keep rendering like before. $columns = max(2, min(5, (int) ($s['columns'] ?? 4))); $shape = ($s['image_shape'] ?? 'square') === 'circle' ? 'circle' : 'square'; $radius = max(0, min(80, (int) ($s['image_radius'] ?? 0))); $ratio = (string) ($s['image_ratio'] ?? '1/1'); $ratio = in_array($ratio, ['1/1', '4/3', '3/4', '16/10'], true) ? $ratio : '1/1'; $fit = ($s['image_fit'] ?? 'cover') === 'contain' ? 'contain' : 'cover'; $titleSize = max(10, min(28, (int) ($s['title_size'] ?? 15))); $weight = (string) ($s['title_weight'] ?? '600'); $weight = in_array($weight, ['400', '500', '600', '700', '800'], true) ? $weight : '600'; $fontFamily = trim((string) ($s['title_font'] ?? '')); $font = $fontFamily !== '' ? \App\Models\Font::query()->active()->where('family', $fontFamily)->first() : null; $fontStack = $font ? "'".str_replace("'", '', $font->family)."', var(--font)" : 'inherit'; $gridClass = 'product-grid cols-'.$columns.($shape === 'circle' ? ' pgrid-circle' : ''); $gridVars = implode('; ', [ '--pcard-img-radius: '.$radius.'px', '--pcard-ratio: '.$ratio, '--pcard-fit: '.$fit, '--pcard-title-size: '.$titleSize.'px', '--pcard-title-weight: '.$weight, '--pcard-title-font: '.$fontStack, ]); @endphp @include('pages.blocks.partials.font', ['font' => $font]) @if ($products->isNotEmpty())
@include('pages.blocks.partials.head', [ 'eyebrow' => $block->text('eyebrow'), 'title' => $block->text('title'), 'linkLabel' => $block->text('link_label'), 'linkUrl' => (string) ($s['link_url'] ?? ''), ])
@foreach ($products as $product) @include('partials.product-card', ['product' => $product]) @endforeach
@endif