Commit 71c1673708e0ce950c7ee253a22bca8c4d3e5eda

Authored by Yarik
1 parent 44a8a989

Url manager fix

frontend/config/main.php
... ... @@ -59,6 +59,11 @@
59 59 'route' => 'filter/index',
60 60 'defaults' => [ 'filter' => '' ],
61 61 ],
  62 + [
  63 + 'pattern' => 'category/<category>/<filter>',
  64 + 'route' => 'category/view',
  65 + 'defaults' => [ 'filter' => '' ],
  66 + ],
62 67 'robots.txt' => 'site/robots',
63 68 ],
64 69 ],
... ...
frontend/controllers/CategoryController.php
... ... @@ -4,6 +4,7 @@
4 4 use artbox\catalog\helpers\FilterHelper;
5 5 use artbox\catalog\models\Category;
6 6 use artbox\core\components\SeoComponent;
  7 + use artbox\core\models\Alias;
7 8 use yii\data\ActiveDataProvider;
8 9 use yii\db\ActiveQuery;
9 10 use yii\web\Controller;
... ... @@ -20,15 +21,15 @@
20 21 /**
21 22 * Show category by ID
22 23 *
23   - * @param int $id
  24 + * @param string $category
24 25 *
25 26 * @param string $filter
26 27 *
27 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 34 * @var SeoComponent $seo
34 35 * @var FilterHelper $filterHelper
... ... @@ -62,18 +63,29 @@
62 63 /**
63 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 69 * @throws \yii\web\NotFoundHttpException
69 70 */
70   - protected function findModel($id)
  71 + protected function findModel($category)
71 72 {
72 73 /**
73 74 * @var SeoComponent $seo
74 75 */
75 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 89 * @var Category $model
78 90 */
79 91 $model = Category::findWithFilters($id)
... ...
frontend/views/category/view.php
... ... @@ -115,8 +115,8 @@ _________________________________________________________ --&gt;
115 115 $brand->lang->title,
116 116 [
117 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 @@ _________________________________________________________ --&gt;
151 151 $option->lang->value,
152 152 [
153 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 @@ _________________________________________________________ --&gt;
187 187 $option->lang->value,
188 188 [
189 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 @@ _________________________________________________________ --&gt;
223 223 $option->lang->value,
224 224 [
225 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 @@ _________________________________________________________ --&gt;
259 259 $option->lang->value,
260 260 [
261 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 22 $category->lang->title,
23 23 [
24 24 'category/view',
25   - 'id' => $category->id,
  25 + 'category' => $category->lang->alias->value,
26 26 ],
27 27 [
28 28 'tabindex' => -1,
... ... @@ -39,7 +39,7 @@
39 39 $childCategory->lang->title,
40 40 [
41 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 @@ _________________________________________________________ --&gt;
394 394 <div class="container">
395 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 404 </div>
... ... @@ -402,7 +406,7 @@ _________________________________________________________ --&gt;
402 406 <?php
403 407 }
404 408 ?>
405   - <!-- *** Breadcrumbs END *** -->
  409 + <!-- *** crumbs END *** -->
406 410  
407 411 <?= $content ?>
408 412  
... ...
frontend/views/product/view.php
... ... @@ -23,7 +23,7 @@
23 23 'label' => $model->category->parent->lang->title,
24 24 'url' => [
25 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 31 'label' => $model->category->lang->title,
32 32 'url' => [
33 33 '/category/view',
34   - 'id' => $model->category->id,
  34 + 'category' => $model->category->lang->alias->value,
35 35 ],
36 36 ];
37 37 }
... ...