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
|
],
'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)
{
|
eb190b1f
Alexey Boroda
-Order form add p...
|
71
72
|
$query = Order::find()
->where([ 'published' => true ]);
|
8a7e6ecf
Yarik
Namespaces
|
73
74
75
76
77
78
|
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
|
b0c7d586
Alexey Boroda
-Bykov fixes
|
79
|
'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC ] ],
|
8a7e6ecf
Yarik
Namespaces
|
80
81
82
83
|
]
);
$this->load($params);
|
bb962a6d
Alexey Boroda
-Order in process
|
84
|
|
01185786
Alexey Boroda
-Sms in process
|
85
86
|
// VarDumper::dump($params, 10, true); die();
|
8a7e6ecf
Yarik
Namespaces
|
87
88
89
90
91
92
|
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
|
93
94
95
96
97
98
99
100
101
|
if (!empty( $this->sku )) {
$query->innerJoinWith('products.productVariant')
->andWhere(
[
'product_variant.id' => $this->sku,
]
);
}
|
8a7e6ecf
Yarik
Namespaces
|
102
103
104
|
// grid filtering conditions
$query->andFilterWhere(
[
|
01185786
Alexey Boroda
-Sms in process
|
105
|
'id' => $this->id,
|
8a7e6ecf
Yarik
Namespaces
|
106
107
108
109
110
111
112
113
114
|
]
);
$query->andFilterWhere(
[
'like',
'name',
$this->name,
]
|
01185786
Alexey Boroda
-Sms in process
|
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
159
|
);
$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
|
160
|
|
01185786
Alexey Boroda
-Sms in process
|
161
162
163
164
165
166
167
168
|
]
);
$query->andFilterWhere(
[
'delivery' => $this->delivery,
]
);
if (!empty( $this->date_range )) {
|
bb962a6d
Alexey Boroda
-Order in process
|
169
170
|
$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
|
171
|
|
bb962a6d
Alexey Boroda
-Order in process
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
$query->andFilterWhere(
[
'>=',
'created_at',
$this->date_from,
]
);
$query->andFilterWhere(
[
'<=',
'created_at',
$this->date_to,
]
);
}
|
2ad65823
Alexey Boroda
-Added date range...
|
187
|
|
8a7e6ecf
Yarik
Namespaces
|
188
189
190
|
return $dataProvider;
}
}
|