|
@@ -42,7 +42,7 @@ class ProductController extends Controller
|
|
->where('dist_id', getDistId())
|
|
->where('dist_id', getDistId())
|
|
->firstOrFail();
|
|
->firstOrFail();
|
|
|
|
|
|
- // 获取分类下的所有产品,并按 is_pinned 排序,然后进行分页
|
|
|
|
|
|
+ // 获取分类下的所有产品,排序,然后进行分页
|
|
$products = DistProduct::where('category_id', $category->id)
|
|
$products = DistProduct::where('category_id', $category->id)
|
|
->where('dist_id', getDistId())
|
|
->where('dist_id', getDistId())
|
|
->where('enabled', 1)
|
|
->where('enabled', 1)
|
|
@@ -51,6 +51,8 @@ class ProductController extends Controller
|
|
->orderBy('id', 'desc') // 按 id 降序排序
|
|
->orderBy('id', 'desc') // 按 id 降序排序
|
|
->paginate(12);
|
|
->paginate(12);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// 创建分页数据结构
|
|
// 创建分页数据结构
|
|
$paginator = [
|
|
$paginator = [
|
|
'previous_page' => $products->previousPageUrl() ? true : false, // 是否有上一页
|
|
'previous_page' => $products->previousPageUrl() ? true : false, // 是否有上一页
|
|
@@ -94,6 +96,7 @@ class ProductController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 产品详情
|
|
* Display the specified product.
|
|
* Display the specified product.
|
|
*
|
|
*
|
|
* @param int $id
|
|
* @param int $id
|
|
@@ -108,7 +111,22 @@ class ProductController extends Controller
|
|
abort('404');
|
|
abort('404');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 获取改产品分类下的相关产品,不包当前产品,限制条数 limit 4
|
|
|
|
+ $relatedProducts = DistProduct::where('category_id', $product->category_id)
|
|
|
|
+ ->where('dist_id', getDistId())
|
|
|
|
+ ->where('enabled', 1)
|
|
|
|
+ ->where('id', '<>', $product->id)
|
|
|
|
+ ->with('images') // Eager load images
|
|
|
|
+ ->orderBy('order', 'desc') // 按 order 字段降序排序
|
|
|
|
+ ->orderBy('id', 'desc') // 按 id 降序排序
|
|
|
|
+ ->limit(4)
|
|
|
|
+ ->get();
|
|
|
|
+
|
|
|
|
+
|
|
// 构建导航数据 开始
|
|
// 构建导航数据 开始
|
|
|
|
+ $category=$product->distProductCategory;
|
|
|
|
+ $categoryUrl = $category->slug ? "/products/categories/{$category->slug}" : "/products/categories/{$category->id}";
|
|
|
|
+
|
|
$breadcrumbs = [
|
|
$breadcrumbs = [
|
|
[
|
|
[
|
|
'url' => '/',
|
|
'url' => '/',
|
|
@@ -116,10 +134,6 @@ class ProductController extends Controller
|
|
]
|
|
]
|
|
];
|
|
];
|
|
|
|
|
|
- $category=$product->distProductCategory;
|
|
|
|
-
|
|
|
|
- $categoryUrl = $category->slug ? "/products/categories/{$category->slug}" : "/products/categories/{$category->id}";
|
|
|
|
-
|
|
|
|
$breadcrumbs[] = [
|
|
$breadcrumbs[] = [
|
|
'url' => $categoryUrl,
|
|
'url' => $categoryUrl,
|
|
'name' => $category->name,
|
|
'name' => $category->name,
|
|
@@ -131,10 +145,11 @@ class ProductController extends Controller
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
+ // 渲染模板并传递数据
|
|
return $this->liquidRenderer->render('products_detail.liquid',
|
|
return $this->liquidRenderer->render('products_detail.liquid',
|
|
[
|
|
[
|
|
'product' => $product,
|
|
'product' => $product,
|
|
- 'csrf_token' => csrf_token(),
|
|
|
|
|
|
+ 'relatedProducts' => $relatedProducts,
|
|
'breadcrumbs' => $breadcrumbs,
|
|
'breadcrumbs' => $breadcrumbs,
|
|
]);
|
|
]);
|
|
}
|
|
}
|