|
@@ -30,39 +30,27 @@ class ProductController extends Controller
|
|
|
|
|
|
public function category($slug)
|
|
|
{
|
|
|
+ // $products = DistProduct::paginate(10); // 每页显示10个产品
|
|
|
+// return $this->liquidRenderer->render('products_categories.liquid', ['products' => $products]);
|
|
|
+
|
|
|
// 获取分类信息
|
|
|
// 获取分类信息,并限定 dist_id
|
|
|
- $slugs = [];
|
|
|
- if (strpos($slug, ',') !== false) {
|
|
|
- // 包含逗号
|
|
|
- $slugs = explode(',', $slug);
|
|
|
- } else {
|
|
|
- // 不包含逗号
|
|
|
- $slugs = [$slug];
|
|
|
- }
|
|
|
-
|
|
|
- $categoryIds = [];
|
|
|
- foreach ($slugs as $slug) {
|
|
|
- $category = DistProductCategory::where(function ($query) use ($slug) {
|
|
|
- $query->where('slug', $slug)
|
|
|
- ->orWhere('id', $slug);
|
|
|
- })
|
|
|
- ->where('dist_id', getDistId())
|
|
|
- ->firstOrFail();
|
|
|
- $categoryIds[] = $category->id;
|
|
|
- }
|
|
|
+ $category = DistProductCategory::where(function ($query) use ($slug) {
|
|
|
+ $query->where('slug', $slug)
|
|
|
+ ->orWhere('id', $slug);
|
|
|
+ })
|
|
|
+ ->where('dist_id', getDistId())
|
|
|
+ ->firstOrFail();
|
|
|
|
|
|
- if (empty($categoryIds)) {
|
|
|
+ if (!$category) {
|
|
|
abort('404');
|
|
|
}
|
|
|
-
|
|
|
- if ($categoryIds) {
|
|
|
+ $categoryIds = [$category->id];
|
|
|
+ if ($category) {
|
|
|
//找下一级分类
|
|
|
- foreach ($categoryIds as $id) {
|
|
|
- $subCategories = DistProductCategory::where('parent_id', $id)->get();
|
|
|
- foreach ($subCategories as $subCategory) {
|
|
|
- $categoryIds[] = $subCategory->id;
|
|
|
- }
|
|
|
+ $subCategories = DistProductCategory::where('parent_id', $category->id)->get();
|
|
|
+ foreach ($subCategories as $subCategory) {
|
|
|
+ $categoryIds[] = $subCategory->id;
|
|
|
}
|
|
|
}
|
|
|
|