From 9ec2918fb42d93a96e43b3b1fb3837389062820f Mon Sep 17 00:00:00 2001 From: Bayu Lukman Yusuf Date: Mon, 16 Feb 2026 15:15:47 +0700 Subject: [PATCH] product grid --- app/Http/Controllers/ProductController.php | 79 ++++++++++++++++++- .../home/home-popular-products.blade.php | 7 +- .../home/product-highlight.blade.php | 8 +- .../views/shop/catalog-fashion.blade.php | 67 +--------------- routes/web.php | 1 + 5 files changed, 90 insertions(+), 72 deletions(-) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 5d72687..6bb7ece 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -115,7 +115,7 @@ class ProductController extends Controller $productHtml .= ''; } else { foreach ($products as $product) { - $productHtml .= '
'; + $productHtml .= '
'; $productHtml .= view('components.home.product-card', ['product' => $product])->render(); $productHtml .= '
'; } @@ -289,6 +289,8 @@ class ProductController extends Controller break; } + $params['limit'] = 10; + $products = $productRepository->getList($params); // Render product cards HTML @@ -299,7 +301,80 @@ class ProductController extends Controller $productHtml .= '
'; } else { foreach ($products as $product) { - $productHtml .= '
'; + $productHtml .= '
'; + $productHtml .= view('components.home.product-card', ['product' => $product])->render(); + $productHtml .= '
'; + } + } + + return response()->json([ + 'success' => true, + 'products' => $productHtml, + 'count' => count($products), + 'type' => $type, + ]); + } + + public function populers(Request $request) + { + $type = $request->input('type', 'new'); + $limit = 6; + + $user = auth()->user(); + $userId = $user ? $user->id : 0; + [$location_id, $is_consignment] = Cache::remember('employee_user_'.$userId, 60 * 60 * 24, function () use ($user) { + + if ($user == null) { + return [10, false]; + } + + $employee = @$user->employee; + $location_id = @$employee->location_id; + $location = @$employee->location; + $is_consignment = (bool) @$location->is_consignment; + + return [$location_id, $is_consignment]; + + }); + + $productRepository = new ProductRepository; + + // Set parameters based on type + $params = [ + 'limit' => $limit, + 'location_id' => $location_id, + 'is_consignment' => $is_consignment, + ]; + + switch ($type) { + case 'new': + $params['sort'] = 'new'; + break; + case 'best_sellers': + $params['sort'] = 'best_sellers'; + break; + case 'special-offer': + $params['event'] = 'special-offer'; + break; + case 'top_rated': + $params['sort'] = 'random'; + break; + default: + $params['sort'] = 'new'; + break; + } + + $products = $productRepository->getList($params); + + // Render product cards HTML + $productHtml = ''; + if (count($products) == 0) { + $productHtml = '
'; + $productHtml .= 'No products found'; + $productHtml .= '
'; + } else { + foreach ($products as $product) { + $productHtml .= '
'; $productHtml .= view('components.home.product-card', ['product' => $product])->render(); $productHtml .= '
'; } diff --git a/resources/views/components/home/home-popular-products.blade.php b/resources/views/components/home/home-popular-products.blade.php index ac477ee..d157481 100644 --- a/resources/views/components/home/home-popular-products.blade.php +++ b/resources/views/components/home/home-popular-products.blade.php @@ -113,7 +113,7 @@ document.addEventListener('DOMContentLoaded', function() { } // Make AJAX request for popular products - fetch('{{ route("product.ajax.highlights") }}?type=best_sellers&limit=6') + fetch('{{ route("product.ajax.populers") }}?type=best_sellers&limit=6') .then(response => response.json()) .then(data => { if (data.success && data.products) { @@ -167,8 +167,13 @@ document.addEventListener('DOMContentLoaded', function() { price.className = 'h6 mb-0'; price.textContent = productPrice ? productPrice.textContent : '$0.00'; + const name = document.createElement('div'); + name.className = 'text-truncate mb-1'; + name.textContent = productLink ? productLink.textContent.trim() : 'Product Name'; + link.appendChild(span); navDiv.appendChild(link); + navDiv.appendChild(name); navDiv.appendChild(price); listItem.appendChild(img); listItem.appendChild(navDiv); diff --git a/resources/views/components/home/product-highlight.blade.php b/resources/views/components/home/product-highlight.blade.php index 04a0685..16730fa 100644 --- a/resources/views/components/home/product-highlight.blade.php +++ b/resources/views/components/home/product-highlight.blade.php @@ -78,16 +78,16 @@
-
+
-
- @for ($i = 1; $i <= 8; $i++) -
+
+ @for ($i = 1; $i <= 10; $i++) +
diff --git a/resources/views/shop/catalog-fashion.blade.php b/resources/views/shop/catalog-fashion.blade.php index a5ecade..d023add 100644 --- a/resources/views/shop/catalog-fashion.blade.php +++ b/resources/views/shop/catalog-fashion.blade.php @@ -487,7 +487,7 @@
-
+
{{--
@@ -544,70 +544,7 @@ -
-
-

- - #AsiaGolf - -

-

Find more inspiration on our Instagram

-
- -
+ @include('layouts.partials.footer2') diff --git a/routes/web.php b/routes/web.php index bc11f8b..1fb037e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -37,6 +37,7 @@ Route::get('/', [HomeController::class, 'index'])->name('home'); Route::get('/products', [ProductController::class, 'index'])->name('product.index'); Route::get('/products/ajax', [ProductController::class, 'ajax'])->name('product.ajax'); +Route::get('/products/ajax/populers', [ProductController::class, 'populers'])->name('product.ajax.populers'); Route::get('/products/ajax/highlights', [ProductController::class, 'highlights'])->name('product.ajax.highlights'); Route::get('/products/ajax/brands', [ProductController::class, 'brands'])->name('product.ajax.brands'); Route::get('/products/ajax/categories', [ProductController::class, 'categories'])->name('product.ajax.categories');