diff --git a/controllers/OrderController.php b/controllers/OrderController.php
index d0ed4d3..bb72098 100755
--- a/controllers/OrderController.php
+++ b/controllers/OrderController.php
@@ -4,6 +4,7 @@
use artweb\artbox\ecommerce\models\OrderSearch;
use Yii;
+ use yii\helpers\Json;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\data\ActiveDataProvider;
@@ -141,13 +142,20 @@
{
$model = new Order();
+ $dataProvider = new ActiveDataProvider(
+ [
+ 'query' => $model->getProducts(),
+ ]
+ );
+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect([ 'index' ]);
} else {
return $this->render(
'create',
[
- 'model' => $model,
+ 'model' => $model,
+ 'dataProvider' => $dataProvider,
]
);
}
@@ -155,15 +163,44 @@
public function actionUpdate($id)
{
- $model = $this->findModel($id);
+ if (\Yii::$app->request->post('hasEditable'))
+ {
+ $orderProductId = \Yii::$app->request->post('editableKey');
+ $orderProduct = OrderProduct::findOne($orderProductId);
+ $out = Json::encode(['output'=>'', 'message'=>'']);
+
+ $posted = current(\Yii::$app->request->post('OrderProduct'));
+ $post = ['OrderProduct' => $posted];
+
+ if ($orderProduct->load($post))
+ {
+ $orderProduct->save();
+ $output = '';
+ if (isset($posted['count'])) {
+ $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0);
+ }
+ $out = Json::encode(['output'=>$output, 'message'=>'']);
+ }
+ return $out;
+ }
+
+ $model = $this->findModel($id);
+
+ $dataProvider = new ActiveDataProvider(
+ [
+ 'query' => $model->getProducts(),
+ ]
+ );
+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect([ 'index' ]);
} else {
return $this->render(
'update',
[
- 'model' => $model,
+ 'model' => $model,
+ 'dataProvider' => $dataProvider,
]
);
}
diff --git a/models/Order.php b/models/Order.php
index 80b586a..eed66cb 100755
--- a/models/Order.php
+++ b/models/Order.php
@@ -94,7 +94,6 @@
'declaration',
'stock',
'consignment',
- 'payment',
'insurance',
'amount_imposed',
'shipping_by',
@@ -106,6 +105,16 @@
'string',
'max' => 255,
],
+ [
+ [ 'payment' ],
+ 'in',
+ 'range' => [
+ 1,
+ 2,
+ 3,
+ 4,
+ ],
+ ],
];
}
@@ -259,7 +268,7 @@
{
$session = new Session;
$session->open();
- $session[ 'basket' ] = null;
+ $session[ 'basket' ] = NULL;
}
public function getUser()
diff --git a/views/order/_form.php b/views/order/_form.php
index 520bcfc..04c7271 100755
--- a/views/order/_form.php
+++ b/views/order/_form.php
@@ -1,19 +1,34 @@
+
+ = Html::submitButton(
+ $model->isNewRecord ? 'Create' : 'Update',
+ [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
+ ) ?>
+
+
+
@@ -51,13 +66,7 @@
= $form->field($model, 'payment')
->dropDownList(
- [
- 'Оплатить наличными' => 'Оплатить наличными',
- 'Оплатить на карту Приват Банка' => 'Оплатить на карту Приват Банка',
- 'Оплатить по безналичному расчету' => 'Оплатить по безналичному расчету',
- 'Оплатить Правекс-телеграф' => 'Оплатить Правекс-телеграф',
- 'Наложенным платежом' => 'Наложенным платежом',
- ],
+ ArrayHelper::getColumn(OrderFrontend::PAYMENT_LIST, 'label'),
[ 'prompt' => '...' ]
); ?>
@@ -94,13 +103,50 @@
-
-
- = Html::submitButton(
- $model->isNewRecord ? 'Create' : 'Update',
- [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
- ) ?>
+
+
+
+
+ $dataProvider,
+ 'columns' => [
+ 'id',
+ 'product_name',
+ 'sku',
+ [
+ 'class' => 'kartik\grid\EditableColumn',
+ 'attribute' => 'count',
+ 'editableOptions' => [
+ 'header' => \Yii::t('app', 'Количество'),
+ 'inputType' => kartik\editable\Editable::INPUT_SPIN,
+ 'options' => [
+ 'pluginOptions' => [
+ 'min' => 0,
+ 'max' => 5000,
+ ],
+ ],
+ ],
+ 'hAlign' => 'right',
+ 'vAlign' => 'middle',
+ 'width' => '7%',
+ 'format' => [
+ 'decimal',
+ 2,
+ ],
+ 'pageSummary' => true,
+ ],
+ [
+ 'class' => 'yii\grid\ActionColumn',
+ 'template' => '{delete}',
+ ],
+ ],
+ 'responsive' => true,
+ 'hover' => true,
+ ]
+ );
+ ?>
-
diff --git a/views/order/create.php b/views/order/create.php
index 7c29881..3866140 100755
--- a/views/order/create.php
+++ b/views/order/create.php
@@ -1,19 +1,32 @@
title = 'Добавить товар в заказ';
-$this->params['breadcrumbs'][] = ['label' => 'Pages', 'url' => ['index']];
-$this->params['breadcrumbs'][] = $this->title;
+ /**
+ * @var Order $model
+ * @var ActiveDataProvider $dataProvider
+ * @var View $this
+ */
+ use artweb\artbox\ecommerce\models\Order;
+ use yii\data\ActiveDataProvider;
+ use yii\helpers\Html;
+ use yii\web\View;
+
+ $this->title = 'Добавить товар в заказ';
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => 'Pages',
+ 'url' => [ 'index' ],
+ ];
+ $this->params[ 'breadcrumbs' ][] = $this->title;
?>
= Html::encode($this->title) ?>
-
- = $this->render('_form', [
- 'model' => $model,
- ]) ?>
+
+ = $this->render(
+ '_form',
+ [
+ 'model' => $model,
+ 'dataProvider' => $dataProvider,
+ 'pjax' => true,
+ ]
+ ) ?>
diff --git a/views/order/update.php b/views/order/update.php
index fb34af0..6f5f4cf 100755
--- a/views/order/update.php
+++ b/views/order/update.php
@@ -1,14 +1,16 @@
title = 'Заказ №' . $model->id;
+ $this->title = 'Заказ #' . $model->id;
$this->params[ 'breadcrumbs' ][] = $this->title;
?>
@@ -17,7 +19,8 @@
= $this->render(
'_form',
[
- 'model' => $model,
+ 'model' => $model,
+ 'dataProvider' => $dataProvider,
]
) ?>
\ No newline at end of file
--
libgit2 0.21.4