From 8b638e12448ced41ce4cf51119db2360f464cdb0 Mon Sep 17 00:00:00 2001 From: stes Date: Mon, 15 Jan 2018 10:43:38 +0200 Subject: [PATCH] sum in order --- controllers/OrderController.php | 1 + views/order/_form.php | 10 +++++++--- views/order/_order_product.php | 4 ++-- web/js/order.js | 9 +++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 3982a23..13c5c25 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -395,6 +395,7 @@ return [ 'success' => true, 'row' => $row, + 'price' => $variant->price * $count, ]; } diff --git a/views/order/_form.php b/views/order/_form.php index 5714204..8ac7643 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -30,9 +30,6 @@ field($model, 'name') ->textInput([ 'maxlength' => true ]) ?> - field($model, 'secondname') - ->textInput([ 'maxlength' => true ]) ?> - field($model, 'phone') ->textInput([ 'maxlength' => true ]) ?> @@ -142,7 +139,9 @@
isNewRecord) { + $sum = 0; foreach ($model->orderProducts as $index => $orderProduct) { + $sum += ( $orderProduct->count * $orderProduct->price ); echo $this->render( '_order_product', [ @@ -154,9 +153,14 @@ ] ); } + } ?> +
+ isNewRecord) { + echo( "
Всего

" . $sum . "

" ); + } ?> diff --git a/views/order/_order_product.php b/views/order/_order_product.php index 26bdf6e..16094ef 100644 --- a/views/order/_order_product.php +++ b/views/order/_order_product.php @@ -17,7 +17,7 @@ ?> -
+
field($orderProduct, "[$index]variant_id") @@ -32,7 +32,7 @@
field($orderProduct, "[$index]count") - ->textInput() + ->textInput([ 'class' => 'count' ]) ->label(false); ?>
diff --git a/web/js/order.js b/web/js/order.js index 493feec..dbc5dd4 100755 --- a/web/js/order.js +++ b/web/js/order.js @@ -29,21 +29,21 @@ $(function() { var order = $(this) .data('id'); if (id.val() && count.val()) { - var selector = '#order-product-pjax'; $.post('/admin/order/add-to-order', { id: id.val(), count: count.val(), order: order }, function(data) { if (data.success) { - $('#product-rows') - .append(data.row); var sum = $(".sum_all") .children('p') .text(); $(".sum_all") .children('p') - .html(parseInt(sum) + parseInt(data)); + .html(parseInt(sum) + parseInt(data.price)); + $('#product-rows') + .append(data.row); + } }); @@ -51,6 +51,7 @@ $(function() { }); $(document).on('change', '.count', function() { var count_old = parseInt(this.defaultValue); + console.log(count_old); var count_new = parseInt(this.value); var current_price = parseInt($(this).parents('.row-order-product').data('price')); var total_price = parseInt($(".sum_all").children('p').text()); -- libgit2 0.21.4