/** * Собирает данные о вариантах товара из элемента * * @param {HTMLElement} productElement - Элемент товара, содержащий данные * @returns {ProductDataOptions[]} */function t_catalog__collectOptionsByElement(productElement) { // TODO В теории можно вынести эту функцию в t-cart.js и переиспользовать ее здесь // 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 var options = []; // с разными свойствами var editionOptionsElements = productElement.querySelectorAll('.js-product-edition-option'); Array.prototype.forEach.call(editionOptionsElements, function (optionsElement) { var optionName = optionsElement.querySelector('.js-product-edition-option-name').textContent; var selectedOption = optionsElement.querySelector('option:checked'); if (selectedOption) { var optionVariant = selectedOption.value; var optionPrice = selectedOption.getAttribute('data-product-edition-variant-price'); optionPrice = parseFloat(optionPrice); if (optionName && optionVariant) { var optionObj = {}; if (optionName != '') { optionName = t_catalog_escapeQuote(optionName); } if (optionVariant != '') { optionVariant = t_catalog_escapeQuote(optionVariant); optionVariant = optionVariant.replace(/(?:\r\n|\r|\n)/g, ''); } if (optionName.length > 1 && optionName.charAt(optionName.length - 1) == ':') { optionName = optionName.substring(0, optionName.length - 1); } optionObj['option'] = optionName; optionObj['variant'] = optionVariant; optionObj['price'] = optionPrice; options.push(optionObj); } } }); // дополнительные одиночные опции var optionsElements = productElement.querySelectorAll('.js-product-option'); Array.prototype.forEach.call(optionsElements, function (optionsElement) { var optionName = optionsElement.querySelector('.js-product-option-name').textContent; var selectedOption = optionsElement.querySelector('option:checked'); if (selectedOption) { var optionVariant = selectedOption.value; var optionPrice = selectedOption.getAttribute('data-product-variant-price'); optionPrice = parseFloat(optionPrice); if (typeof optionName != 'undefined' && typeof optionVariant != 'undefined') { var optionObj = {}; if (optionName != '') { optionName = t_catalog_escapeQuote(optionName); } if (optionVariant != '') { optionVariant = t_catalog_escapeQuote(optionVariant); optionVariant = optionVariant.replace(/(?:\r\n|\r|\n)/g, ''); } if (optionName.length > 1 && optionName.charAt(optionName.length - 1) == ':') { optionName = optionName.substring(0, optionName.length - 1); } optionObj['option'] = optionName; optionObj['variant'] = optionVariant; optionObj['price'] = optionPrice; options.push(optionObj); } } }); // дополнительные мультиопци var multioptionsElements = productElement.querySelectorAll('.js-product-multioption'); Array.prototype.forEach.call(multioptionsElements, function (optionsElement) { var checkboxes = optionsElement.querySelectorAll('input[type="checkbox"]:checked'); Array.prototype.forEach.call(checkboxes, function (checkbox) { var optionName = optionsElement.querySelector('.js-product-option-name').textContent; if (optionName) { optionName = t_catalog_escapeQuote(optionName); } if (optionName.length > 1 && optionName.charAt(optionName.length - 1) == ':') { optionName = optionName.substring(0, optionName.length - 1); } var optionVariant = checkbox.name; if (optionVariant) { optionVariant = t_catalog_escapeQuote(optionVariant);