brands category
This commit is contained in:
parent
3b91c813da
commit
3a66f08579
|
|
@ -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 .= '<a class="swiper-slide text-body" href="' . route('product.index', ['brand' => $brand->slug]) . '" aria-label="' . $brand->name . '">';
|
||||
$brandHtml .= '<img src="' . $brand->image_url . '" alt="' . $brand->name . '" class="object-fit-contain">';
|
||||
$brandHtml .= '</a>';
|
||||
$isActive = $currentBrandId == $brand->id;
|
||||
$brandHtml .= '<li class="nav-item mb-1">';
|
||||
$brandHtml .= '<a class="nav-link d-block fw-normal p-0 ' . ($isActive ? 'active text-primary' : '') . '" ';
|
||||
$brandHtml .= 'href="#" data-brand-id="' . $brand->id . '">';
|
||||
$brandHtml .= $brand->name;
|
||||
$brandHtml .= '</a></li>';
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
|
|
|
|||
|
|
@ -75,6 +75,27 @@
|
|||
</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">
|
||||
<div style="height: 220px" data-simplebar data-simplebar-auto-hide="false">
|
||||
<ul class="nav flex-column gap-2 pe-3" id="brands-list">
|
||||
<!-- Brands 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">
|
||||
|
|
@ -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 =
|
||||
'<li class="nav-item mb-1"><span class="text-danger">Error loading brands</span></li>';
|
||||
});
|
||||
}
|
||||
|
||||
function loadProducts(params = {}) {
|
||||
// Prevent multiple simultaneous calls
|
||||
if (isLoading) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue