Commit fcd620e29bbd32b893485a0fe315863ab7341cc5

Authored by Alexey Boroda
1 parent 995dd689

-Number column added to order

Showing 1 changed file with 89 additions and 78 deletions   Show diff stats
controllers/OrderController.php
1 <?php 1 <?php
2 2
3 namespace artbox\order\controllers; 3 namespace artbox\order\controllers;
4 - 4 +
5 use artbox\catalog\models\Variant; 5 use artbox\catalog\models\Variant;
6 use artbox\core\admin\actions\Index; 6 use artbox\core\admin\actions\Index;
7 use artbox\order\labels\models\Delivery; 7 use artbox\order\labels\models\Delivery;
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 use yii\filters\AccessControl; 16 use yii\filters\AccessControl;
17 use yii\web\Response; 17 use yii\web\Response;
18 use yii\widgets\ActiveForm; 18 use yii\widgets\ActiveForm;
19 - 19 +
20 /** 20 /**
21 * OrderController implements the CRUD actions for Order model. 21 * OrderController implements the CRUD actions for Order model.
22 */ 22 */
@@ -29,11 +29,11 @@ @@ -29,11 +29,11 @@
29 { 29 {
30 return '@artbox/order/views/order'; 30 return '@artbox/order/views/order';
31 } 31 }
32 - 32 +
33 public function behaviors() 33 public function behaviors()
34 { 34 {
35 return [ 35 return [
36 - 'verbs' => [ 36 + 'verbs' => [
37 'class' => VerbFilter::className(), 37 'class' => VerbFilter::className(),
38 'actions' => [ 38 'actions' => [
39 'delete' => [ 'POST' ], 39 'delete' => [ 'POST' ],
@@ -57,15 +57,18 @@ @@ -57,15 +57,18 @@
57 ], 57 ],
58 ]; 58 ];
59 } 59 }
60 - 60 +
61 public function actions() 61 public function actions()
62 { 62 {
63 return [ 63 return [
64 'index' => [ 64 'index' => [
65 'class' => Index::className(), 65 'class' => Index::className(),
66 'columns' => [ 66 'columns' => [
  67 + 'id' => [
  68 + 'type' => Index::NUMBER_COL,
  69 + ],
67 'name' => [ 70 'name' => [
68 - 'type' => Index::ACTION_COL, 71 + 'type' => Index::ACTION_COL,
69 'columnConfig' => [ 72 'columnConfig' => [
70 'buttonsTemplate' => '{edit}{delete}', 73 'buttonsTemplate' => '{edit}{delete}',
71 ], 74 ],
@@ -93,7 +96,7 @@ @@ -93,7 +96,7 @@
93 ], 96 ],
94 ]; 97 ];
95 } 98 }
96 - 99 +
97 /** 100 /**
98 * Displays a single Order model. 101 * Displays a single Order model.
99 * 102 *
@@ -110,7 +113,7 @@ @@ -110,7 +113,7 @@
110 ] 113 ]
111 ); 114 );
112 } 115 }
113 - 116 +
114 /** 117 /**
115 * Creates a new Order model. 118 * Creates a new Order model.
116 * If creation is successful, the browser will be redirected to the 'view' page. 119 * If creation is successful, the browser will be redirected to the 'view' page.
@@ -120,7 +123,7 @@ @@ -120,7 +123,7 @@
120 public function actionCreate() 123 public function actionCreate()
121 { 124 {
122 $model = new Order(); 125 $model = new Order();
123 - 126 +
124 if ($model->load(Yii::$app->request->post()) && $model->save()) { 127 if ($model->load(Yii::$app->request->post()) && $model->save()) {
125 if (!empty(\Yii::$app->request->post('Product'))) { 128 if (!empty(\Yii::$app->request->post('Product'))) {
126 foreach (\Yii::$app->request->post('Product') as $id => $count) { 129 foreach (\Yii::$app->request->post('Product') as $id => $count) {
@@ -153,46 +156,46 @@ @@ -153,46 +156,46 @@
153 $labels = Label::find() 156 $labels = Label::find()
154 ->joinWith('language') 157 ->joinWith('language')
155 ->select( 158 ->select(
156 - [  
157 - 'title',  
158 - 'id',  
159 - ]  
160 - ) 159 + [
  160 + 'title',
  161 + 'id',
  162 + ]
  163 + )
161 ->where( 164 ->where(
162 - [  
163 - 'status' => true,  
164 - ]  
165 - ) 165 + [
  166 + 'status' => true,
  167 + ]
  168 + )
166 ->indexBy('id') 169 ->indexBy('id')
167 ->column(); 170 ->column();
168 $deliveries = Delivery::find() 171 $deliveries = Delivery::find()
169 ->joinWith('language') 172 ->joinWith('language')
170 ->select( 173 ->select(
171 - [  
172 - 'title',  
173 - 'id',  
174 - ]  
175 - ) 174 + [
  175 + 'title',
  176 + 'id',
  177 + ]
  178 + )
176 ->where( 179 ->where(
177 - [  
178 - 'status' => true,  
179 - ]  
180 - ) 180 + [
  181 + 'status' => true,
  182 + ]
  183 + )
181 ->indexBy('id') 184 ->indexBy('id')
182 ->column(); 185 ->column();
183 $payments = Payment::find() 186 $payments = Payment::find()
184 ->joinWith('language') 187 ->joinWith('language')
185 ->select( 188 ->select(
186 - [  
187 - 'title',  
188 - 'id',  
189 - ]  
190 - ) 189 + [
  190 + 'title',
  191 + 'id',
  192 + ]
  193 + )
191 ->where( 194 ->where(
192 - [  
193 - 'status' => true,  
194 - ]  
195 - ) 195 + [
  196 + 'status' => true,
  197 + ]
  198 + )
196 ->indexBy('id') 199 ->indexBy('id')
197 ->column(); 200 ->column();
198 return $this->render( 201 return $this->render(
@@ -206,7 +209,7 @@ @@ -206,7 +209,7 @@
206 ); 209 );
207 } 210 }
208 } 211 }
209 - 212 +
210 /** 213 /**
211 * Updates an existing Order model. 214 * Updates an existing Order model.
212 * If update is successful, the browser will be redirected to the 'view' page. 215 * If update is successful, the browser will be redirected to the 'view' page.
@@ -218,9 +221,13 @@ @@ -218,9 +221,13 @@
218 public function actionUpdate($id) 221 public function actionUpdate($id)
219 { 222 {
220 $model = $this->findModel($id); 223 $model = $this->findModel($id);
221 -  
222 - if ($model->load(Yii::$app->request->post()) && $model->save() && !empty(\Yii::$app->request->post('OrderProduct'))) {  
223 - //print_r(\Yii::$app->request->post('OrderProduct')); die(); 224 +
  225 + if ($model->load(Yii::$app->request->post()) && $model->save() && !empty(
  226 + \Yii::$app->request->post(
  227 + 'OrderProduct'
  228 + )
  229 + )) {
  230 + //print_r(\Yii::$app->request->post('OrderProduct')); die();
224 OrderProduct::saveItems(\Yii::$app->request->post('OrderProduct'), $id); 231 OrderProduct::saveItems(\Yii::$app->request->post('OrderProduct'), $id);
225 return $this->redirect( 232 return $this->redirect(
226 [ 233 [
@@ -247,31 +254,31 @@ @@ -247,31 +254,31 @@
247 $deliveries = Delivery::find() 254 $deliveries = Delivery::find()
248 ->joinWith('language') 255 ->joinWith('language')
249 ->select( 256 ->select(
250 - [  
251 - 'title',  
252 - 'id',  
253 - ]  
254 - ) 257 + [
  258 + 'title',
  259 + 'id',
  260 + ]
  261 + )
255 ->where( 262 ->where(
256 - [  
257 - 'status' => true,  
258 - ]  
259 - ) 263 + [
  264 + 'status' => true,
  265 + ]
  266 + )
260 ->indexBy('id') 267 ->indexBy('id')
261 ->column(); 268 ->column();
262 $payments = Payment::find() 269 $payments = Payment::find()
263 ->joinWith('language') 270 ->joinWith('language')
264 ->select( 271 ->select(
265 - [  
266 - 'title',  
267 - 'id',  
268 - ]  
269 - ) 272 + [
  273 + 'title',
  274 + 'id',
  275 + ]
  276 + )
270 ->where( 277 ->where(
271 - [  
272 - 'status' => true,  
273 - ]  
274 - ) 278 + [
  279 + 'status' => true,
  280 + ]
  281 + )
275 ->indexBy('id') 282 ->indexBy('id')
276 ->column(); 283 ->column();
277 return $this->render( 284 return $this->render(
@@ -285,7 +292,7 @@ @@ -285,7 +292,7 @@
285 ); 292 );
286 } 293 }
287 } 294 }
288 - 295 +
289 /** 296 /**
290 * Deletes an existing Order model. 297 * Deletes an existing Order model.
291 * If deletion is successful, the browser will be redirected to the 'index' page. 298 * If deletion is successful, the browser will be redirected to the 'index' page.
@@ -298,10 +305,10 @@ @@ -298,10 +305,10 @@
298 { 305 {
299 $this->findModel($id) 306 $this->findModel($id)
300 ->delete(); 307 ->delete();
301 - 308 +
302 return $this->redirect([ 'index' ]); 309 return $this->redirect([ 'index' ]);
303 } 310 }
304 - 311 +
305 public function actionProductList($q = null, $id = null) 312 public function actionProductList($q = null, $id = null)
306 { 313 {
307 $response = \Yii::$app->response; 314 $response = \Yii::$app->response;
@@ -349,7 +356,7 @@ @@ -349,7 +356,7 @@
349 } 356 }
350 return $out; 357 return $out;
351 } 358 }
352 - 359 +
353 public function actionAddToOrder() 360 public function actionAddToOrder()
354 { 361 {
355 /** 362 /**
@@ -360,7 +367,7 @@ @@ -360,7 +367,7 @@
360 \Yii::$app->response->format = Response::FORMAT_JSON; 367 \Yii::$app->response->format = Response::FORMAT_JSON;
361 $id = \Yii::$app->request->post('id'); 368 $id = \Yii::$app->request->post('id');
362 $count = \Yii::$app->request->post('count') ? \Yii::$app->request->post('count') : 1; 369 $count = \Yii::$app->request->post('count') ? \Yii::$app->request->post('count') : 1;
363 - 370 +
364 $variant = Variant::find() 371 $variant = Variant::find()
365 ->with('product.lang') 372 ->with('product.lang')
366 ->where( 373 ->where(
@@ -369,7 +376,7 @@ @@ -369,7 +376,7 @@
369 ] 376 ]
370 ) 377 )
371 ->one(); 378 ->one();
372 - 379 +
373 if ($variant) { 380 if ($variant) {
374 $form = new ActiveForm(); 381 $form = new ActiveForm();
375 $orderProduct = new OrderProduct( 382 $orderProduct = new OrderProduct(
@@ -378,7 +385,7 @@ @@ -378,7 +385,7 @@
378 'variant_id' => $variant->id, 385 'variant_id' => $variant->id,
379 ] 386 ]
380 ); 387 );
381 - 388 +
382 $row = $this->renderPartial( 389 $row = $this->renderPartial(
383 '_order_product', 390 '_order_product',
384 [ 391 [
@@ -389,20 +396,20 @@ @@ -389,20 +396,20 @@
389 'form' => $form, 396 'form' => $form,
390 ] 397 ]
391 ); 398 );
392 - 399 +
393 return [ 400 return [
394 'success' => true, 401 'success' => true,
395 'row' => $row, 402 'row' => $row,
396 'price' => $variant->price * $count, 403 'price' => $variant->price * $count,
397 ]; 404 ];
398 } 405 }
399 - 406 +
400 return [ 407 return [
401 'success' => false, 408 'success' => false,
402 'message' => \Yii::t('app', 'Product not found'), 409 'message' => \Yii::t('app', 'Product not found'),
403 ]; 410 ];
404 } 411 }
405 - 412 +
406 /** 413 /**
407 * Finds the Order model based on its primary key value. 414 * Finds the Order model based on its primary key value.
408 * If the model is not found, a 404 HTTP exception will be thrown. 415 * If the model is not found, a 404 HTTP exception will be thrown.
@@ -421,25 +428,29 @@ @@ -421,25 +428,29 @@
421 } 428 }
422 } 429 }
423 430
424 - public function actionPrint($id){ 431 + public function actionPrint($id)
  432 + {
425 $this->layout = false; 433 $this->layout = false;
426 $model = $this->findModel($id); 434 $model = $this->findModel($id);
427 - return $this->renderPartial('@backend/views/layouts/print', [  
428 - 'model' => $model  
429 - ]); 435 + return $this->renderPartial(
  436 + '@backend/views/layouts/print',
  437 + [
  438 + 'model' => $model,
  439 + ]
  440 + );
430 } 441 }
431 - 442 +
432 protected function hasProducts() 443 protected function hasProducts()
433 { 444 {
434 if (empty(\Yii::$app->request->post('OrderProduct'))) { 445 if (empty(\Yii::$app->request->post('OrderProduct'))) {
435 \Yii::$app->session->setFlash('error', \Yii::t('app', 'Заказ не может быть без товаров')); 446 \Yii::$app->session->setFlash('error', \Yii::t('app', 'Заказ не может быть без товаров'));
436 - 447 +
437 return false; 448 return false;
438 } 449 }
439 - 450 +
440 return true; 451 return true;
441 } 452 }
442 - 453 +
443 /** 454 /**
444 * @return array 455 * @return array
445 */ 456 */
@@ -461,7 +472,7 @@ @@ -461,7 +472,7 @@
461 ->indexBy('id') 472 ->indexBy('id')
462 ->column(); 473 ->column();
463 } 474 }
464 - 475 +
465 /** 476 /**
466 * @return array 477 * @return array
467 */ 478 */
@@ -483,7 +494,7 @@ @@ -483,7 +494,7 @@
483 ->indexBy('id') 494 ->indexBy('id')
484 ->column(); 495 ->column();
485 } 496 }
486 - 497 +
487 /** 498 /**
488 * @return array 499 * @return array
489 */ 500 */