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