CatalogController.php
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace frontend\controllers;
use common\modules\product\models\Category;
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
use yii\web\HttpException;
class CatalogController extends \yii\web\Controller
{
public function actionCategory($alias)
{
$category = CategorySearch::findByAlias($alias);
if ($category->depth < 2) {
return $this->render(
'categories',
[
'category' => $category
]
);
} else {
return $this->render(
'products',
[
'category' => $category,
]
);
}
}
public function actionProduct($alias)
{
$product = Product::find()->where('like', ['alias' => $alias]);
if (empty($product->product_id)) {
// throw new HttpException(404 ,'Page not found');
// return $this->redirect('/', 301);
}
return $this->render('product');
}
public function actionBrands()
{
return 'actionBrands';
}
public function actionBrand($alias)
{
return 'actionBrand:'. $alias;
}
}