6701// @ts-expect-error ST-2949_26702const withoutLoyalty = [];6703(Array.isArray(discounts) ? discounts : []).forEach(function (discount) {6704if (!discount) return;6705// TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551)6706// @ts-expect-error ST-2949_16707if (discount.is_loyalty) return;6708// @ts-expect-error ST-2949_16709if (loyaltyId != null && discount.id == loyaltyId) return;6710withoutLoyalty.push(discount);6711});6712
// TODO ST-2949_2: implicit any on params, vars, this, and index access (TS7006, TS7005, TS7008, TS7034, TS2683, TS7053, TS7015) // @ts-expect-error ST-2949_2 window.t_cart__discounts = withoutLoyalty; t_cart__saveDiscountsToLocalStorage(window.t_cart__discounts, window.sumpromowithdiscount); if (window.t_cart__discounts?.length > 0) { tcart__applyLoadedDiscountsToCart(); tcart__reDrawProducts(); tcart__auth__refreshLoggedInEl(); return; } // ПЛ сняли, каталожных скидок нет — сбрасываем калькулятор и пересчитываем. // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 delete window.cartCalculator; tcart__updateTotalProductsinCartObj(); tcart__reDrawTotal(); tcart__reDrawProducts(); tcart__saveLocalObj(); tcart__auth__refreshLoggedInEl();}/** * Зачищает скидку по ПЛ из памяти и localStorage (например, после логаута). */function tcart__clearLoyaltyDiscount() { const { t_cart__getDiscountsFromLocalStorage } = t_cart__loadDiscountsHook(); let discounts = Array.isArray(window.t_cart__discounts) ? window.t_cart__discounts.slice() : null; if (!discounts) { const { tCartDiscounts, sumPromoWithDiscount } = t_cart__getDiscountsFromLocalStorage(); discounts = Array.isArray(tCartDiscounts) ? tCartDiscounts.slice() : []; if (typeof sumPromoWithDiscount !== 'undefined' && sumPromoWithDiscount !== null) { window.sumpromowithdiscount = sumPromoWithDiscount; } } const hadLoyalty = discounts.some(function (discount) { return discount && discount.is_loyalty; }); if (!hadLoyalty) return; tcart__applyDiscountsWithoutLoyalty(discounts);}/** * При открытии корзины запрашивает getbuyerinfo и вмерживает ПЛ-скидку * в `window.t_cart__discounts` и `localStorage` (`tcart_discounts`). * * @returns {Promise<void>} */async function tcart__syncBuyerLoyaltyDiscount() { const inEditor = document.getElementById('allrecords')?.getAttribute('data-tilda-mode') === 'edit'; if (inEditor) return; const buyerInfo = await t_cart__loadBuyerInfo(); if (!buyerInfo) return; const { t_cart__getDiscountsFromLocalStorage, t_cart__saveDiscountsToLocalStorage } = t_cart__loadDiscountsHook(); let discounts = Array.isArray(window.t_cart__discounts) ? window.t_cart__discounts.slice() : null; if (!discounts) { const { tCartDiscounts, sumPromoWithDiscount } = t_cart__getDiscountsFromLocalStorage(); discounts = Array.isArray(tCartDiscounts) ? tCartDiscounts.slice() : []; if (typeof sumPromoWithDiscount !== 'undefined' && sumPromoWithDiscount !== null) { window.sumpromowithdiscount = sumPromoWithDiscount; } } const loyaltyDiscount = buyerInfo.loyalty; const loyaltyId = loyaltyDiscount && typeof loyaltyDiscount === 'object' && loyaltyDiscount.id != null ? loyaltyDiscount.id : null; if (!loyaltyDiscount || typeof loyaltyDiscount !== 'object') { tcart__applyDiscountsWithoutLoyalty(discounts, loyaltyId); return; } const withoutLoyalty = []; discounts.forEach(function (discount) { if (!discount) return; // Снимаем старую ПЛ по флагу и по id привилегии из ответа. if (discount.is_loyalty) return; if (loyaltyId != null && discount.id == loyaltyId) return; withoutLoyalty.push(discount);