Colleagues.
Forgive me if I could not express what I really want in the title, because I could not find a correct definition but explain it here.
I have a shopping cart where the products are listed according to customer purchase and are stored in a DB table, however I am using a feature via Jquery that shows the quantity of products and changes by clicking the + or - button. See the image below:
Thecodeisthesameforeachproduct:
HTML
<divclass="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);
Show how much the fields will have, but here my challenge comes in. Each product coming from the DB has its own quantity. How would I integrate this code? The integration would be the results coming from the bank gets PHP.
<?php
while($jmProdutos = mysqli_fetch_object($sqlProdutos)){
.....
$qtdProduto = $jmProdutos->Quantidade;
}