Некодим логотипНекодим
МодификацииПубликацииНекодИИмЦены
Некодим логотипНекодим

© 2020-2026 Некодим

Готовые модификации для вашего сайта. Улучшайте функциональность и дизайн без программирования.

Компания

  • Контакты
  • Публичная оферта
  • Политика конфиденциальности
  • Согласие на обработку данных
  • Лицензионное соглашение
  • Реферальная программа

Полезное

  • Модификации
  • Публикации
  • Каталог блоков Tilda
  • MCP для агентов
  • Журнал изменений
  • Доска почёта

Личный кабинет

  • Вход
  • Регистрация
  • Цены
Журнал измененийИстория GitФайлыTilda MCP
Каталог файлов

tilda-cart-1.1.js

Код файла
Версия от 04.12.2026, 04:03:54 МСК
Оригинал на CDNСнимок 56c3b845Полный текст
6701	// @ts-expect-error ST-2949_26702	const withoutLoyalty = [];6703	(Array.isArray(discounts) ? discounts : []).forEach(function (discount) {6704		if (!discount) return;6705		// TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551)6706		// @ts-expect-error ST-2949_16707		if (discount.is_loyalty) return;6708		// @ts-expect-error ST-2949_16709		if (loyaltyId != null && discount.id == loyaltyId) return;6710		withoutLoyalty.push(discount);6711	});6712
История файла и сравнение версий
  • 04.12.2026, 04:03:54 · 56c3b845
6713 // TODO ST-2949_2: implicit any on params, vars, this, and index access (TS7006, TS7005, TS7008, TS7034, TS2683, TS7053, TS7015)
6714 // @ts-expect-error ST-2949_2
6715 window.t_cart__discounts = withoutLoyalty;
6716 t_cart__saveDiscountsToLocalStorage(window.t_cart__discounts, window.sumpromowithdiscount);
6717
6718 if (window.t_cart__discounts?.length > 0) {
6719 tcart__applyLoadedDiscountsToCart();
6720 tcart__reDrawProducts();
6721 tcart__auth__refreshLoggedInEl();
6722 return;
6723 }
6724
6725 // ПЛ сняли, каталожных скидок нет — сбрасываем калькулятор и пересчитываем.
6726 // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551)
6727 // @ts-expect-error ST-2949_1
6728 delete window.cartCalculator;
6729 tcart__updateTotalProductsinCartObj();
6730 tcart__reDrawTotal();
6731 tcart__reDrawProducts();
6732 tcart__saveLocalObj();
6733 tcart__auth__refreshLoggedInEl();
6734}
6735
6736/**
6737 * Зачищает скидку по ПЛ из памяти и localStorage (например, после логаута).
6738 */
6739function tcart__clearLoyaltyDiscount() {
6740 const { t_cart__getDiscountsFromLocalStorage } = t_cart__loadDiscountsHook();
6741
6742 let discounts = Array.isArray(window.t_cart__discounts) ? window.t_cart__discounts.slice() : null;
6743 if (!discounts) {
6744 const { tCartDiscounts, sumPromoWithDiscount } = t_cart__getDiscountsFromLocalStorage();
6745 discounts = Array.isArray(tCartDiscounts) ? tCartDiscounts.slice() : [];
6746 if (typeof sumPromoWithDiscount !== 'undefined' && sumPromoWithDiscount !== null) {
6747 window.sumpromowithdiscount = sumPromoWithDiscount;
6748 }
6749 }
6750
6751 const hadLoyalty = discounts.some(function (discount) {
6752 return discount && discount.is_loyalty;
6753 });
6754 if (!hadLoyalty) return;
6755
6756 tcart__applyDiscountsWithoutLoyalty(discounts);
6757}
6758
6759/**
6760 * При открытии корзины запрашивает getbuyerinfo и вмерживает ПЛ-скидку
6761 * в `window.t_cart__discounts` и `localStorage` (`tcart_discounts`).
6762 *
6763 * @returns {Promise<void>}
6764 */
6765async function tcart__syncBuyerLoyaltyDiscount() {
6766 const inEditor = document.getElementById('allrecords')?.getAttribute('data-tilda-mode') === 'edit';
6767 if (inEditor) return;
6768
6769 const buyerInfo = await t_cart__loadBuyerInfo();
6770 if (!buyerInfo) return;
6771
6772 const { t_cart__getDiscountsFromLocalStorage, t_cart__saveDiscountsToLocalStorage } = t_cart__loadDiscountsHook();
6773
6774 let discounts = Array.isArray(window.t_cart__discounts) ? window.t_cart__discounts.slice() : null;
6775 if (!discounts) {
6776 const { tCartDiscounts, sumPromoWithDiscount } = t_cart__getDiscountsFromLocalStorage();
6777 discounts = Array.isArray(tCartDiscounts) ? tCartDiscounts.slice() : [];
6778 if (typeof sumPromoWithDiscount !== 'undefined' && sumPromoWithDiscount !== null) {
6779 window.sumpromowithdiscount = sumPromoWithDiscount;
6780 }
6781 }
6782
6783 const loyaltyDiscount = buyerInfo.loyalty;
6784 const loyaltyId =
6785 loyaltyDiscount && typeof loyaltyDiscount === 'object' && loyaltyDiscount.id != null
6786 ? loyaltyDiscount.id
6787 : null;
6788
6789 if (!loyaltyDiscount || typeof loyaltyDiscount !== 'object') {
6790 tcart__applyDiscountsWithoutLoyalty(discounts, loyaltyId);
6791 return;
6792 }
6793
6794 const withoutLoyalty = [];
6795 discounts.forEach(function (discount) {
6796 if (!discount) return;
6797 // Снимаем старую ПЛ по флагу и по id привилегии из ответа.
6798 if (discount.is_loyalty) return;
6799 if (loyaltyId != null && discount.id == loyaltyId) return;
6800 withoutLoyalty.push(discount);
Предыдущие 100 строкСледующие 100 строк