* @param {string} recid * @param {CartOptions} options */async function tcart__init(recid, options = {}) { if (options && typeof options !== 'object') { console.error(`Cart param "options" is not an object. Please specify object instead of ${typeof options}`); } const cartBlock = tcart__getCartBlock(); if (!cartBlock) return; // ST-3277: скидка и код промокода в итоге и в ценах товаров — пока только для team-пользователей const isPromocodeDetails = isTeamUser(); document.querySelectorAll('.t706').forEach(cart => { cart.classList.add('t706_flextotals'); if (isPromocodeDetails) cart.classList.add('t706_promocode-details'); }); const { ymapApiKey = cartBlock.getAttribute('data-yandexmap-apikey') || '', cssClassName } = options; const cartBlocksLength = tcart__getCartBlocks().length; const rec = document.querySelector('#rec' + recid); window.tcart__ymapApiKey = ymapApiKey; if (rec && cssClassName) { rec.classList.add(cssClassName); } // Скрываем поля формы и рассчет цены, пока не загрузились данные об авторизации tcart__form__hideFormFields(); tcart__hideBottomTotalAmount(); // Поля снова покажет tcart__initAuthAndDelivery, поэтому сбрасываем флаг: иначе при повторной инициализации // (перерисовка блока в редакторе после сохранения, смена ширины у полноэкранной корзины) поля останутся скрытыми window.tcart_isAuthInited = false; window.t_cart__browserLang = t_cart__getCartLang(); await loadTranslations(window.t_cart__browserLang); // предотвращает несколько инициализаций // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 if (window.tcart_initted === 'yes' && cartBlocksLength > 1) { var errorText = window.t_cart__browserLang === 'RU' ? 'Ошибка: На странице присутствуют ' + cartBlocksLength + ' виджета корзины (блок ST100). Пожалуйста, удалите дубликаты. Блоки могут находиться на странице Header или Footer.' : 'Error: ' + cartBlocksLength + ' cart widgets (block ST100) on the page. Remove a duplicate. Blocks can be on the Header or Footer page.'; if (!document.querySelector('.t706__previewmode-infobox .t706__previewmode-infobox-error')) { Array.prototype.forEach.call( document.querySelectorAll('.t706__previewmode-infobox center'), function (infobox) { infobox.insertAdjacentHTML( 'beforeend', '<div class="t706__previewmode-infobox-error" style="color:red">' + errorText + '</div>' ); } ); } // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 if (window.tcart_erroralert === undefined) { alert(errorText); // @ts-expect-error ST-2949_1 window.tcart_erroralert = 'yes'; console.error('Error: Two cart widgets (block ST100) on the page. Remove a duplicate.'); } return; } var dontStore = cartBlock.getAttribute('data-cart-dontstore'); if (dontStore == 'y') window.tcart_dontstore = 'y'; var isOneProduct = cartBlock.getAttribute('data-cart-oneproduct'); // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 if (isOneProduct == 'y') window.tcart_oneproduct = 'y'; var maxStoreDays = cartBlock.getAttribute('data-cart-maxstoredays'); if (maxStoreDays) window.tcart_maxstoredays = maxStoreDays;