Commit b6db17e590e12ba7b2534985f406c6ecd593c558
1 parent
72ce46f7
order in admin
Showing
3 changed files
with
49 additions
and
7 deletions
Show diff stats
controllers/OrderController.php
... | ... | @@ -404,6 +404,22 @@ |
404 | 404 | return $sum; |
405 | 405 | } |
406 | 406 | |
407 | + public function actionDeleteFromOrder() | |
408 | + { | |
409 | + $id = \Yii::$app->request->post('id'); | |
410 | + $variant = \Yii::$app->request->post('variant'); | |
411 | + $product = OrderProduct::find() | |
412 | + ->where( | |
413 | + [ | |
414 | + 'order_id' => $id, | |
415 | + 'variant_id' => $variant, | |
416 | + ] | |
417 | + ) | |
418 | + ->one() | |
419 | + ->delete(); | |
420 | + return 'ok'; | |
421 | + } | |
422 | + | |
407 | 423 | /** |
408 | 424 | * Finds the Order model based on its primary key value. |
409 | 425 | * If the model is not found, a 404 HTTP exception will be thrown. | ... | ... |
views/order/_form.php
web/js/order.js
... | ... | @@ -4,13 +4,35 @@ $(function() { |
4 | 4 | e.preventDefault(); |
5 | 5 | var current_price = parseInt($(this).parents('.row-order-product').data('price')); |
6 | 6 | var number = parseInt($(this).parents('.row-order-product').children('.col-md-3').children('.form-group').children('input').val()); |
7 | - $(this) | |
8 | - .parents('.row-order-product') | |
9 | - .remove(); | |
10 | - var total_price = parseInt($(".sum_all").children('p').text()); | |
11 | - total_price = total_price - (current_price * number); | |
12 | - console.log(number); | |
13 | - $(".sum_all").children('p').text(total_price); | |
7 | + var id = $(this) | |
8 | + .data('id'); | |
9 | + var variant = $(this) | |
10 | + .data('variant'); | |
11 | + var selector = '#order-product-pjax'; | |
12 | + $.post('/admin/order/delete-from-order', { | |
13 | + id: id, | |
14 | + variant: variant | |
15 | + }, function(data) { | |
16 | + var total_price = parseInt($(".sum_all") | |
17 | + .children('p') | |
18 | + .text()); | |
19 | + total_price = total_price - (current_price * number); | |
20 | + console.log(number); | |
21 | + $(".sum_all") | |
22 | + .children('p') | |
23 | + .text(total_price); | |
24 | + $.pjax.reload(selector, { | |
25 | + timeout: 5000, | |
26 | + fragment: selector | |
27 | + }); | |
28 | + | |
29 | + }); | |
30 | + | |
31 | + | |
32 | + | |
33 | + | |
34 | + | |
35 | + | |
14 | 36 | }); |
15 | 37 | $(document) |
16 | 38 | .on('click', '.variant-to-order', function(e) { | ... | ... |