diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 8227f91..3bcd122 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -1,7 +1,7 @@ [ + 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => [ 'POST' ], @@ -57,15 +57,18 @@ ], ]; } - + public function actions() { return [ 'index' => [ 'class' => Index::className(), 'columns' => [ + 'id' => [ + 'type' => Index::NUMBER_COL, + ], 'name' => [ - 'type' => Index::ACTION_COL, + 'type' => Index::ACTION_COL, 'columnConfig' => [ 'buttonsTemplate' => '{edit}{delete}', ], @@ -93,7 +96,7 @@ ], ]; } - + /** * Displays a single Order model. * @@ -110,7 +113,7 @@ ] ); } - + /** * Creates a new Order model. * If creation is successful, the browser will be redirected to the 'view' page. @@ -120,7 +123,7 @@ public function actionCreate() { $model = new Order(); - + if ($model->load(Yii::$app->request->post()) && $model->save()) { if (!empty(\Yii::$app->request->post('Product'))) { foreach (\Yii::$app->request->post('Product') as $id => $count) { @@ -153,46 +156,46 @@ $labels = Label::find() ->joinWith('language') ->select( - [ - 'title', - 'id', - ] - ) + [ + 'title', + 'id', + ] + ) ->where( - [ - 'status' => true, - ] - ) + [ + 'status' => true, + ] + ) ->indexBy('id') ->column(); $deliveries = Delivery::find() ->joinWith('language') ->select( - [ - 'title', - 'id', - ] - ) + [ + 'title', + 'id', + ] + ) ->where( - [ - 'status' => true, - ] - ) + [ + 'status' => true, + ] + ) ->indexBy('id') ->column(); $payments = Payment::find() ->joinWith('language') ->select( - [ - 'title', - 'id', - ] - ) + [ + 'title', + 'id', + ] + ) ->where( - [ - 'status' => true, - ] - ) + [ + 'status' => true, + ] + ) ->indexBy('id') ->column(); return $this->render( @@ -206,7 +209,7 @@ ); } } - + /** * Updates an existing Order model. * If update is successful, the browser will be redirected to the 'view' page. @@ -218,9 +221,13 @@ public function actionUpdate($id) { $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save() && !empty(\Yii::$app->request->post('OrderProduct'))) { - //print_r(\Yii::$app->request->post('OrderProduct')); die(); + + if ($model->load(Yii::$app->request->post()) && $model->save() && !empty( + \Yii::$app->request->post( + 'OrderProduct' + ) + )) { + //print_r(\Yii::$app->request->post('OrderProduct')); die(); OrderProduct::saveItems(\Yii::$app->request->post('OrderProduct'), $id); return $this->redirect( [ @@ -247,31 +254,31 @@ $deliveries = Delivery::find() ->joinWith('language') ->select( - [ - 'title', - 'id', - ] - ) + [ + 'title', + 'id', + ] + ) ->where( - [ - 'status' => true, - ] - ) + [ + 'status' => true, + ] + ) ->indexBy('id') ->column(); $payments = Payment::find() ->joinWith('language') ->select( - [ - 'title', - 'id', - ] - ) + [ + 'title', + 'id', + ] + ) ->where( - [ - 'status' => true, - ] - ) + [ + 'status' => true, + ] + ) ->indexBy('id') ->column(); return $this->render( @@ -285,7 +292,7 @@ ); } } - + /** * Deletes an existing Order model. * If deletion is successful, the browser will be redirected to the 'index' page. @@ -298,10 +305,10 @@ { $this->findModel($id) ->delete(); - + return $this->redirect([ 'index' ]); } - + public function actionProductList($q = null, $id = null) { $response = \Yii::$app->response; @@ -349,7 +356,7 @@ } return $out; } - + public function actionAddToOrder() { /** @@ -360,7 +367,7 @@ \Yii::$app->response->format = Response::FORMAT_JSON; $id = \Yii::$app->request->post('id'); $count = \Yii::$app->request->post('count') ? \Yii::$app->request->post('count') : 1; - + $variant = Variant::find() ->with('product.lang') ->where( @@ -369,7 +376,7 @@ ] ) ->one(); - + if ($variant) { $form = new ActiveForm(); $orderProduct = new OrderProduct( @@ -378,7 +385,7 @@ 'variant_id' => $variant->id, ] ); - + $row = $this->renderPartial( '_order_product', [ @@ -389,20 +396,20 @@ 'form' => $form, ] ); - + return [ 'success' => true, 'row' => $row, 'price' => $variant->price * $count, ]; } - + return [ 'success' => false, 'message' => \Yii::t('app', 'Product not found'), ]; } - + /** * Finds the Order model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. @@ -421,25 +428,29 @@ } } - public function actionPrint($id){ + public function actionPrint($id) + { $this->layout = false; $model = $this->findModel($id); - return $this->renderPartial('@backend/views/layouts/print', [ - 'model' => $model - ]); + return $this->renderPartial( + '@backend/views/layouts/print', + [ + 'model' => $model, + ] + ); } - + protected function hasProducts() { if (empty(\Yii::$app->request->post('OrderProduct'))) { \Yii::$app->session->setFlash('error', \Yii::t('app', 'Заказ не может быть без товаров')); - + return false; } - + return true; } - + /** * @return array */ @@ -461,7 +472,7 @@ ->indexBy('id') ->column(); } - + /** * @return array */ @@ -483,7 +494,7 @@ ->indexBy('id') ->column(); } - + /** * @return array */ -- libgit2 0.21.4