Каталог файловtilda-products-1.0.js
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
История файла и сравнение версий
var price = t_prod__cleanPrice(optionPrice);
114 if (optionPrice.indexOf('+') !== -1) { 116 } else if (parseFloat(price) !== 0) { 120 optionPriceEmptyCount += 1; 124 // Обработка для одиночных опций 125 Array.prototype.forEach.call(productSelects, function (select) { 126 var optionPrice = select.querySelector('option:checked').getAttribute('data-product-variant-price'); 127 handlePrice(optionPrice); 130 // Обработка для мультиопций 131 var multioptionCheckedCheckboxes = element.querySelectorAll( 132 '.js-product-multioption input[type="checkbox"]:checked' 134 Array.prototype.forEach.call(multioptionCheckedCheckboxes, function (checkbox) { 135 var optionPrice = checkbox.getAttribute('data-product-variant-price'); 136 handlePrice(optionPrice); 139 totalPrice = priceValue + add; 141 productPrice.classList.contains('js-store-prod-price-range-val') || 142 productPrice.classList.contains('js-catalog-prod-price-range-val'); 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 = ''; 149 if (priceContainer && priceContainer.style.display === 'none') { 150 priceContainer.style.display = ''; 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; 161 productPrice.innerHTML = priceHandled; 164 if (priceWrapper && priceWrapper.style.visibility === '') { 165 priceWrapper.style.visibility = 'hidden'; 167 if (priceContainer && priceContainer.style.display === '') { 168 priceContainer.style.display = 'none'; 170 productPrice.innerHTML = productPrice.getAttribute('data-product-price-def-str'); 175 * Функция объединяет пользовательский ввод и правильно сформированную цену. Например: 176 * Пользователь ввёл в input "от 1550". В этом случае, функции t_prod__roundPrice и t_prod__showPrice 177 * вернут 1 550 / 1 550.00 (второй вариант в случае если в настройках указана currency). Данная функция увидит, 178 * что пользователь так же написал слово "от" и смержит эти 2 вариант, в итоге получим "от 1 550.00" 180 * @param {number} total - подсчитанная итоговая цена 181 * @param {string} handled - обработанная цена (с учётом настроек проекта) 182 * @param {string} userInput - необработанная строка (то, что пользователь ввёл в input) 183 * @returns {string} - объединение обработанной цены с сохранением доп. символов, которые ввёл пользователь 185function t_prod__saveUserInputInPrice(total, handled, userInput) { 186 if (!userInput) return handled; 188 if (userInput.indexOf(handled) !== -1) { 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);