Commit 71c1673708e0ce950c7ee253a22bca8c4d3e5eda
1 parent
44a8a989
Url manager fix
Showing
6 changed files
with
43 additions
and
22 deletions
Show diff stats
frontend/config/main.php
@@ -59,6 +59,11 @@ | @@ -59,6 +59,11 @@ | ||
59 | 'route' => 'filter/index', | 59 | 'route' => 'filter/index', |
60 | 'defaults' => [ 'filter' => '' ], | 60 | 'defaults' => [ 'filter' => '' ], |
61 | ], | 61 | ], |
62 | + [ | ||
63 | + 'pattern' => 'category/<category>/<filter>', | ||
64 | + 'route' => 'category/view', | ||
65 | + 'defaults' => [ 'filter' => '' ], | ||
66 | + ], | ||
62 | 'robots.txt' => 'site/robots', | 67 | 'robots.txt' => 'site/robots', |
63 | ], | 68 | ], |
64 | ], | 69 | ], |
frontend/controllers/CategoryController.php
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | use artbox\catalog\helpers\FilterHelper; | 4 | use artbox\catalog\helpers\FilterHelper; |
5 | use artbox\catalog\models\Category; | 5 | use artbox\catalog\models\Category; |
6 | use artbox\core\components\SeoComponent; | 6 | use artbox\core\components\SeoComponent; |
7 | + use artbox\core\models\Alias; | ||
7 | use yii\data\ActiveDataProvider; | 8 | use yii\data\ActiveDataProvider; |
8 | use yii\db\ActiveQuery; | 9 | use yii\db\ActiveQuery; |
9 | use yii\web\Controller; | 10 | use yii\web\Controller; |
@@ -20,15 +21,15 @@ | @@ -20,15 +21,15 @@ | ||
20 | /** | 21 | /** |
21 | * Show category by ID | 22 | * Show category by ID |
22 | * | 23 | * |
23 | - * @param int $id | 24 | + * @param string $category |
24 | * | 25 | * |
25 | * @param string $filter | 26 | * @param string $filter |
26 | * | 27 | * |
27 | * @return string | 28 | * @return string |
28 | */ | 29 | */ |
29 | - public function actionView($id, $filter = '') | 30 | + public function actionView($category, $filter = '') |
30 | { | 31 | { |
31 | - $model = $this->findModel($id); | 32 | + $model = $this->findModel($category); |
32 | /** | 33 | /** |
33 | * @var SeoComponent $seo | 34 | * @var SeoComponent $seo |
34 | * @var FilterHelper $filterHelper | 35 | * @var FilterHelper $filterHelper |
@@ -62,18 +63,29 @@ | @@ -62,18 +63,29 @@ | ||
62 | /** | 63 | /** |
63 | * Find category by ID | 64 | * Find category by ID |
64 | * | 65 | * |
65 | - * @param $id | 66 | + * @param $category |
66 | * | 67 | * |
67 | - * @return Category | 68 | + * @return \artbox\catalog\models\Category |
68 | * @throws \yii\web\NotFoundHttpException | 69 | * @throws \yii\web\NotFoundHttpException |
69 | */ | 70 | */ |
70 | - protected function findModel($id) | 71 | + protected function findModel($category) |
71 | { | 72 | { |
72 | /** | 73 | /** |
73 | * @var SeoComponent $seo | 74 | * @var SeoComponent $seo |
74 | */ | 75 | */ |
75 | $seo = Yii::$app->get('seo'); | 76 | $seo = Yii::$app->get('seo'); |
76 | /** | 77 | /** |
78 | + * @var FilterHelper $filter | ||
79 | + */ | ||
80 | + $filter = \Yii::$app->get('filter'); | ||
81 | + /** | ||
82 | + * @var Alias $alias | ||
83 | + */ | ||
84 | + $alias = Alias::find() | ||
85 | + ->where([ 'value' => $category ]) | ||
86 | + ->one(); | ||
87 | + $id = $filter->getIdFromRoute($alias->route); | ||
88 | + /** | ||
77 | * @var Category $model | 89 | * @var Category $model |
78 | */ | 90 | */ |
79 | $model = Category::findWithFilters($id) | 91 | $model = Category::findWithFilters($id) |
frontend/views/category/view.php
@@ -115,8 +115,8 @@ _________________________________________________________ --> | @@ -115,8 +115,8 @@ _________________________________________________________ --> | ||
115 | $brand->lang->title, | 115 | $brand->lang->title, |
116 | [ | 116 | [ |
117 | '/category/view', | 117 | '/category/view', |
118 | - 'id' => $model->id, | ||
119 | - 'filter' => $filterHelper->buildLink($brand), | 118 | + 'category' => $model->lang->alias->value, |
119 | + 'filter' => $filterHelper->buildLink($brand), | ||
120 | ] | 120 | ] |
121 | ), | 121 | ), |
122 | [ | 122 | [ |
@@ -151,8 +151,8 @@ _________________________________________________________ --> | @@ -151,8 +151,8 @@ _________________________________________________________ --> | ||
151 | $option->lang->value, | 151 | $option->lang->value, |
152 | [ | 152 | [ |
153 | '/category/view', | 153 | '/category/view', |
154 | - 'id' => $model->id, | ||
155 | - 'filter' => $filterHelper->buildLink($option), | 154 | + 'category' => $model->lang->alias->value, |
155 | + 'filter' => $filterHelper->buildLink($option), | ||
156 | ] | 156 | ] |
157 | ), | 157 | ), |
158 | [ | 158 | [ |
@@ -187,8 +187,8 @@ _________________________________________________________ --> | @@ -187,8 +187,8 @@ _________________________________________________________ --> | ||
187 | $option->lang->value, | 187 | $option->lang->value, |
188 | [ | 188 | [ |
189 | '/category/view', | 189 | '/category/view', |
190 | - 'id' => $model->id, | ||
191 | - 'filter' => $filterHelper->buildLink($option), | 190 | + 'category' => $model->lang->alias->value, |
191 | + 'filter' => $filterHelper->buildLink($option), | ||
192 | ] | 192 | ] |
193 | ), | 193 | ), |
194 | [ | 194 | [ |
@@ -223,8 +223,8 @@ _________________________________________________________ --> | @@ -223,8 +223,8 @@ _________________________________________________________ --> | ||
223 | $option->lang->value, | 223 | $option->lang->value, |
224 | [ | 224 | [ |
225 | '/category/view', | 225 | '/category/view', |
226 | - 'id' => $model->id, | ||
227 | - 'filter' => $filterHelper->buildLink($option), | 226 | + 'category' => $model->lang->alias->value, |
227 | + 'filter' => $filterHelper->buildLink($option), | ||
228 | ] | 228 | ] |
229 | ), | 229 | ), |
230 | [ | 230 | [ |
@@ -259,8 +259,8 @@ _________________________________________________________ --> | @@ -259,8 +259,8 @@ _________________________________________________________ --> | ||
259 | $option->lang->value, | 259 | $option->lang->value, |
260 | [ | 260 | [ |
261 | '/category/view', | 261 | '/category/view', |
262 | - 'id' => $model->id, | ||
263 | - 'filter' => $filterHelper->buildLink($option), | 262 | + 'category' => $model->lang->alias->value, |
263 | + 'filter' => $filterHelper->buildLink($option), | ||
264 | ] | 264 | ] |
265 | ), | 265 | ), |
266 | [ | 266 | [ |
frontend/views/layouts/_category_menu.php
@@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
22 | $category->lang->title, | 22 | $category->lang->title, |
23 | [ | 23 | [ |
24 | 'category/view', | 24 | 'category/view', |
25 | - 'id' => $category->id, | 25 | + 'category' => $category->lang->alias->value, |
26 | ], | 26 | ], |
27 | [ | 27 | [ |
28 | 'tabindex' => -1, | 28 | 'tabindex' => -1, |
@@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
39 | $childCategory->lang->title, | 39 | $childCategory->lang->title, |
40 | [ | 40 | [ |
41 | 'category/view', | 41 | 'category/view', |
42 | - 'id' => $childCategory->id, | 42 | + 'category' => $childCategory->lang->alias->value, |
43 | ] | 43 | ] |
44 | ) | 44 | ) |
45 | ); | 45 | ); |
frontend/views/layouts/main.php
@@ -394,7 +394,11 @@ _________________________________________________________ --> | @@ -394,7 +394,11 @@ _________________________________________________________ --> | ||
394 | <div class="container"> | 394 | <div class="container"> |
395 | <?= Breadcrumbs::widget( | 395 | <?= Breadcrumbs::widget( |
396 | [ | 396 | [ |
397 | - 'links' => isset( $this->params[ 'breadcrumbs' ] ) ? $this->params[ 'breadcrumbs' ] : [], | 397 | + 'links' => isset( $this->params[ 'breadcrumbs' ] ) ? $this->params[ 'breadcrumbs' ] : [], |
398 | + 'homeLink' => [ | ||
399 | + 'label' => \Yii::t('app', 'Home'), | ||
400 | + 'url' => [ '/site/index' ], | ||
401 | + ], | ||
398 | ] | 402 | ] |
399 | ) ?> | 403 | ) ?> |
400 | </div> | 404 | </div> |
@@ -402,7 +406,7 @@ _________________________________________________________ --> | @@ -402,7 +406,7 @@ _________________________________________________________ --> | ||
402 | <?php | 406 | <?php |
403 | } | 407 | } |
404 | ?> | 408 | ?> |
405 | - <!-- *** Breadcrumbs END *** --> | 409 | + <!-- *** crumbs END *** --> |
406 | 410 | ||
407 | <?= $content ?> | 411 | <?= $content ?> |
408 | 412 |
frontend/views/product/view.php
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | 'label' => $model->category->parent->lang->title, | 23 | 'label' => $model->category->parent->lang->title, |
24 | 'url' => [ | 24 | 'url' => [ |
25 | '/category/view', | 25 | '/category/view', |
26 | - 'id' => $model->category->parent->id, | 26 | + 'category' => $model->category->parent->lang->alias->value, |
27 | ], | 27 | ], |
28 | ]; | 28 | ]; |
29 | } | 29 | } |
@@ -31,7 +31,7 @@ | @@ -31,7 +31,7 @@ | ||
31 | 'label' => $model->category->lang->title, | 31 | 'label' => $model->category->lang->title, |
32 | 'url' => [ | 32 | 'url' => [ |
33 | '/category/view', | 33 | '/category/view', |
34 | - 'id' => $model->category->id, | 34 | + 'category' => $model->category->lang->alias->value, |
35 | ], | 35 | ], |
36 | ]; | 36 | ]; |
37 | } | 37 | } |