8a7e6ecf
Yarik
Namespaces
|
1
2
3
4
5
6
|
<?php
namespace artweb\artbox\ecommerce\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
|
01185786
Alexey Boroda
-Sms in process
|
7
|
use yii\helpers\VarDumper;
|
8a7e6ecf
Yarik
Namespaces
|
8
9
10
11
12
13
|
/**
* OrderSearch represents the model behind the search form about `\artweb\artbox\ecommerce\models\Order`.
*/
class OrderSearch extends Order
{
|
2ad65823
Alexey Boroda
-Added date range...
|
14
15
16
|
public $date_from;
public $date_to;
public $date_range;
|
01185786
Alexey Boroda
-Sms in process
|
17
|
public $sku;
|
8a7e6ecf
Yarik
Namespaces
|
18
19
20
21
22
23
24
25
26
27
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
'id',
|
01185786
Alexey Boroda
-Sms in process
|
28
|
'manager_id',
|
8a7e6ecf
Yarik
Namespaces
|
29
30
31
32
33
34
35
36
|
],
'integer',
],
[
[
'name',
'email',
'phone',
|
2ad65823
Alexey Boroda
-Added date range...
|
37
38
39
|
'date_from',
'date_to',
'date_range',
|
01185786
Alexey Boroda
-Sms in process
|
40
41
42
43
44
45
46
|
'created_at',
'body',
'declaration',
'consignment',
'delivery',
'label',
'sku',
|
8a7e6ecf
Yarik
Namespaces
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
],
'safe',
],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Order::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
|
b0c7d586
Alexey Boroda
-Bykov fixes
|
78
|
'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC ] ],
|
8a7e6ecf
Yarik
Namespaces
|
79
80
81
82
|
]
);
$this->load($params);
|
bb962a6d
Alexey Boroda
-Order in process
|
83
|
|
01185786
Alexey Boroda
-Sms in process
|
84
85
|
// VarDumper::dump($params, 10, true); die();
|
8a7e6ecf
Yarik
Namespaces
|
86
87
88
89
90
91
|
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
|
01185786
Alexey Boroda
-Sms in process
|
92
93
94
95
96
97
98
99
100
|
if (!empty( $this->sku )) {
$query->innerJoinWith('products.productVariant')
->andWhere(
[
'product_variant.id' => $this->sku,
]
);
}
|
8a7e6ecf
Yarik
Namespaces
|
101
102
103
|
// grid filtering conditions
$query->andFilterWhere(
[
|
01185786
Alexey Boroda
-Sms in process
|
104
|
'id' => $this->id,
|
8a7e6ecf
Yarik
Namespaces
|
105
106
107
108
109
110
111
112
113
|
]
);
$query->andFilterWhere(
[
'like',
'name',
$this->name,
]
|
01185786
Alexey Boroda
-Sms in process
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
);
$query->andFilterWhere(
[
'like',
'email',
$this->email,
]
);
$query->andFilterWhere(
[
'like',
'phone',
$this->phone,
]
);
$query->andFilterWhere(
[
'like',
'body',
$this->body,
]
);
$query->andFilterWhere(
[
'like',
'consignment',
$this->consignment,
]
);
$query->andFilterWhere(
[
'like',
'declaration',
$this->declaration,
]
);
$query->andFilterWhere(
[
'label' => $this->label,
]
);
$query->andFilterWhere(
[
'manager_id' => $this->manager_id,
|
b0c7d586
Alexey Boroda
-Bykov fixes
|
159
|
|
01185786
Alexey Boroda
-Sms in process
|
160
161
162
163
164
165
166
167
|
]
);
$query->andFilterWhere(
[
'delivery' => $this->delivery,
]
);
if (!empty( $this->date_range )) {
|
bb962a6d
Alexey Boroda
-Order in process
|
168
169
|
$this->date_from = strtotime(explode('to', $this->date_range)[ 0 ]);
$this->date_to = strtotime(explode('to', $this->date_range)[ 1 ]);
|
01185786
Alexey Boroda
-Sms in process
|
170
|
|
bb962a6d
Alexey Boroda
-Order in process
|
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
$query->andFilterWhere(
[
'>=',
'created_at',
$this->date_from,
]
);
$query->andFilterWhere(
[
'<=',
'created_at',
$this->date_to,
]
);
}
|
2ad65823
Alexey Boroda
-Added date range...
|
186
|
|
8a7e6ecf
Yarik
Namespaces
|
187
188
189
|
return $dataProvider;
}
}
|