} }}/** * Обновляет количество товаров в корзине **/function tcart__updateTotalProductsinCartObj() { var projectIdEl = document.getElementById('allrecords'); if (projectIdEl) { var inEditor = projectIdEl.getAttribute('data-tilda-mode') === 'edit'; if ( window.t_cart__discounts && window.t_cart__discounts.length !== 0 && Array.isArray(window.t_cart__discounts) && !inEditor ) { // calc discounts tcart__onFuncLoad('tcart__calcAmountWithDiscounts', function () { tcart__calcAmountWithDiscounts(); }); } else if (window.tcart.products && window.tcart.products.length > 0) { // обнуляем скидки у продуктов window.tcart.products.forEach(function (product) { delete product.discountid; delete product.amount_withdiscount; delete product.price_withdiscount; }); delete window.tcart.dyndiscount; delete window.tcart.prodamount_withdyndiscount; } } var products = window.tcart['products']; if (products.length > 0) { // пропускает пустые или удаленные товары var total = 0; var prodAmount = 0; Array.prototype.forEach.call(products, function (product) { if (!tcart__isEmptyObject(product) && product.deleted !== 'yes') { if (product.single === 'y') { total = total + 1; } else { total = total + product['quantity'] * 1; } prodAmount = prodAmount * 1 + product['amount'] * 1; } }); prodAmount = tcart__roundPrice(prodAmount); window.tcart['total'] = total; window.tcart['prodamount'] = prodAmount; var amount = prodAmount; if ( typeof window.tcart.prodamount_withdyndiscount !== 'undefined' && window.t_cart__discounts && window.t_cart__discounts.length > 0 ) { amount = window.tcart.prodamount_withdyndiscount; } // добавляет промокод amount = tcart__calcPromocode(amount); // добавляет доставку if ( typeof window.tcart.delivery == 'object' && typeof window.tcart.delivery.price != 'undefined' && window.tcart.delivery.price > 0 && window.tcart.prodamount > 0 ) { if (window.tcart.delivery.freedl > 0 && amount >= window.tcart.delivery.freedl) { } else { amount = amount + window.tcart.delivery.price * 1; } } if (amount > 0) { amount = tcart__roundPrice(amount); } window.tcart['amount'] = amount; } else { window.tcart['total'] = 0; window.tcart['prodamount'] = 0; window.tcart['amount'] = 0; }