@props(['availableFilters', 'context' => []]) @php $currentQuery = request()->query(); // Aktif filtre chip'lerini toplama $chips = []; // Kategori chip (Arama sayfasındaysak) if (request()->filled('category') && empty($context['category_slug'])) { $cat = \App\Models\Category::where('slug', request('category'))->first(); if ($cat) { $tempQuery = $currentQuery; unset($tempQuery['category']); unset($tempQuery['page']); $chips[] = [ 'label' => 'Kategori: ' . $cat->name, 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } // Marka chip (Marka sayfasında değilsek) if (request()->filled('brand') && empty($context['brand_slug'])) { $brand = \App\Models\Brand::where('slug', request('brand'))->first(); if ($brand) { $tempQuery = $currentQuery; unset($tempQuery['brand']); unset($tempQuery['page']); $chips[] = [ 'label' => 'Marka: ' . $brand->name, 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } // Fiyat chip'leri if (request()->filled('min_price')) { $tempQuery = $currentQuery; unset($tempQuery['min_price']); unset($tempQuery['page']); $chips[] = [ 'label' => 'Min: ' . number_format((float)request('min_price'), 0, ',', '.') . ' TL', 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } if (request()->filled('max_price')) { $tempQuery = $currentQuery; unset($tempQuery['max_price']); unset($tempQuery['page']); $chips[] = [ 'label' => 'Max: ' . number_format((float)request('max_price'), 0, ',', '.') . ' TL', 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } // Stok durumu chip if (request('stock') === 'in_stock') { $tempQuery = $currentQuery; unset($tempQuery['stock']); unset($tempQuery['page']); $chips[] = [ 'label' => 'Sadece Stoktakiler', 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } elseif (request('stock') === 'out_of_stock') { $tempQuery = $currentQuery; unset($tempQuery['stock']); unset($tempQuery['page']); $chips[] = [ 'label' => 'Tükenen Ürünler', 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } // İndirim chip if (request('discounted') == '1') { $tempQuery = $currentQuery; unset($tempQuery['discounted']); unset($tempQuery['page']); $chips[] = [ 'label' => 'İndirimli Ürünler', 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } // Puan chip if (request()->filled('rating')) { $tempQuery = $currentQuery; unset($tempQuery['rating']); unset($tempQuery['page']); $chips[] = [ 'label' => request('rating') . '+ Yıldız', 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } // Varyant chip'leri if (request()->filled('options') && is_array(request('options'))) { foreach (request('options') as $group => $vals) { foreach ($vals as $val) { $tempQuery = $currentQuery; $idx = array_search($val, $tempQuery['options'][$group]); if ($idx !== false) { unset($tempQuery['options'][$group][$idx]); if (empty($tempQuery['options'][$group])) { unset($tempQuery['options'][$group]); } } if (empty($tempQuery['options'])) { unset($tempQuery['options']); } unset($tempQuery['page']); $chips[] = [ 'label' => $group . ': ' . $val, 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } } // option_ parametreleri foreach ($currentQuery as $key => $val) { if (str_starts_with($key, 'option_')) { $groupName = substr($key, 7); $vals = is_array($val) ? $val : [$val]; foreach ($vals as $v) { $tempQuery = $currentQuery; if (is_array($tempQuery[$key])) { $idx = array_search($v, $tempQuery[$key]); if ($idx !== false) { unset($tempQuery[$key][$idx]); } if (empty($tempQuery[$key])) { unset($tempQuery[$key]); } } else { unset($tempQuery[$key]); } unset($tempQuery['page']); $chips[] = [ 'label' => $groupName . ': ' . $v, 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } } // Teknik Özellik (Attribute) chip'leri $availableAttributes = $availableFilters['attributes'] ?? collect(); foreach ($currentQuery as $key => $val) { if (str_starts_with($key, 'attr_')) { $parts = explode('_', $key); if (count($parts) < 2) continue; $attrId = (int)$parts[1]; $suffix = $parts[2] ?? null; // Özelliği bulalım $attr = $availableAttributes->firstWhere('id', $attrId); if (!$attr) { // Fallback olarak veritabanından çekelim $attr = \App\Models\ProductAttribute::active()->where('is_filterable', true)->find($attrId); if (!$attr) continue; } if ($suffix === 'min') { if ($val !== null && $val !== '') { $tempQuery = $currentQuery; unset($tempQuery[$key]); unset($tempQuery['page']); $chips[] = [ 'label' => $attr->name . ' Min: ' . $val . ($attr->unit ? ' ' . $attr->unit : ''), 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } elseif ($suffix === 'max') { if ($val !== null && $val !== '') { $tempQuery = $currentQuery; unset($tempQuery[$key]); unset($tempQuery['page']); $chips[] = [ 'label' => $attr->name . ' Max: ' . $val . ($attr->unit ? ' ' . $attr->unit : ''), 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } else { $vals = is_array($val) ? $val : [$val]; foreach ($vals as $v) { if ($v === null || $v === '') continue; $tempQuery = $currentQuery; if (is_array($tempQuery[$key])) { $idx = array_search($v, $tempQuery[$key]); if ($idx !== false) { unset($tempQuery[$key][$idx]); } if (empty($tempQuery[$key])) { unset($tempQuery[$key]); } } else { unset($tempQuery[$key]); } unset($tempQuery['page']); $labelVal = $v; if ($attr->type === 'boolean') { $labelVal = filter_var($v, FILTER_VALIDATE_BOOLEAN) ? 'Evet' : 'Hayır'; } elseif ($attr->unit) { $labelVal = $v . ' ' . $attr->unit; } $chips[] = [ 'label' => $attr->name . ': ' . $labelVal, 'url' => request()->url() . '?' . http_build_query($tempQuery) ]; } } } } @endphp
{{-- Aktif Filtre Chip'leri --}} @if(count($chips) > 0)

Aktif Filtreler

@foreach($chips as $chip) {{ $chip['label'] }} @endforeach Tümünü Temizle
@endif
{{-- Arama parametresini koru --}} @if(request()->filled('q')) @endif {{-- Sıralama parametresini koru --}} {{-- Kategori Filtresi --}} @if($availableFilters['categories']->isNotEmpty())

{{ empty($context['category_slug']) ? 'Kategoriler' : 'Alt Kategoriler' }}

@foreach($availableFilters['categories'] as $cat) @if(empty($context['category_slug'])) @else {{ $cat->name }} @endif @endforeach
@endif {{-- Marka Filtresi --}} @if($availableFilters['brands']->isNotEmpty())

Markalar

@foreach($availableFilters['brands'] as $brand) @endforeach
@endif {{-- Fiyat Aralığı Filtresi --}} @if($availableFilters['price_bounds']['max'] > $availableFilters['price_bounds']['min'])

Fiyat Aralığı

-
@endif {{-- Stok Durumu --}}

Stok Durumu

{{-- İndirimli Ürünler --}}

Fırsatlar

{{-- Değerlendirme Puanı --}} @if($availableFilters['has_reviews'])

Müşteri Puanı

@foreach([4, 3, 2, 1] as $stars) @endforeach
@endif {{-- Varyant Seçenekleri --}} @if(!empty($availableFilters['options'])) @foreach($availableFilters['options'] as $groupName => $values)

{{ $groupName }}

@foreach($values as $val) @php $isChecked = false; if (request()->filled("options.{$groupName}") && is_array(request("options.{$groupName}"))) { $isChecked = in_array($val, request("options.{$groupName}")); } elseif (request()->filled("option_" . $groupName)) { $optionVal = request("option_" . $groupName); $isChecked = is_array($optionVal) ? in_array($val, $optionVal) : ($optionVal === $val); } @endphp @endforeach
@endforeach @endif {{-- Teknik Özellik (Attribute) Filtreleri --}} @if(!empty($availableFilters['attributes'])) @foreach($availableFilters['attributes'] as $attr) @if(!empty($attr->values_options))

{{ $attr->name }}

@if($attr->type === 'number') {{-- Number tipi range inputs --}}
-
@elseif($attr->type === 'boolean') {{-- Boolean Evet / Hayır seçenekleri --}}
@php $paramName = "attr_" . $attr->id; $isCheckedEvet = false; $isCheckedHayir = false; if (request()->filled($paramName)) { $reqVal = request($paramName); $reqValArray = is_array($reqVal) ? $reqVal : [$reqVal]; $isCheckedEvet = in_array('1', $reqValArray) || in_array('true', $reqValArray); $isCheckedHayir = in_array('0', $reqValArray) || in_array('false', $reqValArray); } @endphp
@else {{-- Text ve Select için checkbox listesi --}}
@foreach($attr->values_options as $val) @php $paramName = "attr_" . $attr->id; $isChecked = false; if (request()->filled($paramName)) { $reqVal = request($paramName); $isChecked = is_array($reqVal) ? in_array($val, $reqVal) : ($reqVal == $val); } @endphp @endforeach
@endif
@endif @endforeach @endif {{-- Filtreleri Temizleme --}}
Temizle