diff --git a/backend/controllers/OrdersController.php b/backend/controllers/OrdersController.php new file mode 100644 index 0000000..1b57061 --- /dev/null +++ b/backend/controllers/OrdersController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Orders models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new OrdersSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Orders model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Orders model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Orders(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->order_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Orders model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->order_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Orders model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Orders model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Orders the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Orders::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index 42d6851..840cc2c 100644 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -39,7 +39,7 @@ use yii\widgets\Menu; ['label' => 'Создать', 'url' => ['blog/create']], ], ], - ['label' => 'Заказы', 'url' => ['cart/index'], 'template'=>' {label}'], + ['label' => 'Заказы', 'url' => ['orders/index'], 'template'=>' {label}'], [ 'label' => 'Products', 'url' => ['/product/manage'], diff --git a/backend/views/orders/_form.php b/backend/views/orders/_form.php new file mode 100644 index 0000000..5071223 --- /dev/null +++ b/backend/views/orders/_form.php @@ -0,0 +1,41 @@ + + +
+ + + + field($model, 'customer_id')->textInput() ?> + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'email')->textInput(['maxlength' => true]) ?> + + field($model, 'phone')->textInput(['maxlength' => true]) ?> + + field($model, 'delivery')->textInput() ?> + + field($model, 'payment')->textInput() ?> + + field($model, 'code')->textInput(['maxlength' => true]) ?> + + field($model, 'status')->textInput() ?> + + field($model, 'created_at')->textInput() ?> + + field($model, 'updated_at')->textInput() ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/orders/_search.php b/backend/views/orders/_search.php new file mode 100644 index 0000000..665ffd8 --- /dev/null +++ b/backend/views/orders/_search.php @@ -0,0 +1,47 @@ + + + diff --git a/backend/views/orders/create.php b/backend/views/orders/create.php new file mode 100644 index 0000000..2862711 --- /dev/null +++ b/backend/views/orders/create.php @@ -0,0 +1,21 @@ +title = Yii::t('app', 'Create Orders'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Orders'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/orders/index.php b/backend/views/orders/index.php new file mode 100644 index 0000000..66f25b7 --- /dev/null +++ b/backend/views/orders/index.php @@ -0,0 +1,42 @@ +title = Yii::t('app', 'Orders'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'order_id', + 'customer_id', + 'name', + 'email:email', + 'phone', + // 'delivery', + // 'payment', + // 'code', + // 'status', + // 'created_at', + // 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/views/orders/update.php b/backend/views/orders/update.php new file mode 100644 index 0000000..2f0f5d7 --- /dev/null +++ b/backend/views/orders/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Orders', +]) . ' ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Orders'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->order_id]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/orders/view.php b/backend/views/orders/view.php new file mode 100644 index 0000000..d25be9b --- /dev/null +++ b/backend/views/orders/view.php @@ -0,0 +1,45 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Orders'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->order_id], ['class' => 'btn btn-primary']) ?> + $model->order_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'order_id', + 'customer_id', + 'name', + 'email:email', + 'phone', + 'delivery', + 'payment', + 'code', + 'status', + 'created_at', + 'updated_at', + ], + ]) ?> + +
diff --git a/backend/views/site/login.php b/backend/views/site/login.php index 20f3f78..11e8c4b 100644 --- a/backend/views/site/login.php +++ b/backend/views/site/login.php @@ -19,7 +19,7 @@ $this->params['breadcrumbs'][] = $this->title;
'login-form']); ?> - field($model, 'username')->textInput(['autofocus' => true]) ?> + field($model, 'email')->textInput(['autofocus' => true]) ?> field($model, 'password')->passwordInput() ?> diff --git a/common/models/OrdersSearch.php b/common/models/OrdersSearch.php new file mode 100644 index 0000000..48efed8 --- /dev/null +++ b/common/models/OrdersSearch.php @@ -0,0 +1,78 @@ + $query, + ]); + + $this->load($params); + + 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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'order_id' => $this->order_id, + 'customer_id' => $this->customer_id, + 'delivery' => $this->delivery, + 'payment' => $this->payment, + 'status' => $this->status, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'email', $this->email]) + ->andFilterWhere(['like', 'phone', $this->phone]) + ->andFilterWhere(['like', 'code', $this->code]); + + return $dataProvider; + } +} -- libgit2 0.21.4