diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 8b1ae90..df68878 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -96,6 +96,7 @@ class ProductController extends Controller 'sort' => $sortBy, 'category_id' => $filter['category'] ?? null, 'gender_id' => $filter['gender'] ?? null, + 'brand_id' => $filter['brand'] ?? null, 'search' => $search, 'location_id' => $location_id, 'is_consignment' => $is_consignment, @@ -142,6 +143,16 @@ class ProductController extends Controller } } + if (isset($filter['brand']) && $filter['brand']) { + $brand = \App\Models\Brand::find($filter['brand']); + + if ($brand) { + $filter['brand'] = $brand->name; + } else { + unset($filter); + } + } + $filters = $filter; return response()->json([ @@ -179,12 +190,17 @@ class ProductController extends Controller $brandRepository = new \App\Repositories\Catalog\BrandRepository; $brands = $brandRepository->getList([]); - // Render brand HTML + // Render brand links HTML $brandHtml = ''; + $currentBrandId = $request->input('current_brand'); + foreach ($brands as $brand) { - $brandHtml .= ''; - $brandHtml .= '' . $brand->name . ''; - $brandHtml .= ''; + $isActive = $currentBrandId == $brand->id; + $brandHtml .= ''; } return response()->json([ diff --git a/resources/views/shop/catalog-fashion.blade.php b/resources/views/shop/catalog-fashion.blade.php index b2fcfa6..22b9376 100644 --- a/resources/views/shop/catalog-fashion.blade.php +++ b/resources/views/shop/catalog-fashion.blade.php @@ -75,6 +75,27 @@ + + +
+

+ +

+
+
+
+ +
+
+
+
+

@@ -654,6 +675,7 @@ document.addEventListener('DOMContentLoaded', function() { loadGenders(); loadCategories(); + loadBrands(); loadProducts(); // Handle sort change @@ -827,6 +849,7 @@ loadGenders(); loadCategories(); + loadBrands(); loadProducts(Object.fromEntries(urlParams.entries())); } @@ -856,6 +879,7 @@ loadGenders(); loadCategories(); + loadBrands(); loadProducts(Object.fromEntries(urlParams.entries())); } @@ -939,6 +963,45 @@ }); } + function loadBrands() { + const currentBrandId = new URLSearchParams(window.location.search).get('filter[brand]'); + + fetch(`{{ route('product.ajax.brands') }}?current_brand=${currentBrandId || ''}`, { + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'Accept': 'application/json' + } + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + document.getElementById('brands-list').innerHTML = data.brands; + + // Attach event listeners to newly loaded brand links + const brandLinks = document.querySelectorAll('#brands-list a[data-brand-id]'); + brandLinks.forEach(link => { + link.addEventListener('click', function(e) { + e.preventDefault(); + // Remove active class from all brand links + brandLinks.forEach(b => b.classList.remove('active', 'text-primary')); + // Add active class to clicked link + this.classList.add('active', 'text-primary'); + + const brandId = this.getAttribute('data-brand-id'); + loadProducts({ + 'filter[brand]': brandId + }); + }); + }); + } + }) + .catch(error => { + console.error('Error loading brands:', error); + document.getElementById('brands-list').innerHTML = + ''; + }); + } + function loadProducts(params = {}) { // Prevent multiple simultaneous calls if (isLoading) {