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 @@