Commit 0b5518db0b5dc2b5141031b521978faf652a569e
1 parent
b12f37d7
-Order products half way done
Showing
3 changed files
with
62 additions
and
12 deletions
Show diff stats
controllers/OrderController.php
| @@ -113,7 +113,7 @@ | @@ -113,7 +113,7 @@ | ||
| 113 | public function actionCreate() | 113 | public function actionCreate() |
| 114 | { | 114 | { |
| 115 | $model = new Order(); | 115 | $model = new Order(); |
| 116 | - | 116 | + |
| 117 | if ($model->load(Yii::$app->request->post()) && $model->save()) { | 117 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 118 | return $this->redirect( | 118 | return $this->redirect( |
| 119 | [ | 119 | [ |
controllers/OrderProductController.php
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | use artbox\order\models\OrderProductSearch; | 5 | use artbox\order\models\OrderProductSearch; |
| 6 | use Yii; | 6 | use Yii; |
| 7 | use artbox\order\models\OrderProduct; | 7 | use artbox\order\models\OrderProduct; |
| 8 | + use yii\helpers\Html; | ||
| 8 | use yii\web\Controller; | 9 | use yii\web\Controller; |
| 9 | use yii\web\NotFoundHttpException; | 10 | use yii\web\NotFoundHttpException; |
| 10 | use yii\filters\VerbFilter; | 11 | use yii\filters\VerbFilter; |
| @@ -21,7 +22,7 @@ | @@ -21,7 +22,7 @@ | ||
| 21 | public function behaviors() | 22 | public function behaviors() |
| 22 | { | 23 | { |
| 23 | return [ | 24 | return [ |
| 24 | - 'verbs' => [ | 25 | + 'verbs' => [ |
| 25 | 'class' => VerbFilter::className(), | 26 | 'class' => VerbFilter::className(), |
| 26 | 'actions' => [ | 27 | 'actions' => [ |
| 27 | 'delete' => [ 'POST' ], | 28 | 'delete' => [ 'POST' ], |
| @@ -171,4 +172,32 @@ | @@ -171,4 +172,32 @@ | ||
| 171 | throw new NotFoundHttpException('The requested page does not exist.'); | 172 | throw new NotFoundHttpException('The requested page does not exist.'); |
| 172 | } | 173 | } |
| 173 | } | 174 | } |
| 175 | + | ||
| 176 | + public function actionAdd(int $variant_id, int $count = 1) | ||
| 177 | + { | ||
| 178 | + | ||
| 179 | + $result = '<div class="row"> | ||
| 180 | + <div class="col-md-8">'; | ||
| 181 | + | ||
| 182 | + $result .= '</div> | ||
| 183 | + <div class="col-md-3">'; | ||
| 184 | + $result .= Html::textInput( | ||
| 185 | + 'Product[11994]', | ||
| 186 | + 1, | ||
| 187 | + [ | ||
| 188 | + 'class' => 'form-control', | ||
| 189 | + ] | ||
| 190 | + ); | ||
| 191 | + $result .= '</div> | ||
| 192 | +<div class="col-md-1">'; | ||
| 193 | + $result .= Html::a( | ||
| 194 | + '<i class="fa fa-trash"></i>', | ||
| 195 | + '#', | ||
| 196 | + [ | ||
| 197 | + 'class' => 'btn btn-primary', | ||
| 198 | + ] | ||
| 199 | + ); | ||
| 200 | + $result .= '</div> | ||
| 201 | +</div>'; | ||
| 202 | + } | ||
| 174 | } | 203 | } |
views/order/_form.php
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | use yii\bootstrap\Html; | 4 | use yii\bootstrap\Html; |
| 5 | use yii\helpers\Url; | 5 | use yii\helpers\Url; |
| 6 | use yii\web\JsExpression; | 6 | use yii\web\JsExpression; |
| 7 | + use yii\web\View; | ||
| 7 | use yii\widgets\ActiveForm; | 8 | use yii\widgets\ActiveForm; |
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| @@ -14,6 +15,29 @@ | @@ -14,6 +15,29 @@ | ||
| 14 | * @var array $payments | 15 | * @var array $payments |
| 15 | * @var ActiveForm $form | 16 | * @var ActiveForm $form |
| 16 | */ | 17 | */ |
| 18 | + | ||
| 19 | + $js = <<< JS | ||
| 20 | +$(document).on('click', '#create-add', function(e) { | ||
| 21 | + e.preventDefault(); | ||
| 22 | + var variant_id = $('#add-to-order').val(); | ||
| 23 | + var count = $('#count-to-order').val(); | ||
| 24 | + | ||
| 25 | + $.ajax({ | ||
| 26 | + url: '/admin/order-product/add', | ||
| 27 | + type: "GET", | ||
| 28 | + data: { | ||
| 29 | + variant_id: variant_id, | ||
| 30 | + count: count | ||
| 31 | + }, | ||
| 32 | + success: function(data) { | ||
| 33 | + console.log(data); | ||
| 34 | + } | ||
| 35 | + }); | ||
| 36 | +}); | ||
| 37 | +JS; | ||
| 38 | + | ||
| 39 | + $this->registerJs($js, View::POS_READY); | ||
| 40 | + | ||
| 17 | ?> | 41 | ?> |
| 18 | 42 | ||
| 19 | <div class="order-form"> | 43 | <div class="order-form"> |
| @@ -184,7 +208,6 @@ | @@ -184,7 +208,6 @@ | ||
| 184 | <?php | 208 | <?php |
| 185 | } else { | 209 | } else { |
| 186 | ?> | 210 | ?> |
| 187 | - | ||
| 188 | <div class="row"> | 211 | <div class="row"> |
| 189 | <div class="col-md-8"> | 212 | <div class="col-md-8"> |
| 190 | <?php | 213 | <?php |
| @@ -218,7 +241,8 @@ | @@ -218,7 +241,8 @@ | ||
| 218 | </div> | 241 | </div> |
| 219 | <div class="col-md-3"> | 242 | <div class="col-md-3"> |
| 220 | <?php | 243 | <?php |
| 221 | - echo Html::textInput( | 244 | + echo Html::input( |
| 245 | + 'number', | ||
| 222 | 'count-to-order', | 246 | 'count-to-order', |
| 223 | null, | 247 | null, |
| 224 | [ | 248 | [ |
| @@ -231,21 +255,18 @@ | @@ -231,21 +255,18 @@ | ||
| 231 | <div class="col-md-1"> | 255 | <div class="col-md-1"> |
| 232 | <?php | 256 | <?php |
| 233 | echo Html::a( | 257 | echo Html::a( |
| 234 | - Html::icon( | ||
| 235 | - 'plus-circle', | ||
| 236 | - [ | ||
| 237 | - 'prefix' => 'fa fa-', | ||
| 238 | - ] | ||
| 239 | - ), | 258 | + '<i class="fa fa-plus"></i>', |
| 240 | '#', | 259 | '#', |
| 241 | [ | 260 | [ |
| 242 | - 'class' => 'variant-to-order', | ||
| 243 | - 'data-id' => $model->id, | 261 | + 'class' => 'btn btn-success', |
| 262 | + 'id' => 'create-add', | ||
| 244 | ] | 263 | ] |
| 245 | ); | 264 | ); |
| 246 | ?> | 265 | ?> |
| 247 | </div> | 266 | </div> |
| 248 | </div> | 267 | </div> |
| 268 | + | ||
| 269 | + <div id="products"></div> | ||
| 249 | 270 | ||
| 250 | <?php | 271 | <?php |
| 251 | } | 272 | } |