<!-- Автоматический расчет стоимости НДС в корзине Тильда | youx.agency -->
<!-- https://youx.agency/otzyvy-i-karta-yandeks-na-tilda -->
<script>
(function() {
const VAT_RATE = 0.05;
function formatPrice(num) {
return num.toLocaleString('ru-RU', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) + ' руб.';
}
function updateTotalWithVAT() {
try {
// Ищем итоговую сумму
const totalSelectors = [
'.t706__cartwin-totalamount-value',
'.t706__cartwin-totalamount',
'.t-cart-win__total-amount'
];
let totalEl = null;
for (let selector of totalSelectors) {
totalEl = document.querySelector(selector);
if (totalEl && totalEl.textContent.trim().length > 0) break;
}
// Если корзина закрыта или пуста — выходим
if (!totalEl) return;
const totalText = totalEl.textContent
.replace(/\s+/g, '')
.replace(/[₽р.]/g, '')
.replace(',', '.');
const grandTotal = parseFloat(totalText);
if (isNaN(grandTotal) || grandTotal === 0) return;
// Считаем НДС
const vatAmount = grandTotal - (grandTotal / (1 + VAT_RATE));
// Ищем или создаем строку НДС
let vatRow = document.querySelector('.t706__cartwin-vat-row');
if (!vatRow) {
vatRow = document.createElement('div');
vatRow.className = 't706__cartwin-row t706__cartwin-vat-row';
// Стили оставляем как были
vatRow.style.cssText = 'display:flex; justify-content:space-between; padding:10px 0; font-size:14px; color:#555; border-top:1px solid #ddd; margin-top:10px; font-family:Arial, sans-serif;';
const wrapper = totalEl.closest('.t706__cartwin-total') || totalEl.parentNode;
if (wrapper && wrapper.parentNode) {
wrapper.parentNode.insertBefore(vatRow, wrapper);
}
}
// Обновляем текст, только если сумма реально изменилась
const newHTML = `
<span>НДС (5%, включен в цену):</span>
<span style="font-weight:600;">${formatPrice(vatAmount)}</span>
`;
if (vatRow.innerHTML !== newHTML) {
vatRow.innerHTML = newHTML;
}
} catch (e) {}
}
// Запускаем проверку каждые 500мс (чтобы работало сразу при открытии без кликов)
setInterval(updateTotalWithVAT, 500);
// Дополнительно вешаем наблюдатель для мгновенной реакции на + / -
const observer = new MutationObserver(updateTotalWithVAT);
const cartArea = document.querySelector('.t706__cartwin');
if (cartArea) {
observer.observe(cartArea, { childList: true, subtree: true, characterData: true });
}
})();
</script>
<!-- Автоматический расчет стоимости НДС в корзине Тильда | youx.agency -->
<!-- https://youx.agency/otzyvy-i-karta-yandeks-na-tilda -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const VAT_RATE = 0.05;
function formatPrice(num) {
return Math.round(num).toLocaleString('ru-RU') + ' ₽';
}
function updateTotalWithVAT() {
// Находим текущую итоговую сумму
let totalEl = document.querySelector('.t706__cartwin-totalamount .t706__cartwin-totalamount-value, .t706__cartwin-totalamount');
if (!totalEl) return;
let totalText = totalEl.textContent
.replace(/\s+/g, '')
.replace(/[₽р.]/g, '')
.replace(',', '.');
let subtotal = parseFloat(totalText);
if (!subtotal || subtotal <= 0) return;
// Считаем НДС
const vatAmount = subtotal * VAT_RATE;
// Новая итоговая сумма
const grandTotal = subtotal + vatAmount;
// === Создаём/обновляем строку НДС ===
let vatRow = document.querySelector('.t706__cartwin-vat-row');
if (!vatRow) {
vatRow = document.createElement('div');
vatRow.className = 't706__cartwin-row t706__cartwin-vat-row';
vatRow.style.cssText = `
display: flex;
justify-content: space-between;
padding: 12px 0 8px 0;
font-size: 15px;
color: #333;
border-top: 1px solid #eee;
`;
const totalWrapper = totalEl.closest('.t706__cartwin-total, .t706__cartwin-totalamount-wrapper') || totalEl.parentNode;
if (totalWrapper && totalWrapper.parentNode) {
totalWrapper.parentNode.insertBefore(vatRow, totalWrapper);
}
}
vatRow.innerHTML = `
<div>НДС 5%</div>
<div style="font-weight:500;">${formatPrice(vatAmount)}</div>
`;
// === Обновляем итоговую сумму (прибавляем НДС) ===
let grandTotalEl = document.querySelector('.t706__cartwin-grandtotal');
if (!grandTotalEl) {
grandTotalEl = document.createElement('div');
grandTotalEl.className = 't706__cartwin-row t706__cartwin-grandtotal';
grandTotalEl.style.cssText = `
display: flex;
justify-content: space-between;
padding: 15px 0 10px 0;
font-size: 18px;
font-weight: 700;
border-top: 2px solid #000;
margin-top: 5px;
`;
vatRow.parentNode.appendChild(grandTotalEl);
}
grandTotalEl.innerHTML = `
<div>Итого к оплате:</div>
<div style="font-size: 20px;">${formatPrice(grandTotal)}</div>
`;
}
// Запуск и отслеживание
setTimeout(updateTotalWithVAT, 700);
const observer = new MutationObserver(() => setTimeout(updateTotalWithVAT, 250));
const cartArea = document.querySelector('.t706__cartwin, .t706__cart');
if (cartArea) observer.observe(cartArea, { childList: true, subtree: true });
document.addEventListener('tcartchange', updateTotalWithVAT);
setInterval(updateTotalWithVAT, 3000);
});
</script>