d8c1a2e0
Yarik
Big commit artbox
|
1
|
<?php
|
d55d2fe0
Yarik
Multilanguage
|
2
|
|
4e55ce81
Yarik
Another one admin...
|
3
4
5
6
|
namespace common\modules\product\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
|
d55d2fe0
Yarik
Multilanguage
|
7
|
|
d8c1a2e0
Yarik
Big commit artbox
|
8
|
/**
|
4e55ce81
Yarik
Another one admin...
|
9
10
|
* ProductVariantSearch represents the model behind the search form about
* `common\modules\product\models\ProductVariant`.
|
d8c1a2e0
Yarik
Big commit artbox
|
11
|
*/
|
4e55ce81
Yarik
Another one admin...
|
12
|
class ProductVariantSearch extends ProductVariant
|
d8c1a2e0
Yarik
Big commit artbox
|
13
|
{
|
4e55ce81
Yarik
Another one admin...
|
14
|
|
8af13427
Yarik
For leha commit.
|
15
|
public $variantName;
|
4e55ce81
Yarik
Another one admin...
|
16
17
18
19
|
public function behaviors()
{
return [];
|
d8c1a2e0
Yarik
Big commit artbox
|
20
|
}
|
4e55ce81
Yarik
Another one admin...
|
21
22
23
24
25
26
27
28
29
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
|
8af13427
Yarik
For leha commit.
|
30
|
'variantName',
|
4e55ce81
Yarik
Another one admin...
|
31
32
33
|
'sku',
],
'safe',
|
d8c1a2e0
Yarik
Big commit artbox
|
34
|
],
|
4e55ce81
Yarik
Another one admin...
|
35
36
|
[
[
|
4428da8c
Yarik
Almost all databa...
|
37
|
'id',
|
4e55ce81
Yarik
Another one admin...
|
38
39
40
|
'stock',
],
'integer',
|
d8c1a2e0
Yarik
Big commit artbox
|
41
|
],
|
4e55ce81
Yarik
Another one admin...
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
[
[
'price',
'price_old',
],
'number',
],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
|
d8c1a2e0
Yarik
Big commit artbox
|
59
|
}
|
4e55ce81
Yarik
Another one admin...
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ProductVariant::find()
->joinWith('lang');
// add conditions that should always apply here
|
4428da8c
Yarik
Almost all databa...
|
75
76
77
78
79
|
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
]
);
|
4e55ce81
Yarik
Another one admin...
|
80
81
82
|
$this->load($params);
|
4428da8c
Yarik
Almost all databa...
|
83
|
if (!$this->validate()) {
|
4e55ce81
Yarik
Another one admin...
|
84
85
86
87
88
|
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
|
4428da8c
Yarik
Almost all databa...
|
89
90
91
92
93
94
95
96
97
98
99
100
|
$dataProvider->setSort(
[
'attributes' => [
'id',
'sku',
'variantName' => [
'asc' => [ 'product_variant_lang.title' => SORT_ASC ],
'desc' => [ 'product_variant_lang.title' => SORT_DESC ],
],
'price',
'price_old',
'stock',
|
4e55ce81
Yarik
Another one admin...
|
101
|
],
|
4428da8c
Yarik
Almost all databa...
|
102
103
|
]
);
|
4e55ce81
Yarik
Another one admin...
|
104
|
|
4428da8c
Yarik
Almost all databa...
|
105
106
107
108
109
110
111
|
$query->andFilterWhere(
[
'price' => $this->price,
'price_old' => $this->price_old,
'stock' => $this->stock,
]
);
|
4e55ce81
Yarik
Another one admin...
|
112
|
|
4428da8c
Yarik
Almost all databa...
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
$query->andFilterWhere(
[
'ilike',
'product_variant_lang.title',
$this->variantName,
]
)
->andFilterWhere(
[
'ilike',
'sku',
$this->sku,
]
);
|
4e55ce81
Yarik
Another one admin...
|
127
|
|
4428da8c
Yarik
Almost all databa...
|
128
129
130
131
132
133
|
$query->groupBy(
[
'product_variant.id',
'product_variant_lang.title',
]
);
|
4e55ce81
Yarik
Another one admin...
|
134
135
|
return $dataProvider;
|
d8c1a2e0
Yarik
Big commit artbox
|
136
|
}
|
d8c1a2e0
Yarik
Big commit artbox
|
137
|
}
|