diff --git a/frontend/controllers/CategoryController.php b/frontend/controllers/CategoryController.php index 3a6174e..fba2f3c 100755 --- a/frontend/controllers/CategoryController.php +++ b/frontend/controllers/CategoryController.php @@ -1,6 +1,7 @@ buildQuery() ->innerJoinWith('category', false) ->andWhere([ 'product_to_category.category_id' => $model->id ]) - ->with('image', 'variants.image', 'lang'); + ->innerJoinWith('lang') + ->innerJoinWith('variant') + ->with('image', 'variants.image'); $dataProvider = new ActiveDataProvider( [ 'query' => $query, 'pagination' => [ 'pageSize' => 18, ], + 'sort' => [ + 'attributes' => [ + 'title_asc' => [ + 'asc' => [ + 'product_lang.title' => SORT_ASC, + ], + 'desc' => [ + 'product_lang.title' => SORT_ASC, + ], + 'label' => \Yii::t('app', 'по имени от А до Я'), + ], + 'title_desc' => [ + 'asc' => [ + 'product_lang.title' => SORT_DESC, + ], + 'desc' => [ + 'product_lang.title' => SORT_DESC, + ], + 'label' => \Yii::t('app', 'по имени от Я до А'), + ], + 'price_asc' => [ + 'asc' => [ + 'variant.price' => SORT_ASC, + ], + 'desc' => [ + 'variant.price' => SORT_ASC, + ], + 'label' => \Yii::t('app', 'по цене по возрастанию'), + ], + 'price_desc' => [ + 'asc' => [ + 'variant.price' => SORT_DESC, + ], + 'desc' => [ + 'variant.price' => SORT_DESC, + ], + 'label' => \Yii::t('app', 'по цене по убыванию'), + ], + ], + ], ] ); @@ -106,7 +148,7 @@ ) ->one(); $seo->setAlias($model->lang->alias); - if (!empty( $model )) { + if (!empty($model)) { if ($model->lang->alias_id !== $seo->aliasId) { throw new NotFoundHttpException('Wrong language'); } diff --git a/frontend/views/category/view.php b/frontend/views/category/view.php index 6b44812..cf85ce5 100755 --- a/frontend/views/category/view.php +++ b/frontend/views/category/view.php @@ -324,20 +324,48 @@ _________________________________________________________ --> _________________________________________________________ -->
-
-

Сортировка:

- +
+

:

+
+ sort->attributes)[ 0 ]; + $currentSort = \Yii::$app->request->get($dataProvider->sort->sortParam); + if (!empty($currentSort)) { + if (preg_match('/^-?(\w+)$/', $currentSort, $matches)) { + if (array_key_exists($matches[ 1 ], $dataProvider->sort->attributes)) { + $currentSortAttribute = $matches[ 1 ]; + } + } + } + echo $dataProvider->sort->link( + $currentSortAttribute, + [ + 'label' => Html::tag( + 'span', + $dataProvider->sort->attributes[ $currentSortAttribute ][ 'label' ] + ) . Html::tag( + 'i', + '', + [ + 'class' => 'fa fa-angle-down', + 'aria-hidden' => true, + ] + ), + ] + ); + ?> +
    + sort->attributes as $attribute => $sort) { + if ($currentSortAttribute == $attribute) { + continue; + } + echo Html::tag('li', $dataProvider->sort->link($attribute)); + } + ?> +
+