@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