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
controllers/OrderProductController.php
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | use artbox\order\models\OrderProductSearch; |
| 6 | 6 | use Yii; |
| 7 | 7 | use artbox\order\models\OrderProduct; |
| 8 | + use yii\helpers\Html; | |
| 8 | 9 | use yii\web\Controller; |
| 9 | 10 | use yii\web\NotFoundHttpException; |
| 10 | 11 | use yii\filters\VerbFilter; |
| ... | ... | @@ -21,7 +22,7 @@ |
| 21 | 22 | public function behaviors() |
| 22 | 23 | { |
| 23 | 24 | return [ |
| 24 | - 'verbs' => [ | |
| 25 | + 'verbs' => [ | |
| 25 | 26 | 'class' => VerbFilter::className(), |
| 26 | 27 | 'actions' => [ |
| 27 | 28 | 'delete' => [ 'POST' ], |
| ... | ... | @@ -171,4 +172,32 @@ |
| 171 | 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 | 4 | use yii\bootstrap\Html; |
| 5 | 5 | use yii\helpers\Url; |
| 6 | 6 | use yii\web\JsExpression; |
| 7 | + use yii\web\View; | |
| 7 | 8 | use yii\widgets\ActiveForm; |
| 8 | 9 | |
| 9 | 10 | /** |
| ... | ... | @@ -14,6 +15,29 @@ |
| 14 | 15 | * @var array $payments |
| 15 | 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 | 43 | <div class="order-form"> |
| ... | ... | @@ -184,7 +208,6 @@ |
| 184 | 208 | <?php |
| 185 | 209 | } else { |
| 186 | 210 | ?> |
| 187 | - | |
| 188 | 211 | <div class="row"> |
| 189 | 212 | <div class="col-md-8"> |
| 190 | 213 | <?php |
| ... | ... | @@ -218,7 +241,8 @@ |
| 218 | 241 | </div> |
| 219 | 242 | <div class="col-md-3"> |
| 220 | 243 | <?php |
| 221 | - echo Html::textInput( | |
| 244 | + echo Html::input( | |
| 245 | + 'number', | |
| 222 | 246 | 'count-to-order', |
| 223 | 247 | null, |
| 224 | 248 | [ |
| ... | ... | @@ -231,21 +255,18 @@ |
| 231 | 255 | <div class="col-md-1"> |
| 232 | 256 | <?php |
| 233 | 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 | 266 | </div> |
| 248 | 267 | </div> |
| 268 | + | |
| 269 | + <div id="products"></div> | |
| 249 | 270 | |
| 250 | 271 | <?php |
| 251 | 272 | } | ... | ... |