diff --git a/models/ProductFrontendSearch.php b/models/ProductFrontendSearch.php index 0f0258e..0abd297 100755 --- a/models/ProductFrontendSearch.php +++ b/models/ProductFrontendSearch.php @@ -7,6 +7,7 @@ use yii\base\Model; use yii\data\ActiveDataProvider; use yii\data\ArrayDataProvider; + use yii\data\Sort; use yii\db\ActiveQuery; use artweb\artbox\ecommerce\models\Product; @@ -63,35 +64,39 @@ public function search($category = null, $params = [], $in_stock = true) { + $sort = new Sort( + [ + 'attributes' => [ + 'name_asc' => [ + 'asc' => [ 'lang.title' => SORT_ASC ], + 'desc' => [ 'lang.title' => SORT_ASC ], + 'default' => SORT_ASC, + 'label' => 'имени от А до Я', + ], + 'name_desc' => [ + 'asc' => [ 'lang.title' => SORT_DESC ], + 'desc' => [ 'lang.title' => SORT_DESC ], + 'default' => SORT_DESC, + 'label' => 'имени от Я до А', + ], + 'price' => [ + 'asc' => [ 'enabledVariants.price' => SORT_ASC ], + 'desc' => [ 'enabledVariants.price' => SORT_DESC ], + 'default' => SORT_DESC, + 'label' => 'по цене', + ], + ], + ] + ); + $dataProvider = new ArrayDataProvider( [ 'allModels' => $this->getSearchQuery($category, $params, $in_stock) - ->all(), + ->with('variant')->all(), 'pagination' => [ 'pageSize' => 10, ], - 'sort' => [ - 'attributes' => [ - 'name_asc' => [ - 'asc' => [ 'name' => SORT_ASC ], - 'desc' => [ 'name' => SORT_ASC ], - 'default' => SORT_ASC, - 'label' => 'имени от А до Я', - ], - 'name_desc' => [ - 'asc' => [ 'name' => SORT_DESC ], - 'desc' => [ 'name' => SORT_DESC ], - 'default' => SORT_DESC, - 'label' => 'имени от Я до А', - ], - 'price' => [ - 'asc' => [ 'price' => SORT_ASC ], - 'desc' => [ 'price' => SORT_DESC ], - 'default' => SORT_DESC, - 'label' => 'по цене', - ], - ], - ], + 'sort' => $sort, ] ); -- libgit2 0.21.4