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 @@ + + +
+ = Html::a(Yii::t('app', 'Create Orders'), ['create'], ['class' => 'btn btn-success']) ?> +
+ = GridView::widget([ + 'dataProvider' => $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'], + ], + ]); ?> ++ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->order_id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->order_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'order_id', + 'customer_id', + 'name', + 'email:email', + 'phone', + 'delivery', + 'payment', + 'code', + 'status', + 'created_at', + 'updated_at', + ], + ]) ?> + +