diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 5c901f8..d64925c 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -113,7 +113,7 @@ public function actionCreate() { $model = new Order(); - + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect( [ diff --git a/controllers/OrderProductController.php b/controllers/OrderProductController.php index 7dee4c5..10ded5f 100755 --- a/controllers/OrderProductController.php +++ b/controllers/OrderProductController.php @@ -5,6 +5,7 @@ use artbox\order\models\OrderProductSearch; use Yii; use artbox\order\models\OrderProduct; + use yii\helpers\Html; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -21,7 +22,7 @@ public function behaviors() { return [ - 'verbs' => [ + 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => [ 'POST' ], @@ -171,4 +172,32 @@ throw new NotFoundHttpException('The requested page does not exist.'); } } + + public function actionAdd(int $variant_id, int $count = 1) + { + + $result = '
+
'; + + $result .= '
+
'; + $result .= Html::textInput( + 'Product[11994]', + 1, + [ + 'class' => 'form-control', + ] + ); + $result .= '
+
'; + $result .= Html::a( + '', + '#', + [ + 'class' => 'btn btn-primary', + ] + ); + $result .= '
+
'; + } } diff --git a/views/order/_form.php b/views/order/_form.php index 781c4c6..fc8a815 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -4,6 +4,7 @@ use yii\bootstrap\Html; use yii\helpers\Url; use yii\web\JsExpression; + use yii\web\View; use yii\widgets\ActiveForm; /** @@ -14,6 +15,29 @@ * @var array $payments * @var ActiveForm $form */ + + $js = <<< JS +$(document).on('click', '#create-add', function(e) { + e.preventDefault(); + var variant_id = $('#add-to-order').val(); + var count = $('#count-to-order').val(); + + $.ajax({ + url: '/admin/order-product/add', + type: "GET", + data: { + variant_id: variant_id, + count: count + }, + success: function(data) { + console.log(data); + } + }); +}); +JS; + + $this->registerJs($js, View::POS_READY); + ?>
@@ -184,7 +208,6 @@ -
'fa fa-', - ] - ), + '', '#', [ - 'class' => 'variant-to-order', - 'data-id' => $model->id, + 'class' => 'btn btn-success', + 'id' => 'create-add', ] ); ?>
+ +