Blame view

models/OrderSearch.php 6.38 KB
8a7e6ecf   Yarik   Namespaces
1
2
3
4
  <?php

      

      namespace artweb\artbox\ecommerce\models;

      

287e356d   Alexey Boroda   -Permissions read...
5
      use common\models\Permissions;

8a7e6ecf   Yarik   Namespaces
6
7
      use yii\base\Model;

      use yii\data\ActiveDataProvider;

c83499b4   Alexey Boroda   -Order index tran...
8
      use yii\helpers\ArrayHelper;

8a7e6ecf   Yarik   Namespaces
9
10
11
      

      /**

       * OrderSearch represents the model behind the search form about `\artweb\artbox\ecommerce\models\Order`.

287e356d   Alexey Boroda   -Permissions read...
12
13
       *

       * @property Permissions $permissions

8a7e6ecf   Yarik   Namespaces
14
15
16
       */

      class OrderSearch extends Order

      {

2ad65823   Alexey Boroda   -Added date range...
17
18
19
          public $date_from;

          public $date_to;

          public $date_range;

01185786   Alexey Boroda   -Sms in process
20
          public $sku;

8a7e6ecf   Yarik   Namespaces
21
          

287e356d   Alexey Boroda   -Permissions read...
22
23
          public $permissions;

          

8a7e6ecf   Yarik   Namespaces
24
25
26
27
28
29
30
31
32
          /**

           * @inheritdoc

           */

          public function rules()

          {

              return [

                  [

                      [

                          'id',

01185786   Alexey Boroda   -Sms in process
33
                          'manager_id',

8a7e6ecf   Yarik   Namespaces
34
35
36
37
38
39
40
41
                      ],

                      'integer',

                  ],

                  [

                      [

                          'name',

                          'email',

                          'phone',

2ad65823   Alexey Boroda   -Added date range...
42
43
44
                          'date_from',

                          'date_to',

                          'date_range',

01185786   Alexey Boroda   -Sms in process
45
46
47
48
49
50
51
                          'created_at',

                          'body',

                          'declaration',

                          'consignment',

                          'delivery',

                          'label',

                          'sku',

8a7e6ecf   Yarik   Namespaces
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
                      ],

                      '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...
76
77
              $query = Order::find()

                            ->where([ 'published' => true ]);

8a7e6ecf   Yarik   Namespaces
78
79
80
81
82
              

              // add conditions that should always apply here

              

              $dataProvider = new ActiveDataProvider(

                  [

7a6df601   Alexey Boroda   -Second phone search
83
84
                      'query'      => $query,

                      'sort'       => [ 'defaultOrder' => [ 'id' => SORT_DESC ] ],

deaedeb0   Alexey Boroda   -Order module tas...
85
86
87
                      'pagination' => [

                          'pageSize' => 50,

                      ],

8a7e6ecf   Yarik   Namespaces
88
89
90
91
                  ]

              );

              

              $this->load($params);

bb962a6d   Alexey Boroda   -Order in process
92
              

01185786   Alexey Boroda   -Sms in process
93
94
              //            VarDumper::dump($params, 10, true); die();

              

8a7e6ecf   Yarik   Namespaces
95
96
97
98
99
100
              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;

              }

              

7a6df601   Alexey Boroda   -Second phone search
101
              if (!empty($this->sku)) {

01185786   Alexey Boroda   -Sms in process
102
103
104
105
106
107
108
109
                  $query->innerJoinWith('products.productVariant')

                        ->andWhere(

                            [

                                'product_variant.id' => $this->sku,

                            ]

                        );

              }

              

8a7e6ecf   Yarik   Namespaces
110
111
112
              // grid filtering conditions

              $query->andFilterWhere(

                  [

01185786   Alexey Boroda   -Sms in process
113
                      'id' => $this->id,

8a7e6ecf   Yarik   Namespaces
114
115
116
117
118
119
120
121
122
                  ]

              );

              

              $query->andFilterWhere(

                  [

                      'like',

                      'name',

                      $this->name,

                  ]

01185786   Alexey Boroda   -Sms in process
123
124
125
126
127
128
129
130
131
132
              );

              $query->andFilterWhere(

                  [

                      'like',

                      'email',

                      $this->email,

                  ]

              );

              $query->andFilterWhere(

                  [

7a6df601   Alexey Boroda   -Second phone search
133
134
135
136
137
138
139
140
141
142
143
                      'or',

                      [

                          'like',

                          'phone',

                          $this->phone,

                      ],

                      [

                          'like',

                          'phone2',

                          $this->phone,

                      ],

01185786   Alexey Boroda   -Sms in process
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
                  ]

              );

              $query->andFilterWhere(

                  [

                      'like',

                      'body',

                      $this->body,

                  ]

              );

              $query->andFilterWhere(

                  [

                      'like',

                      'consignment',

                      $this->consignment,

                  ]

              );

              $query->andFilterWhere(

                  [

                      'like',

                      'declaration',

                      $this->declaration,

                  ]

              );

287e356d   Alexey Boroda   -Permissions read...
167
168
169
170
171
172
173
174
              

              if (!empty($this->permissions))

              {

                  $query->andFilterWhere([

                      'label' => $this->permissions->labelsArray,

                                         ]);

              }

              

01185786   Alexey Boroda   -Sms in process
175
176
177
178
179
180
181
182
183
              $query->andFilterWhere(

                  [

                      'label' => $this->label,

                  

                  ]

              );

              $query->andFilterWhere(

                  [

                      'manager_id' => $this->manager_id,

b0c7d586   Alexey Boroda   -Bykov fixes
184
                  

01185786   Alexey Boroda   -Sms in process
185
186
187
188
189
190
191
                  ]

              );

              $query->andFilterWhere(

                  [

                      'delivery' => $this->delivery,

                  ]

              );

7a6df601   Alexey Boroda   -Second phone search
192
              if (!empty($this->date_range)) {

bb962a6d   Alexey Boroda   -Order in process
193
194
                  $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
195
                  

bb962a6d   Alexey Boroda   -Order in process
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
                  $query->andFilterWhere(

                      [

                          '>=',

                          'created_at',

                          $this->date_from,

                      ]

                  );

                  $query->andFilterWhere(

                      [

                          '<=',

                          'created_at',

                          $this->date_to,

                      ]

                  );

              }

2ad65823   Alexey Boroda   -Added date range...
211
              

8a7e6ecf   Yarik   Namespaces
212
213
              return $dataProvider;

          }

facb6c13   Alexey Boroda   -Translations
214
215
216
          

          public function attributeLabels()

          {

c83499b4   Alexey Boroda   -Order index tran...
217
218
              $labels = [

                  'sku' => \Yii::t('app', 'Артикул'),

facb6c13   Alexey Boroda   -Translations
219
              ];

c83499b4   Alexey Boroda   -Order index tran...
220
221
              

              return ArrayHelper::merge($labels, parent::attributeLabels());

facb6c13   Alexey Boroda   -Translations
222
          }

8a7e6ecf   Yarik   Namespaces
223
      }