-
Notifications
You must be signed in to change notification settings - Fork 0
/
frete.js
79 lines (59 loc) · 1.99 KB
/
frete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function LoadFrete() {
var cep_destino = $('#cep_destino').val();
var cep_qtd = 0;
$(".qtd_input").each((i, item) => {
cep_qtd += parseInt($(item).val());
});
console.log(cep_qtd);
$.ajax({
url: 'a_frete.php',
type: 'POST',
dataType: 'html',
cache: false,
data: { cep_destino: cep_destino, cep_qtd: cep_qtd },
success: function (data) {
console.log('Valor = ' + data);
data = data.replace(',', '.');
$('#valor_frete').val(data);
$('#val').attr('value', data);
$('#valor_frete').text(data);
$('#val').text(data);
$("#totalcheckout").attr('value', parseFloat($("#subtotal").text()) + parseFloat(data));
$("#totalcheckout").val(parseFloat($("#subtotal").text()) + parseFloat(data));
//var total = parseFloat(data) + parseFloat(val_prod);
}, beforeSend: function () {
}, error: function (jqXHR, textStatus, errorThrown) {
console.log('Erro');
}
});
}
function updateCart(input) {
var qtd = input.val();
var command = input.data("idcommand");
var id_product = input.data("idproduct");
console.log(qtd);
console.log(command);
console.log(id_product);
$.ajax({
url: 'includes/update-cart.php',
type: 'POST',
dataType: 'html',
cache: false,
data: { command: command, id_product: id_product, qtd: qtd },
success: function (data) {
console.log(data);
}, beforeSend: function () {
}, error: function (errorThrown) {
console.log(errorThrown);
}
});
LoadFrete();
}
function recalcTotal() {
total = 0;
$(".qtd_input").each((i, item) => {
total += parseInt($(item).val()) * parseFloat($(item).data("price"));
});
$("#subtotal").text(total.toFixed(2));
$("#totalcheckout").attr('value', (total + parseFloat($('#valor_frete').val())).toFixed(2));
}