}/** * Возвращает значение opacity * * @param {string} opacity - значение opacity * @returns {number} */function tma__userbar__getOpacity(opacity) { if (opacity && opacity !== '0') { return +opacity / 100; } else if (opacity === '0') { return 0; } else { return 1; }}/** * @typedef {Object} HasAddresses * @property {boolean} hasAddresses - наличие или отсутствие адресов для продвинутых доставок * @property {object | null} [loyalty] *//** * Запрашивает getbuyerinfo (через tmst__fetchBuyerInfo), обновляет пункт "Мои адреса" * и виджет уровня лояльности. Сначала рисует ПЛ из tcart_discounts (без applyBuyerInfo). */function tma__loadBuyerInfo() { tma__onFuncLoad('tmst__fetchBuyerInfo', () => { const cache = typeof tmst__loyalty__readDiscountsCache === 'function' ? tmst__loyalty__readDiscountsCache() : null; const loyaltyFromLs = typeof tmst__loyalty__findLoyaltyDiscount === 'function' ? tmst__loyalty__findLoyaltyDiscount(cache && cache.discounts) : null; if (loyaltyFromLs && window.tildaMembers && window.tildaMembers.is_init_store) { if (typeof tmst__loyalty__createUserbarWidget === 'function') { tma__userbar__renderLoyaltyWidget(loyaltyFromLs); } else if (typeof t_onFuncLoad === 'function') { t_onFuncLoad('tmst__loyalty__createUserbarWidget', () => { tma__userbar__renderLoyaltyWidget(loyaltyFromLs); }); } } const path = typeof tma__getPath === 'function' ? tma__getPath() : []; const isDashboard = typeof tmst__loyalty__isMembersDashboardPath === 'function' && tmst__loyalty__isMembersDashboardPath(path); const shouldFetch = typeof tmst__loyalty__shouldFetchBuyerInfo !== 'function' || tmst__loyalty__shouldFetchBuyerInfo({ isDashboard: Boolean(isDashboard), cache }); if (!shouldFetch) return; const popup = document.querySelector('.tlk-userbar__popup-show'); const pendingEl = popup && popup.querySelector('.tlk-userbar__loyalty'); if (typeof tmst__loyalty__setUserbarWidgetPending === 'function') { tmst__loyalty__setUserbarWidgetPending(pendingEl, true); } tmst__fetchBuyerInfo() .then(data => { const deliveries = data && Array.isArray(data.deliveries) ? data.deliveries : []; tma__userbar__applyBuyerInfo({ hasAddresses: deliveries.length > 0, loyalty: data && data.loyalty ? data.loyalty : null, }); }) .catch(error => { console.info(error); const el = document.querySelector('.tlk-userbar__popup-show .tlk-userbar__loyalty'); if (typeof tmst__loyalty__setUserbarWidgetPending === 'function') { tmst__loyalty__setUserbarWidgetPending(el, false); } }); });}/** * @param {{ hasAddresses?: boolean, loyalty?: object | null }} data */function tma__userbar__applyBuyerInfo(data) { const hasAddresses = Boolean(data && data.hasAddresses); tma__createOrUpdateCSSClass('tlk-userbar__popup-store-item-addresses', 'tlk-userbar__popup-store-item-addresses', { display: hasAddresses ? 'block' : 'none', });