Это первая доступная в Git версия файла.
1/*2Устанавливает цену в блоке товара при добавлении параметров3При добавлении нескольких параметров добавляет обработчик для select и option4Выбрав определенный параметр изменяет цену у продукта5*/67/**8* Init products9*10* @param {string} recId - rec id11* @returns {undefined} - exit function12*/
function t_prod__init(recId) { var rec = document.querySelector('#rec' + recId); if (!rec) return; var productElements = rec.querySelectorAll('.js-product'); Array.prototype.forEach.call(productElements, function (productElement) { if (productElement.querySelector('.js-product-option, .js-product-multioption')) { t_prod__initProduct(productElement); } });}/** * Init product card * * @param {string} recId - rec id * @param {Node} productElement - product card */function t_prod__initProduct(productElement, options) { let element = productElement; if (typeof element === 'string') { element = options; } t_prod__initPrice(element); t_prod__addEvents__options(element); t_prod__updatePrice(element, options);}/** * Init price * * @param {Node} productElement - product card */function t_prod__initPrice(productElement) { let element = productElement; // TODO: jqeury in js if (!(element instanceof Element)) element = element[0]; if (!element) return; var productPrice = element.querySelector('.js-product-price'); if (!productPrice) { element.insertAdjacentHTML('beforeend', '<div style="display:none;" class="js-product-price"></div>'); productPrice = element.querySelector('.js-product-price'); } var priceValue = productPrice.textContent; var productDef = productPrice.getAttribute('data-product-price-def'); var productDefStr = productPrice.getAttribute('data-product-price-def-str'); // Базовую цену запоминаем один раз. Пустая строка тоже остаётся: у товара нет своей цены, её даёт опция. // Если прочитать цену из карточки ещё раз, надбавка опции прибавится повторно. if (productDef !== null || productDefStr !== null) return; if (priceValue) { var price = t_prod__cleanPrice(priceValue); productPrice.setAttribute('data-product-price-def', price); productPrice.setAttribute('data-product-price-def-str', priceValue.replace(/"/g, '')); } else { productPrice.setAttribute('data-product-price-def', 0); }}/** * Update the price when changing * * @param {Node} productElement - product card * @returns {undefined} - exit function */function t_prod__updatePrice(productElement, options) { let element = productElement; // TODO: jqeury in js if (!(element instanceof Element)) element = element[0]; if (!element) return; var productPrice = element.querySelector('.js-product-price'); var productSelects = element.querySelectorAll('.js-product-option-variants'); var totalPrice; var add = 0; if (!productPrice) return; var priceContainer = productPrice.parentNode; const hasContainerClass = priceContainer?.classList.value.split(/\s+/).some(cls => cls.endsWith('__price')); priceContainer = hasContainerClass ? priceContainer : null;