From 61595e31d4a4416518d2274901d4f308f48c8d5c Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Sun, 16 Nov 2025 19:24:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=BD=D1=84=D0=BB=D0=B8=D0=BA=D1=82?= =?UTF-8?q?=20ID=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BC=D0=B8=20=D0=B8=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BF=D0=BB=D0=B5=D0=BA=D1=82=D0=B0=D0=BC=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=80=D0=B7=D0=B8=D0=BD=D0=B5,=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=81?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9=20=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=20type-id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myproject/pos/static/pos/js/terminal.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/myproject/pos/static/pos/js/terminal.js b/myproject/pos/static/pos/js/terminal.js index 062ef2c..8f16308 100644 --- a/myproject/pos/static/pos/js/terminal.js +++ b/myproject/pos/static/pos/js/terminal.js @@ -12,7 +12,7 @@ console.log(` - Товаров: ${productsCount}, Комплектов: ${kitsC console.log('Позиции:', ITEMS); let currentCategoryId = null; -const cart = new Map(); // productId -> {id, name, price, qty} +const cart = new Map(); // "type-id" -> {id, name, price, qty, type} function formatMoney(v) { return (Number(v)).toFixed(2); @@ -146,12 +146,13 @@ function renderProducts() { } function addToCart(item) { - const isNew = !cart.has(item.id); + const cartKey = `${item.type}-${item.id}`; // Уникальный ключ: "product-1" или "kit-1" + const isNew = !cart.has(cartKey); if (isNew) { - cart.set(item.id, { id: item.id, name: item.name, price: Number(item.price), qty: 1, type: item.type }); + cart.set(cartKey, { id: item.id, name: item.name, price: Number(item.price), qty: 1, type: item.type }); } else { - cart.get(item.id).qty += 1; + cart.get(cartKey).qty += 1; } renderCart(); @@ -160,7 +161,7 @@ function addToCart(item) { setTimeout(() => { const qtyInputs = document.querySelectorAll('.qty-input'); const cartItems = Array.from(cart.keys()); - const itemIndex = cartItems.indexOf(item.id); + const itemIndex = cartItems.indexOf(cartKey); if (itemIndex !== -1 && qtyInputs[itemIndex]) { qtyInputs[itemIndex].focus(); @@ -188,7 +189,7 @@ function renderCart() { return; } - cart.forEach(item => { + cart.forEach((item, cartKey) => { const row = document.createElement('div'); row.className = 'cart-item mb-2'; @@ -214,9 +215,9 @@ function renderCart() { qtyInput.onchange = (e) => { const newQty = parseInt(e.target.value) || 1; if (newQty <= 0) { - removeFromCart(item.id); + removeFromCart(cartKey); } else { - cart.get(item.id).qty = newQty; + cart.get(cartKey).qty = newQty; renderCart(); } }; @@ -230,7 +231,7 @@ function renderCart() { const deleteBtn = document.createElement('button'); deleteBtn.className = 'btn btn-sm btn-link text-danger p-0'; deleteBtn.innerHTML = ''; - deleteBtn.onclick = () => removeFromCart(item.id); + deleteBtn.onclick = () => removeFromCart(cartKey); row.appendChild(namePrice); row.appendChild(multiplySign); @@ -246,8 +247,8 @@ function renderCart() { document.getElementById('cartTotal').textContent = formatMoney(total); } -function removeFromCart(id) { - cart.delete(id); +function removeFromCart(cartKey) { + cart.delete(cartKey); renderCart(); }