0
Colleagues.
Forgive me if I couldn’t express what I really want in the title, because I couldn’t find a correct definition unless I explained it here.
I have a shopping cart where the products are listed according to the customer’s purchase and are stored in a BD table, but I am using a feature via Jquery that shows the quantity of products and changes by clicking the + or -button. See the image below:
The code is this for each product:
HTML
<div class="quantity">
<div class="quantity-select">
<div class="entry value-minus"> </div>
<div class="entry value"><span>1</span></div>
<div class="entry value-plus active"> </div>
</div>
</div>
JQUERY
$('.value-plus').on('click', function(){
var divUpd = $(this).parent().find('.value'), newVal = parseInt(divUpd.text(), 10)+1;
if(newVal < 8) divUpd.text(newVal);
var valor = $(this).closest('tr').find('td[data-nome]').data('nome'); // Funcional
trocar = valor.replace(",",".");
valorTTotal = document.getElementById("total").innerHTML;
valorTotal = trocar + 1;
vv = parseFloat(valorTotal) + parseFloat(valorTTotal);
document.getElementById("total").innerHTML = vv.toFixed(2);
document.getElementById("subtotal").innerHTML = vv.toFixed(2);
$.ajax({
type: "GET",
dataType: 'json',
data:{ valor: vv.toFixed(2) },
url: "atualizar-carrinho.php",
success: function(resposta){
}
});
var divUpd = $(this).parent().find('.value'), newVal1 = parseInt(divUpd.text(), 10)+1;
if(newVal1 < <?php echo $numero; ?>) divUpd.text(newVal);
var valor = $(this).closest('tr').find('td[data-nome]').data('nome'); // Funcional
trocar = valor.replace(",",".");
valorTTotal = document.getElementById("total").innerHTML;
valorTotal = trocar + 1;
vv = parseFloat(valorTotal) + parseFloat(valorTTotal);
document.getElementById("total").innerHTML = vv.toFixed(2);
document.getElementById("subtotal").innerHTML = vv.toFixed(2);
$.ajax({
type: "GET",
dataType: 'json',
data:{ valor: vv.toFixed(2) },
url: "atualizar-carrinho.php",
success: function(resposta){
}
});
});
The line:
if(newVal < 8) divUpd.text(newVal);
It shows the amount that the fields will have, but here comes my challenge. Each product coming from the BD has its own quantity. How would I integrate into this code? The integration would be the results coming from the database gets PHP.
<?php
while($jmProdutos = mysqli_fetch_object($sqlProdutos)){
.....
$qtdProduto = $jmProdutos->Quantidade;
}
Hello Daniel. Thank you for the return, but unfortunately I could not understand it. Could you give me an example?
– user24136
Of course, just tell me one thing: what columns do you have in the order database? Have a
ID
or something similar?– Daniel
Well, I made the example thinking of things that everyone has in the database and using mysqli as you already seem to be used to.
– Daniel
Thank you Daniel
– user24136