From e0906f08ec8110dfcfd48f12928d90b2111f4a59 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 21 Nov 2016 12:21:59 +0200 Subject: [PATCH] -Fixing existing order form bugs --- controllers/OrderController.php | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/order/_form.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/order/add.php | 30 ++++++++++++++++++++++++++++++ views/order/create.php | 19 +++++++++++++++++++ views/order/index.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/order/show.php | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/order/update.php | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 890 insertions(+), 0 deletions(-) create mode 100755 controllers/OrderController.php create mode 100755 views/order/_form.php create mode 100755 views/order/add.php create mode 100755 views/order/create.php create mode 100755 views/order/index.php create mode 100755 views/order/show.php create mode 100755 views/order/update.php diff --git a/controllers/OrderController.php b/controllers/OrderController.php new file mode 100755 index 0000000..c13f103 --- /dev/null +++ b/controllers/OrderController.php @@ -0,0 +1,175 @@ + [ + 'class' => AccessBehavior::className(), + 'rules' => [ + 'site' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + ]; + } + + public function actionIndex() + { + $searchModel = new OrderSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + 'searchModel' => $searchModel, + ] + ); + } + + public function actionShow($id) + { + + $model = $this->findModel((int) $id); + $dataProvider = new ActiveDataProvider( + [ + 'query' => OrderProduct::find() + ->where([ 'order_id' => (int) $id ]), + 'pagination' => [ + 'pageSize' => 20, + ], + ] + ); + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect([ 'index' ]); + } else { + $model_orderproduct = new OrderProduct(); + + return $this->renderAjax( + 'show', + [ + 'model' => $model, + 'model_orderproduct' => $model_orderproduct, + 'dataProvider' => $dataProvider, + ] + ); + } + } + + public function actionLabelUpdate() + { + $model = Order::findOne($_POST[ 'order_id' ]); + $model->label = $_POST[ 'label_id' ]; + $model->save(); + } + + public function actionPayUpdate() + { + $model = Order::findOne($_POST[ 'order_id' ]); + $model->pay = $_POST[ 'pay_id' ]; + $model->save(); + } + + public function actionDelete() + { + $model = Order::findOne($_GET[ 'id' ]); + $model->delete(); + return Yii::$app->response->redirect([ '/order/index' ]); + } + + public function actionAdd() + { + $model = new OrderProduct(); + if ($model->load(Yii::$app->request->post())) { + /** + * @var ProductVariant $modelMod + */ + if (!$modelMod = ProductVariant::find() + ->with('product.lang') + ->with('lang') + ->where([ 'sku' => $model->sku ]) + ->one() + ) { + throw new HttpException(404, 'Данного артикля не существует!'); + } + $model->product_name = $modelMod->product->lang->title; + $model->name = $modelMod->lang->title; + $model->sku = $modelMod->sku; + $model->price = $modelMod->price; + $model->sum_cost = $model->count * $modelMod->price; + $model->product_variant_id = $modelMod->id; + $model->save(); + //return Yii::$app->response->redirect(['/admin/order/show','id'=>$_GET['order_id']]); + } + + //return $this->render('add',['model'=>$model]); + } + + public function actionCreate() + { + $model = new Order(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect([ 'index' ]); + } else { + return $this->render( + 'create', + [ + 'model' => $model, + ] + ); + } + } + + public function actionDeleteProduct($id) + { + $model = OrderProduct::findOne($id); + $model->delete(); + return Yii::$app->response->redirect( + [ + 'ecommerce/order', + ] + ); + } + + protected function findModel($id) + { + if (( $model = Order::findOne($id) ) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + } diff --git a/views/order/_form.php b/views/order/_form.php new file mode 100755 index 0000000..8e24e2c --- /dev/null +++ b/views/order/_form.php @@ -0,0 +1,91 @@ + + + +
+
+ + + field($model, 'name') ?> + + field($model, 'phone') ?> + + field($model, 'phone2') ?> + + field($model, 'email') ?> + + field($model, 'numbercard') ?> + + field($model, 'body') + ->textarea([ 'rows' => '3' ]) ?> + + field($model, 'delivery')->dropDownList(ArrayHelper::map(Delivery::find()->asArray()->all(), 'id', 'title')) */ ?> + + field($model, 'declaration') ?> + + field($model, 'stock') ?> + + field($model, 'consignment') ?> +
+
+ + field($model, 'payment') + ->dropDownList( + [ + 'Оплатить наличными' => 'Оплатить наличными', + 'Оплатить на карту Приват Банка' => 'Оплатить на карту Приват Банка', + 'Оплатить по безналичному расчету' => 'Оплатить по безналичному расчету', + 'Оплатить Правекс-телеграф' => 'Оплатить Правекс-телеграф', + 'Наложенным платежом' => 'Наложенным платежом', + ], + [ 'prompt' => '...' ] + ); ?> + + field($model, 'insurance') ?> + + field($model, 'amount_imposed') ?> + + field($model, 'shipping_by') ?> + + field($model, 'city') ?> + + field($model, 'adress') ?> + + + field($model, 'total') ?> + + field($model, 'status') + ->dropDownList( + [ + 'Нет' => 'Нет', + 'Обработан' => 'Обработан', + 'На комплектации' => 'На комплектации', + 'Укомплектован' => 'Укомплектован', + 'Доставка' => 'Доставка', + 'Выполнен' => 'Выполнен', + 'Резерв оплачен' => 'Резерв оплачен', + 'Резерв неоплачен' => 'Резерв неоплачен', + ], + [ 'prompt' => '...' ] + ); ?> + + field($model, 'comment') + ->textarea([ 'rows' => '3' ]) ?> +
+
+
+ isNewRecord ? 'Create' : 'Update', + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
+ + diff --git a/views/order/add.php b/views/order/add.php new file mode 100755 index 0000000..912df76 --- /dev/null +++ b/views/order/add.php @@ -0,0 +1,30 @@ +title = 'Добавить товар в заказ'; +$this->params['breadcrumbs'][] = $this->title; +?> +

Добавить товар в заказ

+ + 'reg-form', + 'options' => ['class' => 'form-vertical','enctype' => 'multipart/form-data'], + 'fieldConfig' => [ + //'template' => "{label}\n
{input}
\n
{error}
", + //'labelOptions' => ['class' => 'col-lg-2 control-label'], + ], + ]); ?> + +field($model, 'art') ?> + +field($model, 'count') ?> + + field($model, 'order_id')->hiddenInput(['value'=>$_GET['order_id']])->label(false); ?> + +
+ 'btn btn-primary', 'name' => 'login-button']) ?> +
+ \ No newline at end of file diff --git a/views/order/create.php b/views/order/create.php new file mode 100755 index 0000000..7c29881 --- /dev/null +++ b/views/order/create.php @@ -0,0 +1,19 @@ +title = 'Добавить товар в заказ'; +$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> +
+ diff --git a/views/order/index.php b/views/order/index.php new file mode 100755 index 0000000..0fac670 --- /dev/null +++ b/views/order/index.php @@ -0,0 +1,107 @@ +title = 'Заказы'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +

Заказы

+

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + + [ + 'attribute' => 'id', + 'format' => 'raw', + 'options' => [ 'class' => 'btn btn-warning' ], + 'value' => function ($model) { + return Html::button($model->id, + [ + 'id' => $model->id, + 'class' => 'btn btn-warning', + ] + ); + + }, + + ], + [ + 'attribute' => 'date_time', + 'value' => 'date_time', + ], + + [ + 'attribute' => 'name', + 'value' => 'name', + 'format' => 'raw', + ], + [ + 'attribute' => 'phone', + 'value' => 'phone', + ], + // [ + // 'attribute' => 'total', + // 'value'=>'total', + // ], + // [ + // 'filter' => yii\helpers\ArrayHelper::map(Label::find()->orderBy('id')->asArray()->all(), 'id', 'label'), + // 'attribute' => 'label', + // 'value' => function ($model, $key, $index, $column) { + // return Html::activeDropDownList($model, 'label', + // yii\helpers\ArrayHelper::map(Label::find()->orderBy('id')->asArray()->all(), 'id', 'label'), + // [ + // 'prompt' => 'Нет', + // 'onchange' => "$.ajax({ + // url: \"/admin/order/label-update\", + // type: \"post\", + // data: { order_id: $model->id, label_id : this.value}, + // });" + // ] + // + // ); + // }, + // 'format' => 'raw', + // ], + // [ + // 'attribute' => 'pay', + // 'filter' => [ + // 0 => 'Нет',1=>'Да' + // ], + // 'value' => function ($model, $key, $index, $column) { + // return Html::activeDropDownList($model, 'pay',[0 => 'Нет',1=>'Да'], + // [ + // 'onchange' => "$.ajax({ + // url: \"/admin/order/pay-update\", + // type: \"post\", + // data: { order_id: $model->id, pay_id : this.value}, + // });" + // ] + // + // ); + // }, + // 'format' => 'raw', + // ], + [ + 'attribute' => 'status', + 'value' => 'status', + 'contentOptions' => [ 'style' => 'width: 5px;' ], + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{delete}', + 'contentOptions' => [ 'style' => 'width: 70px;' ], + ], + ], + ] +) ?> + \ No newline at end of file diff --git a/views/order/show.php b/views/order/show.php new file mode 100755 index 0000000..da33ac7 --- /dev/null +++ b/views/order/show.php @@ -0,0 +1,255 @@ +title = 'Заказ №' . $model->id; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ + + +
+ Заказ успешно сохранен! +
+ + + 'reg-form', + 'layout' => 'horizontal', + 'options' => [ 'enctype' => 'multipart/form-data' ], + 'fieldConfig' => [ + //'template' => "{label}\n
{input}
\n
{error}
", + //'labelOptions' => ['class' => 'col-lg-2 control-label'], + ], + 'action' => [ + 'order/show', + 'id' => $model->id, + ], + ] + ); ?> + +
+
+
+
Заказ №id ?>
+ + date_time ?> +
+ + field($model, 'date_dedline') + ->widget(DatePicker::className(), [ + 'pluginOptions' => [ + 'format' => 'dd-mm-yyyy', + 'todayHighlight' => true + ]]); */ ?> +
+
+ field($model, 'name') ?> + + + field($model, 'phone') ?> + + field($model, 'phone2'); ?> + + field($model, 'email') ?> + + field($model, 'numbercard'); ?> + + field($model, 'body') + ->textarea([ 'rows' => '3' ]); ?> +
+
+ field($model, 'delivery') + ->dropDownList( + ArrayHelper::map( + Delivery::find() + ->joinWith('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ) + ); ?> + + field($model, 'declaration'); ?> + + field($model, 'stock'); ?> + + field($model, 'consignment'); ?> + + field($model, 'payment') + ->dropDownList( + [ + 'Оплатить наличными' => 'Оплатить наличными', + 'Оплатить на карту Приват Банка' => 'Оплатить на карту Приват Банка', + 'Оплатить по безналичному расчету' => 'Оплатить по безналичному расчету', + 'Оплатить Правекс-телеграф' => 'Оплатить Правекс-телеграф', + 'Наложенным платежом' => 'Наложенным платежом', + ], + [ 'prompt' => '...' ] + ); ?> + + field($model, 'insurance'); ?> + + field($model, 'amount_imposed'); ?> + + field($model, 'shipping_by'); ?> + + field($model, 'city'); + + echo $form->field($model, 'adress'); + + echo $form->field($model, 'total'); + + echo $form->field($model, 'status') + ->dropDownList( + [ + 'Нет' => 'Нет', + 'Обработан' => 'Обработан', + 'На комплектации' => 'На комплектации', + 'Укомплектован' => 'Укомплектован', + 'Доставка' => 'Доставка', + 'Выполнен' => 'Выполнен', + 'Резерв оплачен' => 'Резерв оплачен', + 'Резерв неоплачен' => 'Резерв неоплачен', + ], + [ 'prompt' => '...' ] + ); ?> + + field($model, 'comment') + ->textarea([ 'rows' => '3' ]) ?> +
+
+
+ +
+   + + + $dataProvider, + 'columns' => [ + [ + 'attribute' => 'id', + 'value' => 'id', + ], + [ + 'attribute' => 'sku', + 'value' => 'sku', + ], + [ + 'attribute' => 'product_name', + 'value' => 'product_name', + ], + // [ + // 'attribute' => 'size', + // 'value'=>'mod.size', + // 'contentOptions'=>['style'=>'width: 100px;'] + // ], + // [ + // 'attribute' => 'size', + // 'value'=>'mod.color', + // 'contentOptions'=>['style'=>'width: 100px;'] + // ], + [ + 'attribute' => 'price', + 'value' => 'price', + ], + [ + 'attribute' => 'count', + 'value' => 'count', + ], + [ + 'attribute' => 'sum_cost', + 'value' => 'sum_cost', + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{delete}', + 'buttons' => [ + 'delete' => function($url, $model) { + return Html::a( + '', + [ + 'order/delete-product', + 'id' => $model->id, + 'order_id' => (int)\Yii::$app->request->get('id'), + ], + [ + 'class' => 'delete-ajax' + ] + ); + }, + ], + ], + + ], + ] + ) ?> +
+ 'btn btn-primary btn-lg btn-block', + 'name' => 'login-button', + ] + ) ?> +
+ + + +
+
+

Добавить товар в заказ

+ + false, + 'id' => 'add_mod', + 'options' => [ + 'class' => 'form-vertical', + 'enctype' => 'multipart/form-data', + ], + 'fieldConfig' => [ + //'template' => "{label}\n
{input}
\n
{error}
", + //'labelOptions' => ['class' => 'col-lg-2 control-label'], + ], + ] + ); ?> + + field($model_orderproduct, 'sku') ?> + + field($model_orderproduct, 'count') ?> + + field($model_orderproduct, 'order_id') + ->hiddenInput([ 'value' => $model->id ]) + ->label(false); ?> + +
+ 'btn btn-primary', + 'name' => 'login-button', + ] + ) ?> +
+ +
+
+ +
+ + + diff --git a/views/order/update.php b/views/order/update.php new file mode 100755 index 0000000..106413c --- /dev/null +++ b/views/order/update.php @@ -0,0 +1,213 @@ +title = 'Заказ №' . $model->id; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +

Заказ №id ?>

+ + +
+ Заказ успешно сохранен! +
+ + + 'reg-form', + 'layout' => 'horizontal', + 'options' => [ 'enctype' => 'multipart/form-data' ], + 'fieldConfig' => [ + //'template' => "{label}\n
{input}
\n
{error}
", + //'labelOptions' => ['class' => 'col-lg-2 control-label'], + ], + ] +); ?> + + +
+
+ + date_time ?> +
+ field($model, 'date_dedline') + ->widget( + \yii\jui\DatePicker::className(), + [ + 'clientOptions' => [], + 'options' => [ + 'class' => 'form-control', + 'style' => 'width:150px;', + ], + 'dateFormat' => 'yyyy-MM-dd', + ] + ) ?> + + field($model, 'surname') ?> + + field($model, 'name') ?> + + field($model, 'patronymic') ?> + + field($model, 'phone') ?> + + field($model, 'phone2') ?> + + field($model, 'email') ?> + + field($model, 'numbercard') ?> + + field($model, 'delivery') + ->dropDownList( + ArrayHelper::map( + Delivery::find() + ->asArray() + ->all(), + 'id', + 'title' + ) + ) ?> + + field($model, 'declaration') ?> + + field($model, 'stock') ?> + + field($model, 'consignment') ?> +
+
+ field($model, 'payment') + ->dropDownList( + [ + 'Оплатить наличными' => 'Оплатить наличными', + 'Оплатить на карту Приват Банка' => 'Оплатить на карту Приват Банка', + 'Оплатить по безналичному расчету' => 'Оплатить по безналичному расчету', + 'Оплатить Правекс-телеграф' => 'Оплатить Правекс-телеграф', + 'Наложенным платежом' => 'Наложенным платежом', + ], + [ 'prompt' => '...' ] + ); ?> + + field($model, 'insurance') ?> + + field($model, 'amount_imposed') ?> + + field($model, 'shipping_by') ?> + + field($model, 'city') ?> + + field($model, 'adress') ?> + + field($model, 'body') + ->textArea([ 'rows' => '6' ]) ?> + + field($model, 'total') ?> + + field($model, 'status') + ->dropDownList( + [ + 'Нет' => 'Нет', + 'Обработан' => 'Обработан', + 'На комплектации' => 'На комплектации', + 'Укомплектован' => 'Укомплектован', + 'Доставка' => 'Доставка', + 'Выполнен' => 'Выполнен', + 'Резерв оплачен' => 'Резерв оплачен', + 'Резерв неоплачен' => 'Резерв неоплачен', + ], + [ 'prompt' => '...' ] + ); ?> + + field($model, 'comment') + ->textArea([ 'rows' => '6' ]) ?> +
+
+ 'btn btn-primary btn-lg btn-block', + 'name' => 'login-button', + ] + ) ?> +
+ + +
+ $model->id, + ], + [ 'class' => 'btn btn-success' ] +) ?> + $dataProvider, + 'columns' => [ + [ + 'attribute' => 'id', + 'value' => 'id', + 'contentOptions' => [ 'style' => 'width: 70px;' ], + ], + [ + 'attribute' => 'art', + 'value' => 'art', + 'contentOptions' => [ 'style' => 'width: 50px;' ], + ], + [ + 'attribute' => 'product_name', + 'value' => 'product_name', + //'contentOptions'=>['style'=>'max-width: 300px;'] + ], + [ + 'attribute' => 'name', + 'value' => 'name', + //'contentOptions'=>['style'=>'max-width: 300px;'] + ], + [ + 'attribute' => 'cost', + 'value' => 'cost', + 'contentOptions' => [ 'style' => 'width: 100px;' ], + ], + [ + 'attribute' => 'count', + 'value' => 'count', + 'contentOptions' => [ 'style' => 'width: 30px;' ], + ], + [ + 'attribute' => 'sum_cost', + 'value' => 'sum_cost', + 'contentOptions' => [ 'style' => 'width: 100px;' ], + ], + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{delete}', + 'contentOptions' => [ 'style' => 'width: 20px;' ], + 'buttons' => [ + 'delete' => function ($url, $model) { + return Html::a( + '', + [ + '/admin/order/delete_product', + 'id' => $model->id, + 'order_id' => $_GET[ 'id' ], + ], + [ + 'title' => "Удалить", + 'data-confirm' => 'Удалить?', + ] + ); + }, + ], + ], + + ], + ] +) ?> + + + -- libgit2 0.21.4