Commit 183a715c3fc418fd20622afe5ed27c47a04b81ba

Authored by Yarik
1 parent df08a6f4

Sort fix

Showing 1 changed file with 28 additions and 23 deletions   Show diff stats
models/ProductFrontendSearch.php
... ... @@ -7,6 +7,7 @@
7 7 use yii\base\Model;
8 8 use yii\data\ActiveDataProvider;
9 9 use yii\data\ArrayDataProvider;
  10 + use yii\data\Sort;
10 11 use yii\db\ActiveQuery;
11 12  
12 13 use artweb\artbox\ecommerce\models\Product;
... ... @@ -63,35 +64,39 @@
63 64 public function search($category = null, $params = [], $in_stock = true)
64 65 {
65 66  
  67 + $sort = new Sort(
  68 + [
  69 + 'attributes' => [
  70 + 'name_asc' => [
  71 + 'asc' => [ 'lang.title' => SORT_ASC ],
  72 + 'desc' => [ 'lang.title' => SORT_ASC ],
  73 + 'default' => SORT_ASC,
  74 + 'label' => 'имени от А до Я',
  75 + ],
  76 + 'name_desc' => [
  77 + 'asc' => [ 'lang.title' => SORT_DESC ],
  78 + 'desc' => [ 'lang.title' => SORT_DESC ],
  79 + 'default' => SORT_DESC,
  80 + 'label' => 'имени от Я до А',
  81 + ],
  82 + 'price' => [
  83 + 'asc' => [ 'enabledVariants.price' => SORT_ASC ],
  84 + 'desc' => [ 'enabledVariants.price' => SORT_DESC ],
  85 + 'default' => SORT_DESC,
  86 + 'label' => 'по цене',
  87 + ],
  88 + ],
  89 + ]
  90 + );
  91 +
66 92 $dataProvider = new ArrayDataProvider(
67 93 [
68 94 'allModels' => $this->getSearchQuery($category, $params, $in_stock)
69   - ->all(),
  95 + ->with('variant')->all(),
70 96 'pagination' => [
71 97 'pageSize' => 10,
72 98 ],
73   - 'sort' => [
74   - 'attributes' => [
75   - 'name_asc' => [
76   - 'asc' => [ 'name' => SORT_ASC ],
77   - 'desc' => [ 'name' => SORT_ASC ],
78   - 'default' => SORT_ASC,
79   - 'label' => 'имени от А до Я',
80   - ],
81   - 'name_desc' => [
82   - 'asc' => [ 'name' => SORT_DESC ],
83   - 'desc' => [ 'name' => SORT_DESC ],
84   - 'default' => SORT_DESC,
85   - 'label' => 'имени от Я до А',
86   - ],
87   - 'price' => [
88   - 'asc' => [ 'price' => SORT_ASC ],
89   - 'desc' => [ 'price' => SORT_DESC ],
90   - 'default' => SORT_DESC,
91   - 'label' => 'по цене',
92   - ],
93   - ],
94   - ],
  99 + 'sort' => $sort,
95 100 ]
96 101 );
97 102  
... ...