0
I have the following loop
:
<?php foreach($order_details as $v_order): ?>
<?php $others_price = $v_order->others_price; ?>
<?php
$adicional = ($v_order->others_price * count($order_details));
$vlr_adc = ($adicional / count($order_details));
?>
<tr>
<td><?php echo $counter ?></td>
<td><?php echo $v_order->product_name ?></td>
<td class="media_price_<?php echo $v_order->product_code; ?>"><?php echo $this->localization->currencyFormat($v_order->buying_price); ?></td>
<td><input type="number" name="product_quantity" value="<?php echo $v_order->product_quantity ?>" class="form-control product_quantity" data-id="<?php echo $v_order->product_code; ?>" style="width: 75%"></td>
<td class="total_price_<?php echo $v_order->product_code; ?> linhas"><?php echo $this->localization->currencyFormat($v_order->sub_total) ?></td>
<td><?php if($counter>1){ ?><button class="btn btn-primary remove_product_<?php echo $v_order->product_code; ?>"><i class="fa fa-minus"></i></button><?php } ?></td>
</tr>
<?php $counter ++?>
<?php endforeach; ?>
And the next jQuery:
$(".product_quantity").keyup(function(){
var product_code = $(".product_quantity").data("id");
var product_quantity = $('.product_quantity').val();
var media_price = $('.media_price_'+product_code).html();
var total_price = $('.total_price_'+product_code).html();
var media_price_r = media_price.replace("R$ ", "");
var media_price_r2 = media_price_r.replace(/\./g, "").replace(",", ".") || 0;
var calc = ((parseFloat(media_price_r2))*product_quantity).toFixed(3);
calc = calc.substr(0, calc.indexOf(".")) + calc.substr(calc.indexOf("."),3);
calc = parseFloat(calc);
$('.total_price_'+product_code).html(calc.toLocaleString("pt-BR", { style: "currency" , currency:"BRL"}));
$(".linhas").each(function(){
var linhas = $(".linhas").val()
var linhas_r = linhas.replace("R$ ", "");
var linhas_r2 = linhas_r.replace(/\./g, "").replace(",", ".") || 0;
var soma += parseFloat(linhas_r2);
})
$(".fechado").html(soma);
});
The problem is: When modifying the field product_quantity
, should calculate and show to the side, in the total_price
. This is done only in the first line, in the others, it is not calculated.
And the second problem would be the sum total of all the values contained in class
lines, to present the total value just below:
<h3 class="text-right fechado">Total: <?php echo $this->localization->currencyFormat($order_info->grand_total) ?></h3>
What’s wrong with it?
Man, there’s no way to make a MVCE? From what I see the problem is only in jQuery and PHP is only hindering the reading of the code. It would be nice if you could add a Snipper just with jQuery and HTML.
– fernandosavio