diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 7a3d4ef..0f7a3b1 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -404,6 +404,22 @@ return $sum; } + public function actionDeleteFromOrder() + { + $id = \Yii::$app->request->post('id'); + $variant = \Yii::$app->request->post('variant'); + $product = OrderProduct::find() + ->where( + [ + 'order_id' => $id, + 'variant_id' => $variant, + ] + ) + ->one() + ->delete(); + return 'ok'; + } + /** * Finds the Order model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/views/order/_form.php b/views/order/_form.php index 1861a27..1ad2399 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -150,6 +150,10 @@ JS; '#', [ 'class' => 'remove-order-product', + 'data' => [ + 'variant' => $orderProduct->variant->id, + 'id' => $model->id, + ], ] ) ?> diff --git a/web/js/order.js b/web/js/order.js index 3b473e1..940e4d1 100755 --- a/web/js/order.js +++ b/web/js/order.js @@ -4,13 +4,35 @@ $(function() { e.preventDefault(); var current_price = parseInt($(this).parents('.row-order-product').data('price')); var number = parseInt($(this).parents('.row-order-product').children('.col-md-3').children('.form-group').children('input').val()); - $(this) - .parents('.row-order-product') - .remove(); - var total_price = parseInt($(".sum_all").children('p').text()); - total_price = total_price - (current_price * number); - console.log(number); - $(".sum_all").children('p').text(total_price); + var id = $(this) + .data('id'); + var variant = $(this) + .data('variant'); + var selector = '#order-product-pjax'; + $.post('/admin/order/delete-from-order', { + id: id, + variant: variant + }, function(data) { + var total_price = parseInt($(".sum_all") + .children('p') + .text()); + total_price = total_price - (current_price * number); + console.log(number); + $(".sum_all") + .children('p') + .text(total_price); + $.pjax.reload(selector, { + timeout: 5000, + fragment: selector + }); + + }); + + + + + + }); $(document) .on('click', '.variant-to-order', function(e) { -- libgit2 0.21.4