price fixes
This commit is contained in:
parent
2940f00142
commit
8d81940faf
4 changed files with 66 additions and 47 deletions
|
|
@ -3,71 +3,85 @@ function changeCake(id, name, price, delta) {
|
|||
if (input != null) {
|
||||
var qty = Number(input.value) + delta;
|
||||
if (qty <= 0) {
|
||||
var item = input.closest('li');
|
||||
var item = input.closest("li");
|
||||
if (item) item.remove();
|
||||
updateTotals();
|
||||
updateCatalogueQty(id, 0);
|
||||
return;
|
||||
}
|
||||
input.value = qty;
|
||||
var item = input.closest('li');
|
||||
item.querySelector('.qty').innerText = qty;
|
||||
item.querySelector('.price').innerText = (price * qty) + ' PLN';
|
||||
var item = input.closest("li");
|
||||
item.querySelector(".qty").innerText = qty;
|
||||
item.querySelector(".price").innerText = price * qty + " PLN";
|
||||
updateTotals();
|
||||
updateCatalogueQty(id, qty);
|
||||
return;
|
||||
}
|
||||
if (delta <= 0) return;
|
||||
var item = document.createElement('li');
|
||||
item.setAttribute('data-cake-id', id);
|
||||
var item = document.createElement("li");
|
||||
item.setAttribute("data-cake-id", id);
|
||||
item.innerHTML =
|
||||
'<div style="flex:1;min-width:0;padding-right:0.5rem">' +
|
||||
'<div class="name">' + name + '</div>' +
|
||||
'<div class="detail">' + price + ' PLN × <span class="qty">1</span></div>' +
|
||||
'</div>' +
|
||||
'<div class="price">' + price + ' PLN</div>' +
|
||||
'<div class="name">' +
|
||||
name +
|
||||
"</div>" +
|
||||
'<div class="detail">' +
|
||||
price +
|
||||
' PLN × <span class="qty">1</span></div>' +
|
||||
"</div>" +
|
||||
'<div class="price">' +
|
||||
price +
|
||||
" PLN</div>" +
|
||||
'<button type="button" class="remove" onclick="removeCake(this)">' +
|
||||
'<span class="material-symbols-outlined">close</span>' +
|
||||
'</button>' +
|
||||
'<input type="hidden" name="cake[' + id + ']" value="1">';
|
||||
document.getElementById('basket-items').appendChild(item);
|
||||
'<span class="material-symbols-outlined">close</span>' +
|
||||
"</button>" +
|
||||
'<input type="hidden" name="cake[' +
|
||||
id +
|
||||
']" value="1">';
|
||||
document.getElementById("basket-items").appendChild(item);
|
||||
updateTotals();
|
||||
updateCatalogueQty(id, 1);
|
||||
}
|
||||
|
||||
function removeCake(btn) {
|
||||
var item = btn.closest('li');
|
||||
var id = item.getAttribute('data-cake-id');
|
||||
var item = btn.closest("li");
|
||||
var id = item.getAttribute("data-cake-id");
|
||||
item.remove();
|
||||
updateTotals();
|
||||
updateCatalogueQty(id, 0);
|
||||
}
|
||||
|
||||
var subtotal = 0;
|
||||
|
||||
function updatePrepaid() {
|
||||
var paid = Number(document.querySelector('[name="paid"]')?.value || 0);
|
||||
document.getElementById("paid-amount").innerText = paid + " PLN";
|
||||
document.getElementById("total-price").innerText = subtotal - paid + " PLN";
|
||||
}
|
||||
|
||||
function updateTotals() {
|
||||
var subtotal = 0;
|
||||
var items = document.querySelectorAll('#basket-items li');
|
||||
items.forEach(function(item) {
|
||||
var priceText = item.querySelector('.detail').innerText;
|
||||
var price = Number(priceText.split(' ')[0]);
|
||||
var qty = Number(item.querySelector('.qty').innerText);
|
||||
subtotal = 0;
|
||||
var items = document.querySelectorAll("#basket-items li");
|
||||
items.forEach(function (item) {
|
||||
var priceText = item.querySelector(".detail").innerText;
|
||||
var price = Number(priceText.split(" ")[0]);
|
||||
var qty = Number(item.querySelector(".qty").innerText);
|
||||
subtotal += price * qty;
|
||||
});
|
||||
var paid = Number(document.querySelector('[name="paid"]')?.value || 0);
|
||||
document.getElementById('subtotal-price').innerText = subtotal + ' PLN';
|
||||
document.getElementById('paid-amount').innerText = paid + ' PLN';
|
||||
document.getElementById('total-price').innerText = (subtotal - paid) + ' PLN';
|
||||
document.getElementById("subtotal-price").innerText = subtotal + " PLN";
|
||||
updatePrepaid();
|
||||
}
|
||||
|
||||
function updateCatalogueQty(id, qty) {
|
||||
var el = document.getElementById('qty-' + id);
|
||||
var el = document.getElementById("qty-" + id);
|
||||
if (el) el.innerText = qty;
|
||||
}
|
||||
|
||||
function filterCatalogue(input) {
|
||||
var query = input.value.toLowerCase();
|
||||
var items = document.querySelectorAll('#catalogue-grid > li');
|
||||
items.forEach(function(item) {
|
||||
var name = item.getAttribute('data-name').toLowerCase();
|
||||
item.style.display = name.includes(query) ? '' : 'none';
|
||||
var items = document.querySelectorAll("#catalogue-grid > li");
|
||||
items.forEach(function (item) {
|
||||
var name = item.getAttribute("data-name").toLowerCase();
|
||||
item.style.display = name.includes(query) ? "" : "none";
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue