Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Add products sorting by shows on backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert committed Apr 28, 2017
1 parent 315c211 commit 9ce5cf8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/entities/Product.php
Expand Up @@ -206,6 +206,7 @@ public function attributeLabels()
'price_id' => Yii::t('shop', 'Price'),
'number' => Yii::t('shop', 'Number'),
'show' => Yii::t('shop', 'Show'),
'shows' => Yii::t('shop', 'Shows'),
];
}

Expand Down
10 changes: 8 additions & 2 deletions common/entities/SearchProduct.php
Expand Up @@ -46,11 +46,15 @@ public function scenarios()
public function search($params)
{
$query = (\Yii::$app->user->can('viewCompleteProductList')) ?
Product::find()->joinWith('translations')->orderBy(['category_id' => SORT_ASC, 'position' => SORT_ASC]) :
Product::find()->joinWith('translations')->where(['owner' => \Yii::$app->user->id])->orderBy(['category_id' => SORT_ASC, 'position' => SORT_ASC]);
Product::find()->joinWith('translations') :
Product::find()->joinWith('translations')->where(['owner' => \Yii::$app->user->id]);

$this->load($params);

if (empty($params['sort'])) {
$query->orderBy(['category_id' => SORT_ASC, 'position' => SORT_ASC]);
}

$query->andFilterWhere([
'shop_product.category_id' => $this->category,
])->andFilterWhere(['like', 'shop_product_translation.title', $this->title
Expand All @@ -59,6 +63,8 @@ public function search($params)

$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['attributes' => ['shows']],

'pagination' => [
'pagesize' => 10,
],
Expand Down

0 comments on commit 9ce5cf8

Please sign in to comment.