ECOMMERCE/resources/views/shop/catalog-fashion.blade.php

859 lines
54 KiB
PHP

@extends('layouts.landing', ['title' => 'Fashion Store - Catalog'])
@section('content')
<x-layout.header />
<main class="content-wrapper">
<!-- Breadcrumb -->
<nav class="container pt-2 pt-xxl-3 my-3 my-md-4" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ route('second', ['home', 'fashion-v1']) }}">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Catalog with sidebar filters</li>
</ol>
</nav>
<!-- Page title -->
<h1 class="h3 container pb-3 pb-lg-4">Shop catalog</h1>
<!-- Products grid + Sidebar with filters -->
<section class="container">
<div class="row">
<!-- Filter sidebar that turns into offcanvas on screens < 992px wide (lg breakpoint) -->
<aside class="col-lg-3">
<div class="offcanvas-lg offcanvas-start pe-lg-4" id="filterSidebar">
<div class="offcanvas-header py-3">
<h5 class="offcanvas-title">Filter products</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas"
data-bs-target="#filterSidebar" aria-label="Close"></button>
</div>
<div class="offcanvas-body flex-column pt-2 py-lg-0 filter-sidebar">
<div class="accordion">
<!-- Genders -->
<div class="accordion-item border-0 pb-1 pb-xl-2">
<h4 class="accordion-header" id="headingGenders">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#genders" aria-expanded="true"
aria-controls="genders">
{{ __('catalog_fashion.genders') }}
</button>
</h4>
<div class="accordion-collapse collapse show" id="genders"
aria-labelledby="headingGenders">
<div class="accordion-body p-0 pb-4 mb-1 mb-xl-2">
<div style="height: 220px" data-simplebar data-simplebar-auto-hide="false">
<ul class="nav flex-column gap-2 pe-3" id="genders-list">
<!-- Genders will be loaded here via AJAX -->
</ul>
</div>
</div>
</div>
</div>
<!-- Categories -->
<div class="accordion-item border-0 pb-1 pb-xl-2">
<h4 class="accordion-header" id="headingCategories">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#categories" aria-expanded="true"
aria-controls="categories">
{{ __('catalog_fashion.categories') }}
</button>
</h4>
<div class="accordion-collapse collapse show" id="categories"
aria-labelledby="headingCategories">
<div class="accordion-body p-0 pb-4 mb-1 mb-xl-2">
<div style="height: 220px" data-simplebar data-simplebar-auto-hide="false">
<ul class="nav flex-column gap-2 pe-3" id="categories-list">
<!-- Categories will be loaded here via AJAX -->
</ul>
</div>
</div>
</div>
</div>
<!-- Price -->
<div class="accordion-item border-0 pb-1 pb-xl-2">
<h4 class="accordion-header" id="headingPrice">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#price" aria-expanded="true"
aria-controls="price">
Price
</button>
</h4>
<div class="accordion-collapse collapse show" id="price"
aria-labelledby="headingPrice">
<div class="accordion-body p-0 pb-4 mb-1 mb-xl-2">
<div class="range-slider"
data-range-slider='{"startMin": 0, "startMax": {{ $min_max_price['max'] }}, "min": 0, "max": {{ $min_max_price['max'] }}, "step": 1000000, "tooltipPrefix": "Rp"}'
aria-labelledby="headingPrice">
<div class="range-slider-ui"></div>
<div class="d-flex align-items-center">
<div class="position-relative w-50">
<input type="number" class="form-control"
min="0" data-range-slider-min>
</div>
<i class="ci-minus text-body-emphasis mx-2"></i>
<div class="position-relative w-50">
<input type="number" class="form-control"
min="0" data-range-slider-max>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Brands -->
{{-- <div class="accordion-item border-0 pb-1 pb-xl-2">
<h4 class="accordion-header" id="headingBrands">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#brands" aria-expanded="true"
aria-controls="brands">
Brands
</button>
</h4>
<div class="accordion-collapse collapse show" id="brands"
aria-labelledby="headingBrands">
<div class="accordion-body p-0 pb-4 mb-1 mb-xl-2"
data-filter-list='{"searchClass": "brands-search", "listClass": "brands-list", "valueNames": ["form-check-label"]}'>
<div class="position-relative mb-3">
<i
class="ci-search position-absolute top-50 start-0 translate-middle-y ms-3"></i>
<input type="search" class="brands-search form-control form-icon-start"
placeholder="Search">
</div>
<div style="height: 210px" data-simplebar data-simplebar-auto-hide="false">
<div class="brands-list d-flex flex-column gap-2">
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="adidas"
checked>
<label for="adidas" class="form-check-label text-body-emphasis">
Adidas<span class="fs-xs text-body-secondary ms-1">(425)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="taylor">
<label for="taylor" class="form-check-label text-body-emphasis">
Ann Taylor<span
class="fs-xs text-body-secondary ms-1">(15)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="armani">
<label for="armani" class="form-check-label text-body-emphasis">
Armani<span class="fs-xs text-body-secondary ms-1">(18)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="banana">
<label for="banana" class="form-check-label text-body-emphasis">
Banana Republic<span
class="fs-xs text-body-secondary ms-1">(103)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="bilabong"
checked>
<label for="bilabong" class="form-check-label text-body-emphasis">
Bilabong<span
class="fs-xs text-body-secondary ms-1">(27)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="birkenstock">
<label for="birkenstock"
class="form-check-label text-body-emphasis">
Birkenstock<span
class="fs-xs text-body-secondary ms-1">(10)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="klein">
<label for="klein" class="form-check-label text-body-emphasis">
Calvin Klein<span
class="fs-xs text-body-secondary ms-1">(365)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="columbia">
<label for="columbia" class="form-check-label text-body-emphasis">
Columbia<span
class="fs-xs text-body-secondary ms-1">(508)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="converse">
<label for="converse" class="form-check-label text-body-emphasis">
Converse<span
class="fs-xs text-body-secondary ms-1">(176)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="dockers">
<label for="dockers" class="form-check-label text-body-emphasis">
Dockers<span class="fs-xs text-body-secondary ms-1">(54)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="fruit">
<label for="fruit" class="form-check-label text-body-emphasis">
Fruit of the Loom<span
class="fs-xs text-body-secondary ms-1">(739)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="hanes">
<label for="hanes" class="form-check-label text-body-emphasis">
Hanes<span class="fs-xs text-body-secondary ms-1">(92)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="choo">
<label for="choo" class="form-check-label text-body-emphasis">
Jimmy Choo<span
class="fs-xs text-body-secondary ms-1">(17)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="levis">
<label for="levis" class="form-check-label text-body-emphasis">
Levi's<span class="fs-xs text-body-secondary ms-1">(361)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="wearhouse">
<label for="wearhouse"
class="form-check-label text-body-emphasis">
Men's Wearhouse<span
class="fs-xs text-body-secondary ms-1">(75)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="newbalance">
<label for="newbalance"
class="form-check-label text-body-emphasis">
New Balance<span
class="fs-xs text-body-secondary ms-1">(218)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="nike">
<label for="nike" class="form-check-label text-body-emphasis">
Nike<span class="fs-xs text-body-secondary ms-1">(810)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="navy">
<label for="navy" class="form-check-label text-body-emphasis">
Old Navy<span
class="fs-xs text-body-secondary ms-1">(147)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="puma">
<label for="puma" class="form-check-label text-body-emphasis">
Puma<span class="fs-xs text-body-secondary ms-1">(370)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="skechers">
<label for="skechers" class="form-check-label text-body-emphasis">
Skechers<span
class="fs-xs text-body-secondary ms-1">(209)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="hilfiger">
<label for="hilfiger" class="form-check-label text-body-emphasis">
Tommy Hilfiger<span
class="fs-xs text-body-secondary ms-1">(487)</span>
</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="armour">
<label for="armour" class="form-check-label text-body-emphasis">
Under Armour<span
class="fs-xs text-body-secondary ms-1">(90)</span>
</label>
</div>
</div>
</div>
</div>
</div>
</div> --}}
<!-- Size -->
{{-- <div class="accordion-item border-0 pb-1 pb-xl-2">
<h4 class="accordion-header" id="headingSize">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#size" aria-expanded="true"
aria-controls="size">
Size
</button>
</h4>
<div class="accordion-collapse collapse show" id="size"
aria-labelledby="headingSize">
<div class="accordion-body p-0 pb-4 mb-1 mb-xl-2">
<div class="d-flex flex-wrap gap-2">
<input type="checkbox" class="btn-check" id="size-xxs" checked>
<label for="size-xxs" class="btn btn-sm btn-outline-secondary">XXS</label>
<input type="checkbox" class="btn-check" id="size-xs">
<label for="size-xs" class="btn btn-sm btn-outline-secondary">XS</label>
<input type="checkbox" class="btn-check" id="size-s">
<label for="size-s" class="btn btn-sm btn-outline-secondary">S</label>
<input type="checkbox" class="btn-check" id="size-m">
<label for="size-m" class="btn btn-sm btn-outline-secondary">M</label>
<input type="checkbox" class="btn-check" id="size-l">
<label for="size-l" class="btn btn-sm btn-outline-secondary">L</label>
<input type="checkbox" class="btn-check" id="size-xl">
<label for="size-xl" class="btn btn-sm btn-outline-secondary"><span
class="mx-n1">XL</span></label>
<input type="checkbox" class="btn-check" id="size-2xl">
<label for="size-2xl" class="btn btn-sm btn-outline-secondary">2XL</label>
<input type="checkbox" class="btn-check" id="size-40">
<label for="size-40" class="btn btn-sm btn-outline-secondary">40</label>
<input type="checkbox" class="btn-check" id="size-42">
<label for="size-42" class="btn btn-sm btn-outline-secondary">42</label>
<input type="checkbox" class="btn-check" id="size-44">
<label for="size-44" class="btn btn-sm btn-outline-secondary">44</label>
<input type="checkbox" class="btn-check" id="size-45">
<label for="size-45" class="btn btn-sm btn-outline-secondary">45</label>
<input type="checkbox" class="btn-check" id="size-46">
<label for="size-46" class="btn btn-sm btn-outline-secondary">46</label>
<input type="checkbox" class="btn-check" id="size-48">
<label for="size-48" class="btn btn-sm btn-outline-secondary">48</label>
<input type="checkbox" class="btn-check" id="size-50">
<label for="size-50" class="btn btn-sm btn-outline-secondary">50</label>
<input type="checkbox" class="btn-check" id="size-52">
<label for="size-52" class="btn btn-sm btn-outline-secondary">52</label>
</div>
</div>
</div>
</div> --}}
<!-- Color -->
{{-- <div class="accordion-item border-0 pb-1 pb-xl-2">
<h4 class="accordion-header" id="headingColor">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#color" aria-expanded="true"
aria-controls="color">
Color
</button>
</h4>
<div class="accordion-collapse collapse show" id="color"
aria-labelledby="headingColor">
<div class="accordion-body p-0 pb-4 mb-1 mb-xl-2">
<div class="d-flex flex-column gap-2">
<div class="d-flex align-items-center mb-1">
<input type="checkbox" class="btn-check" id="green">
<label for="green" class="btn btn-color fs-xl"
style="color: #8bc4ab"></label>
<label for="green" class="fs-sm ms-2">Green</label>
</div>
<div class="d-flex align-items-center mb-1">
<input type="checkbox" class="btn-check" id="red">
<label for="red" class="btn btn-color fs-xl"
style="color: #ee7976"></label>
<label for="red" class="fs-sm ms-2">Coral red</label>
</div>
<div class="d-flex align-items-center mb-1">
<input type="checkbox" class="btn-check" id="pink">
<label for="pink" class="btn btn-color fs-xl"
style="color: #df8fbf"></label>
<label for="pink" class="fs-sm ms-2">Pink</label>
</div>
<div class="d-flex align-items-center mb-1">
<input type="checkbox" class="btn-check" id="blue">
<label for="blue" class="btn btn-color fs-xl"
style="color: #9acbf1"></label>
<label for="blue" class="fs-sm ms-2">Sky blue</label>
</div>
<div class="d-flex align-items-center mb-1">
<input type="checkbox" class="btn-check" id="black">
<label for="black" class="btn btn-color fs-xl"
style="color: #364254"></label>
<label for="black" class="fs-sm ms-2">Black</label>
</div>
<div class="d-flex align-items-center mb-1">
<input type="checkbox" class="btn-check" id="white">
<label for="white" class="btn btn-color fs-xl"
style="color: #e0e5eb"></label>
<label for="white" class="fs-sm ms-2">White</label>
</div>
</div>
</div>
</div>
</div> --}}
<!-- Status -->
<div class="accordion-item border-0">
<h4 class="accordion-header" id="headingStatus">
<button type="button" class="accordion-button p-0 pb-3"
data-bs-toggle="collapse" data-bs-target="#status" aria-expanded="true"
aria-controls="status">
Status
</button>
</h4>
<div class="accordion-collapse collapse show" id="status"
aria-labelledby="headingStatus">
<div class="accordion-body p-0 pb-2 pb-lg-0">
<div class="d-flex flex-column gap-2">
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="instock">
<label for="instock" class="form-check-label text-body-emphasis">In
stock</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="sale"
checked>
<label for="sale" class="form-check-label text-body-emphasis">%
Sale</label>
</div>
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="delivery">
<label for="delivery" class="form-check-label text-body-emphasis">Free
delivery</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</aside>
<!-- Product grid -->
<div class="col-lg-9">
<!-- Sorting -->
<div class="d-sm-flex align-items-center justify-content-between mt-n2 mb-3 mb-sm-4">
<div class="fs-sm text-body-emphasis text-nowrap">Found <span class="fw-semibold" id="product-count">Loading...</span>
items
</div>
<div class="d-flex align-items-center text-nowrap">
<label class="form-label fw-semibold mb-0 me-2">{{ __('catalog_fashion.sort_by') }}:</label>
<div style="width: 190px">
<select class="form-select border-0 rounded-0 px-1"
data-select='{
"removeItemButton": false,
"classNames": {
"containerInner": ["form-select", "border-0", "rounded-0", "px-1"]
}
}'
onchange="window.location.href='{{ route('product.index') }}?sort_by='+this.value+'&{{ http_build_query(request()->except('sort_by')) }}'">
<option value="relevance" {{ request('sort_by') == 'relevance' ? 'selected' : '' }}>{{ __('catalog_fashion.sort_relevance') }}</option>
<option value="popularity" {{ request('sort_by') == 'popularity' ? 'selected' : '' }}>{{ __('catalog_fashion.sort_popularity') }}</option>
<option value="price_low_to_high" {{ request('sort_by') == 'price_low_to_high' ? 'selected' : '' }}>{{ __('catalog_fashion.sort_price_low_to_high') }}</option>
<option value="price_high_to_low" {{ request('sort_by') == 'price_high_to_low' ? 'selected' : '' }}>{{ __('catalog_fashion.sort_price_high_to_low') }}</option>
<option value="new" {{ request('sort_by') == 'newest_arrivals' ? 'selected' : '' }}>{{ __('catalog_fashion.sort_newest_arrivals') }}</option>
</select>
</div>
</div>
</div>
<div class="row gy-4 gy-md-5 pb-4 pb-md-5" id="products-container">
<!-- Products will be loaded here via AJAX -->
</div>
{{-- <div class="col-12 col-md-8 mb-2 mb-sm-3 mb-md-0">
<div
class="position-relative bg-body-tertiary text-center rounded-4 p-4 p-sm-5 py-md-4 py-xl-5">
<p class="fs-xs text-body-secondary mb-1">Sweatshirts</p>
<h2 class="h4 mb-4">Colors for your mood</h2>
<div class="swiper user-select-none mb-4"
data-swiper='{
"allowTouchMove": false,
"loop": true,
"effect": "fade",
"autoplay": {
"delay": 1500,
"disableOnInteraction": false
}
}'
style="max-width: 342px">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="ratio" style="--cz-aspect-ratio: calc(230 / 342 * 100%)">
<img src="/img/shop/fashion/banner01.png" alt="Image">
</div>
</div>
<div class="swiper-slide">
<div class="ratio" style="--cz-aspect-ratio: calc(230 / 342 * 100%)">
<img src="/img/shop/fashion/banner02.png" alt="Image">
</div>
</div>
<div class="swiper-slide">
<div class="ratio" style="--cz-aspect-ratio: calc(230 / 342 * 100%)">
<img src="/img/shop/fashion/banner03.png" alt="Image">
</div>
</div>
</div>
</div>
<a class="btn btn-sm btn-dark stretched-link"
href="{{ route('second', ['shop', 'product-fashion']) }}">Shop
now</a>
</div>
</div> --}}
</div>
<!-- Show more button -->
<a href="{{ route('product.index', array_merge(request()->except('page'), ['page' => 1])) }}" type="button" class="btn btn-lg btn-outline-secondary w-100">
Show more
<i class="ci-chevron-down fs-xl ms-2 me-n1"></i>
</a>
</div>
</div>
</section>
<!-- Instagram feed -->
<section class="container pt-5 mt-2 mt-sm-3 mt-lg-4 mt-xl-5">
<div class="text-center pb-2 pb-md-3">
<h2 class="pb-2 mb-1">
<span class="animate-underline">
<a class="animate-target text-dark-emphasis text-decoration-none" href="#!">#cartzilla</a>
</span>
</h2>
<p>Find more inspiration on our Instagram</p>
</div>
<div class="overflow-x-auto pb-3 mb-n3" data-simplebar>
<div class="d-flex gap-2 gap-md-3 gap-lg-4" style="min-width: 700px">
<a class="hover-effect-scale hover-effect-opacity position-relative w-100 overflow-hidden"
href="#!">
<span
class="hover-effect-target position-absolute top-0 start-0 w-100 h-100 bg-black bg-opacity-25 opacity-0 z-1"></span>
<i
class="ci-instagram hover-effect-target fs-4 text-white position-absolute top-50 start-50 translate-middle opacity-0 z-2"></i>
<div class="hover-effect-target ratio ratio-1x1">
<img src="/img/instagram/01.jpg" alt="Instagram image">
</div>
</a>
<a class="hover-effect-scale hover-effect-opacity position-relative w-100 overflow-hidden"
href="#!">
<span
class="hover-effect-target position-absolute top-0 start-0 w-100 h-100 bg-black bg-opacity-25 opacity-0 z-1"></span>
<i
class="ci-instagram hover-effect-target fs-4 text-white position-absolute top-50 start-50 translate-middle opacity-0 z-2"></i>
<div class="hover-effect-target ratio ratio-1x1">
<img src="/img/instagram/02.jpg" alt="Instagram image">
</div>
</a>
<a class="hover-effect-scale hover-effect-opacity position-relative w-100 overflow-hidden"
href="#!">
<span
class="hover-effect-target position-absolute top-0 start-0 w-100 h-100 bg-black bg-opacity-25 opacity-0 z-1"></span>
<i
class="ci-instagram hover-effect-target fs-4 text-white position-absolute top-50 start-50 translate-middle opacity-0 z-2"></i>
<div class="hover-effect-target ratio ratio-1x1">
<img src="/img/instagram/03.jpg" alt="Instagram image">
</div>
</a>
<a class="hover-effect-scale hover-effect-opacity position-relative w-100 overflow-hidden"
href="#!">
<span
class="hover-effect-target position-absolute top-0 start-0 w-100 h-100 bg-black bg-opacity-25 opacity-0 z-1"></span>
<i
class="ci-instagram hover-effect-target fs-4 text-white position-absolute top-50 start-50 translate-middle opacity-0 z-2"></i>
<div class="hover-effect-target ratio ratio-1x1">
<img src="/img/instagram/04.jpg" alt="Instagram image">
</div>
</a>
<a class="hover-effect-scale hover-effect-opacity position-relative w-100 overflow-hidden"
href="#!">
<span
class="hover-effect-target position-absolute top-0 start-0 w-100 h-100 bg-black bg-opacity-25 opacity-0 z-1"></span>
<i
class="ci-instagram hover-effect-target fs-4 text-white position-absolute top-50 start-50 translate-middle opacity-0 z-2"></i>
<div class="hover-effect-target ratio ratio-1x1">
<img src="/img/instagram/05.jpg" alt="Instagram image">
</div>
</a>
</div>
</div>
</section>
</main>
@include('layouts.partials/footer2')
<button type="button"
class="fixed-bottom z-sticky w-100 btn btn-lg btn-dark border-0 border-top border-light border-opacity-10 rounded-0 pb-4 d-lg-none"
data-bs-toggle="offcanvas" data-bs-target="#filterSidebar" aria-controls="filterSidebar" data-bs-theme="light">
<i class="ci-filter fs-base me-2"></i>
Filters
</button>
<script>
document.addEventListener('DOMContentLoaded', function() {
loadGenders();
loadCategories();
loadProducts();
// Handle sort change
const sortSelect = document.querySelector('select[onchange*="sort_by"]');
if (sortSelect) {
sortSelect.removeAttribute('onchange');
sortSelect.addEventListener('change', function() {
loadProducts({ sort_by: this.value });
});
}
// Handle price range changes
const priceInputs = document.querySelectorAll('[data-range-slider-min], [data-range-slider-max]');
priceInputs.forEach(input => {
input.addEventListener('change', function() {
const minVal = document.querySelector('[data-range-slider-min]').value;
const maxVal = document.querySelector('[data-range-slider-max]').value;
loadProducts({
price_range_start: minVal || null,
price_range_end: maxVal || null
});
});
});
// Attach initial filter event listeners
attachFilterEventListeners();
});
function removeFilter(filterKey) {
const urlParams = new URLSearchParams(window.location.search);
urlParams.delete(`filter[${filterKey}]`);
// Convert URLSearchParams to object for loadProducts
const params = {};
for (const [key, value] of urlParams.entries()) {
params[key] = value;
}
loadProducts(params);
}
function clearAllFilters() {
const urlParams = new URLSearchParams(window.location.search);
// Remove all filter parameters
for (const [key] of urlParams.entries()) {
if (key.startsWith('filter[')) {
urlParams.delete(key);
}
}
// Keep non-filter parameters
const params = {};
for (const [key, value] of urlParams.entries()) {
if (!key.startsWith('filter[')) {
params[key] = value;
}
}
loadProducts(params);
}
function loadGenders() {
const currentGenderId = new URLSearchParams(window.location.search).get('filter[gender]');
fetch(`{{ route('product.ajax.genders') }}?current_gender=${currentGenderId || ''}`, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('genders-list').innerHTML = data.genders;
// Attach event listeners to newly loaded gender links
const genderLinks = document.querySelectorAll('#genders-list a[data-gender-id]');
genderLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
// Remove active class from all gender links
genderLinks.forEach(g => g.classList.remove('active', 'text-primary'));
// Add active class to clicked link
this.classList.add('active', 'text-primary');
const genderId = this.getAttribute('data-gender-id');
loadProducts({ 'filter[gender]': genderId });
});
});
}
})
.catch(error => {
console.error('Error loading genders:', error);
document.getElementById('genders-list').innerHTML = '<li class="nav-item mb-1"><span class="text-danger">Error loading genders</span></li>';
});
}
function loadCategories() {
const currentCategoryId = new URLSearchParams(window.location.search).get('filter[category]');
fetch(`{{ route('product.ajax.categories') }}?current_category=${currentCategoryId || ''}`, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('categories-list').innerHTML = data.categories;
// Attach event listeners to newly loaded category links
const categoryLinks = document.querySelectorAll('#categories-list a[data-category-id]');
categoryLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
// Remove active class from all category links
categoryLinks.forEach(c => c.classList.remove('active', 'text-primary'));
// Add active class to clicked link
this.classList.add('active', 'text-primary');
const categoryId = this.getAttribute('data-category-id');
loadProducts({ 'filter[category]': categoryId });
});
});
}
})
.catch(error => {
console.error('Error loading categories:', error);
document.getElementById('categories-list').innerHTML = '<li class="nav-item mb-1"><span class="text-danger">Error loading categories</span></li>';
});
}
function loadProducts(params = {}) {
const container = document.getElementById('products-container');
const countElement = document.getElementById('product-count');
// Show loading state
container.innerHTML = '<div class="col-12 text-center py-5"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';
countElement.textContent = 'Loading...';
// Get current URL parameters
const urlParams = new URLSearchParams(window.location.search);
// Add custom parameters
Object.keys(params).forEach(key => {
if (params[key] !== null) {
urlParams.set(key, params[key]);
}
});
// Make AJAX request
fetch(`{{ route('product.ajax') }}?${urlParams.toString()}`, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
container.innerHTML = data.products;
countElement.textContent = data.count;
// Update filters section
updateFiltersSection(data.filters);
// Update URL without page reload
const newUrl = window.location.pathname + (urlParams.toString() ? '?' + urlParams.toString() : '');
window.history.pushState({ path: newUrl }, '', newUrl);
} else {
container.innerHTML = '<div class="col-12 text-center py-5 text-danger">Error loading products</div>';
countElement.textContent = '0';
}
})
.catch(error => {
console.error('Error:', error);
container.innerHTML = '<div class="col-12 text-center py-5 text-danger">Error loading products</div>';
countElement.textContent = '0';
});
}
function updateFiltersSection(filters) {
const filtersContainer = document.querySelector('.filter-sidebar');
const filtersSection = filtersContainer.querySelector('.pb-4.mb-2.mb-xl-3');
if (Object.keys(filters).length > 0) {
// Build filters HTML
let filtersHtml = `
<div class="pb-4 mb-2 mb-xl-3">
<div class="d-flex align-items-center justify-content-between mb-3">
<h4 class="h6 mb-0">Filter</h4>
<a type="button" href="#"
class="btn btn-sm btn-secondary bg-transparent border-0 text-decoration-underline p-0 ms-2 clear-all-filters">
Clear all
</a>
</div>
<div class="d-flex flex-wrap gap-2">
`;
Object.keys(filters).forEach(key => {
filtersHtml += `
<button type="button" class="btn btn-sm btn-secondary remove-filter"
data-filter-key="${key}">
<i class="ci-close fs-sm ms-n1 me-1"></i>
${filters[key]}
</button>
`;
});
filtersHtml += `
</div>
</div>
`;
// Update or create filters section
if (filtersSection) {
filtersSection.outerHTML = filtersHtml;
} else {
filtersContainer.insertAdjacentHTML('afterbegin', filtersHtml);
}
// Re-attach event listeners for new filter buttons
attachFilterEventListeners();
} else {
// Remove filters section if no filters
if (filtersSection) {
filtersSection.remove();
}
}
}
function attachFilterEventListeners() {
// Handle filter removal
const removeFilterButtons = document.querySelectorAll('.remove-filter');
removeFilterButtons.forEach(button => {
button.addEventListener('click', function() {
const filterKey = this.getAttribute('data-filter-key');
removeFilter(filterKey);
});
});
// Handle clear all filters
const clearAllButton = document.querySelector('.clear-all-filters');
if (clearAllButton) {
clearAllButton.addEventListener('click', function(e) {
e.preventDefault();
clearAllFilters();
});
}
}
</script>
@endsection
@section('scripts')
@endsection