Blame view

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

      

      namespace artweb\artbox\ecommerce\models;

      

      use yii\base\Model;

      use yii\data\ActiveDataProvider;

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

01185786   Alexey Boroda   -Sms in process
8
      use yii\helpers\VarDumper;

8a7e6ecf   Yarik   Namespaces
9
10
11
12
13
14
      

      /**

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

       */

      class OrderSearch extends Order

      {

2ad65823   Alexey Boroda   -Added date range...
15
16
17
          public $date_from;

          public $date_to;

          public $date_range;

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

8a7e6ecf   Yarik   Namespaces
19
20
21
22
23
24
25
26
27
28
          

          /**

           * @inheritdoc

           */

          public function rules()

          {

              return [

                  [

                      [

                          'id',

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

8a7e6ecf   Yarik   Namespaces
30
31
32
33
34
35
36
37
                      ],

                      'integer',

                  ],

                  [

                      [

                          'name',

                          'email',

                          'phone',

2ad65823   Alexey Boroda   -Added date range...
38
39
40
                          'date_from',

                          'date_to',

                          'date_range',

01185786   Alexey Boroda   -Sms in process
41
42
43
44
45
46
47
                          'created_at',

                          'body',

                          'declaration',

                          'consignment',

                          'delivery',

                          'label',

                          'sku',

8a7e6ecf   Yarik   Namespaces
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
                      ],

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

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

8a7e6ecf   Yarik   Namespaces
74
75
76
77
78
              

              // add conditions that should always apply here

              

              $dataProvider = new ActiveDataProvider(

                  [

7a6df601   Alexey Boroda   -Second phone search
79
80
                      'query'      => $query,

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

deaedeb0   Alexey Boroda   -Order module tas...
81
82
83
                      'pagination' => [

                          'pageSize' => 50,

                      ],

8a7e6ecf   Yarik   Namespaces
84
85
86
87
                  ]

              );

              

              $this->load($params);

bb962a6d   Alexey Boroda   -Order in process
88
              

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

              

8a7e6ecf   Yarik   Namespaces
91
92
93
94
95
96
              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
97
              if (!empty($this->sku)) {

01185786   Alexey Boroda   -Sms in process
98
99
100
101
102
103
104
105
                  $query->innerJoinWith('products.productVariant')

                        ->andWhere(

                            [

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

                            ]

                        );

              }

              

8a7e6ecf   Yarik   Namespaces
106
107
108
              // grid filtering conditions

              $query->andFilterWhere(

                  [

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

8a7e6ecf   Yarik   Namespaces
110
111
112
113
114
115
116
117
118
                  ]

              );

              

              $query->andFilterWhere(

                  [

                      'like',

                      'name',

                      $this->name,

                  ]

01185786   Alexey Boroda   -Sms in process
119
120
121
122
123
124
125
126
127
128
              );

              $query->andFilterWhere(

                  [

                      'like',

                      'email',

                      $this->email,

                  ]

              );

              $query->andFilterWhere(

                  [

7a6df601   Alexey Boroda   -Second phone search
129
130
131
132
133
134
135
136
137
138
139
                      'or',

                      [

                          'like',

                          'phone',

                          $this->phone,

                      ],

                      [

                          'like',

                          'phone2',

                          $this->phone,

                      ],

01185786   Alexey Boroda   -Sms in process
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
                  ]

              );

              $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
172
                  

01185786   Alexey Boroda   -Sms in process
173
174
175
176
177
178
179
                  ]

              );

              $query->andFilterWhere(

                  [

                      'delivery' => $this->delivery,

                  ]

              );

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

bb962a6d   Alexey Boroda   -Order in process
181
182
                  $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
183
                  

bb962a6d   Alexey Boroda   -Order in process
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
                  $query->andFilterWhere(

                      [

                          '>=',

                          'created_at',

                          $this->date_from,

                      ]

                  );

                  $query->andFilterWhere(

                      [

                          '<=',

                          'created_at',

                          $this->date_to,

                      ]

                  );

              }

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

8a7e6ecf   Yarik   Namespaces
200
201
              return $dataProvider;

          }

facb6c13   Alexey Boroda   -Translations
202
203
204
          

          public function attributeLabels()

          {

c83499b4   Alexey Boroda   -Order index tran...
205
206
              $labels = [

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

facb6c13   Alexey Boroda   -Translations
207
              ];

c83499b4   Alexey Boroda   -Order index tran...
208
209
              

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

facb6c13   Alexey Boroda   -Translations
210
          }

8a7e6ecf   Yarik   Namespaces
211
      }