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

© 2020-2026 Некодим

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

Компания

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

Полезное

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

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

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

tilda-products-1.0.js

Код файла
Версия от 13.10.2026, 07:01:03 МСК
Оригинал на CDNСнимок 56c3b845Полный текст
101	var priceWrapper = priceContainer?.parentNode;102	const hasWrapperClass = priceWrapper?.classList.value.split(/\s+/).some(cls => cls.endsWith('__price-wrapper'));103	priceWrapper = hasWrapperClass ? priceWrapper : null;104 105	var priceValue = productPrice.getAttribute('data-product-price-def');106 107	priceValue = priceValue * 1;108	var optionPriceEmptyCount = 0;109 110	var handlePrice = function (optionPrice) {111		if (optionPrice) {112
История файла и сравнение версий
  • 13.10.2026, 07:01:03 · 56c3b845
var price = t_prod__cleanPrice(optionPrice);
113
114 if (optionPrice.indexOf('+') !== -1) {
115 add += price;
116 } else if (parseFloat(price) !== 0) {
117 priceValue = price;
118 }
119 } else {
120 optionPriceEmptyCount += 1;
121 }
122 };
123
124 // Обработка для одиночных опций
125 Array.prototype.forEach.call(productSelects, function (select) {
126 var optionPrice = select.querySelector('option:checked').getAttribute('data-product-variant-price');
127 handlePrice(optionPrice);
128 });
129
130 // Обработка для мультиопций
131 var multioptionCheckedCheckboxes = element.querySelectorAll(
132 '.js-product-multioption input[type="checkbox"]:checked'
133 );
134 Array.prototype.forEach.call(multioptionCheckedCheckboxes, function (checkbox) {
135 var optionPrice = checkbox.getAttribute('data-product-variant-price');
136 handlePrice(optionPrice);
137 });
138
139 totalPrice = priceValue + add;
140 var priceRange =
141 productPrice.classList.contains('js-store-prod-price-range-val') ||
142 productPrice.classList.contains('js-catalog-prod-price-range-val');
143 if (priceRange) {
144 productPrice.setAttribute('data-product-price-range-val', t_prod__roundPrice(totalPrice));
145 } else if (totalPrice > 0) {
146 if (priceWrapper && priceWrapper.style.visibility === 'hidden') {
147 priceWrapper.style.visibility = '';
148 }
149 if (priceContainer && priceContainer.style.display === 'none') {
150 priceContainer.style.display = '';
151 }
152 var priceHandled = t_prod__showPrice(t_prod__roundPrice(totalPrice), options);
153 var priceUserInput = productPrice.getAttribute('data-product-price-def-str');
154 var isAllOptionsPriceEmpty = optionPriceEmptyCount === productSelects.length;
155 var isCatalogProduct =
156 element.classList.contains('js-store-product') || element.classList.contains('js-catalog-product');
157 if (isAllOptionsPriceEmpty && !isCatalogProduct) {
158 var priceHandledUserInput = t_prod__saveUserInputInPrice(totalPrice, priceHandled, priceUserInput);
159 productPrice.innerHTML = priceHandledUserInput;
160 } else {
161 productPrice.innerHTML = priceHandled;
162 }
163 } else {
164 if (priceWrapper && priceWrapper.style.visibility === '') {
165 priceWrapper.style.visibility = 'hidden';
166 }
167 if (priceContainer && priceContainer.style.display === '') {
168 priceContainer.style.display = 'none';
169 }
170 productPrice.innerHTML = productPrice.getAttribute('data-product-price-def-str');
171 }
172}
173
174/**
175 * Функция объединяет пользовательский ввод и правильно сформированную цену. Например:
176 * Пользователь ввёл в input "от 1550". В этом случае, функции t_prod__roundPrice и t_prod__showPrice
177 * вернут 1 550 / 1 550.00 (второй вариант в случае если в настройках указана currency). Данная функция увидит,
178 * что пользователь так же написал слово "от" и смержит эти 2 вариант, в итоге получим "от 1 550.00"
179 *
180 * @param {number} total - подсчитанная итоговая цена
181 * @param {string} handled - обработанная цена (с учётом настроек проекта)
182 * @param {string} userInput - необработанная строка (то, что пользователь ввёл в input)
183 * @returns {string} - объединение обработанной цены с сохранением доп. символов, которые ввёл пользователь
184 */
185function t_prod__saveUserInputInPrice(total, handled, userInput) {
186 if (!userInput) return handled;
187
188 if (userInput.indexOf(handled) !== -1) {
189 return userInput;
190 }
191
192 const totalStr = total.toString();
193 if (handled !== userInput) {
194 if (window.tcart && window.tcart['currency_dec'] === '00') {
195 var separator = window.tcart['currency_sep'];
196 var handledWithoutCurrency = handled.replace(separator + '00', '');
197 if (userInput.indexOf(handledWithoutCurrency) !== -1) {
198 return userInput.replace(handledWithoutCurrency, handled);
199 }
200
Предыдущие 100 строкСледующие 100 строк