@extends('frontend::layouts.master') @php $assetPath = 'frontend_assets'; $langCode = session('lang_code', 'en'); $isRtl = ($direction ?? 'ltr') === 'rtl'; // Build currently selected category IDs array $activeCategoryIds = array_filter(array_map('intval', (array) request('categories', []))); if (request('category') && !$activeCategoryIds) { $activeCategoryIds = [(int) request('category')]; } $decimalPoints = $currentCountry->decimal_points ?? 0; $step = $decimalPoints > 0 ? '0.' . str_repeat('0', $decimalPoints - 1) . '1' : '1'; @endphp @section('content')
{{-- Mobile Filter Toggle Button --}}
{{-- ========================= DESKTOP FILTER SIDEBAR ========================= --}}
{{ webTrans('filtered_by', 'product_listing', 'Filtered By') }}
@if(request('sort')) @endif @if(request('q')) @endif {{-- CATEGORY (Multi-select) --}}
{{ webTrans('category', 'product_listing') }}
@foreach($categories as $category) @php $hasCategoryChildren = $category->children->count() > 0; $isCategoryActive = in_array($category->id, $activeCategoryIds); $isChildActive = $hasCategoryChildren && $category->children->pluck('id')->intersect($activeCategoryIds)->isNotEmpty(); @endphp
{{-- Hidden checkbox for the parent category --}}
{{-- Clicking this label: selects parent, marks red, opens children. REMOVED 'for' to avoid double-toggle --}} @if($hasCategoryChildren) @endif
@if($hasCategoryChildren)
@foreach($category->children as $child)
id, $activeCategoryIds) ? 'checked' : '' }}>
@endforeach
@endif
@endforeach
{{-- DYNAMIC ATTRIBUTES (size, colour, etc.) --}} @foreach($groupedAttributes as $attr) @php $isColor = in_array(strtolower($attr['name']), ['colour', 'color', 'لون']); $isSize = in_array(strtolower($attr['name']), ['size', 'مقاس']); $collapseId = 'attrCollapse-' . $attr['id']; $selectedVals = (array) request('attributes.' . $attr['id'], []); @endphp
{{ $attr['name'] }}
@if($isColor || $isSize)
@foreach($attr['values'] as $val) @if($isColor)
@else
@endif @endforeach
@else
@foreach($attr['values'] as $val)
@endforeach
@endif
@endforeach {{-- PRICE RANGE (submits on change after user finishes typing) --}}
{{ webTrans('price_range', 'product_listing') }}
{{-- APPLY & CLEAR FILTERS --}}
{{ webTrans('clear_filter', 'product_listing', 'Clear filter') }}
{{-- ========================= PRODUCT GRID ========================= --}}
@if($products->count() > 0)
@foreach($products as $product)
@include('frontend::home.sections._product_card', [ 'product' => $product, 'pageName' => 'product_listing', ])
@endforeach
{{-- PAGINATION --}}
{{-- Count label --}}
{{ webTrans('showing', 'product_listing', 'Showing') }}
{{ $products->count() }}
{{ webTrans('products_per_page', 'product_listing', 'Products per page') }} {{ webTrans('products', 'product_listing', 'Products') }}
{{-- Page links --}}
{{ $products->links('frontend::partials.pagination') }}
@else

{{ webTrans('no_products_found', 'product_listing', 'No products found matching your criteria') }}

@endif
{{-- ========================= MOBILE FILTER OFFCANVAS (Slides from Right) ========================= --}}
{{ webTrans('filters', 'product_listing', 'Filters') }}
{{-- Persist search and sort state --}} @if(request('q')) @endif @if(request('sort')) @endif
{{ webTrans('filtered_by', 'product_listing', 'Filtered By') }}
{{-- CATEGORIES --}}
{{ webTrans('category', 'product_listing') }}
@foreach($categories as $category) @php $hasChildren = $category->children->count() > 0; $isActive = in_array($category->id, $activeCategoryIds); $isChildActive = $hasChildren && $category->children->pluck('id')->intersect($activeCategoryIds)->isNotEmpty(); $collapseId = 'mob-cat-collapse-' . $category->id; @endphp
{{-- Hidden checkbox --}}
{{-- REMOVED 'for' to avoid double-toggle --}} @if($hasChildren) @endif
@if($hasChildren)
    @foreach($category->children as $child) @php $isChildChecked = in_array($child->id, $activeCategoryIds); @endphp
  • @endforeach
@endif
@endforeach
{{-- ATTRIBUTES --}} @foreach($groupedAttributes as $attr) @php $isColor = in_array(strtolower($attr['name']), ['colour', 'color', 'لون']); $isSize = in_array(strtolower($attr['name']), ['size', 'مقاس']); $collapseId = 'mob-attr-collapse-' . $attr['id']; $selectedVals = (array) request('attributes.' . $attr['id'], []); @endphp
{{ $attr['name'] }}
@foreach($attr['values'] as $val) @php $isChecked = in_array($val['id'], $selectedVals); @endphp @if($isSize)
@elseif($isColor)
@else
@endif @endforeach
@endforeach {{-- PRICE --}}
Price
{{-- ACTIONS --}}
{{ webTrans('clear_filter', 'product_listing', 'Clear filter') }}
@endsection