Studio Headphones
SKU: 700.954.29
1000
₽
When we first checked out our new headphones, we noticed the box said “improved bass”. We had to wonder if this was marketing jargon or the real thing? But it only took a moment to realize that bass was not kidding.
<script>
(function () {

    const PROMO_LIMITS = {
        "HELLO": 6000,
        "DELIVERY": 10000,
        "BONUS": 15000
    };

    const PROMO_ERROR_TEXT = 'Этот промокод можно использовать при сумме заказа от <strong>{summ_limit} руб</strong>';

    function formatSum(n) {
        return Number(n).toLocaleString('ru-RU');
    }

    function getErrorText(limit) {
        return PROMO_ERROR_TEXT.replace('{summ_limit}', formatSum(limit));
    }

    t_onReady(function () {
        setTimeout(function () {
            t_onFuncLoad('tcart__init', function () {
                promocodeControl();
            });
        }, 200);
    });

    function promocodeControl() {
        delete t_cart__discounts;

        let saveinputPC = null;
        const cartID = document.querySelector('div[data-record-type="706"]')?.getAttribute('id').replace(/[^0-9]/g, '');
        const pcLid = document.querySelector('.t-input-group_pc')?.getAttribute('data-input-lid');

        if (!pcLid) return;

    
        let wrapperPromocode = null;
        let errorEl = null;

       
        function setupDom() {
            const promocodeBtn = document.querySelector('.t-inputpromocode__btn');
            const promoWrapperEl = document.querySelector('.t-inputpromocode__wrapper');
            if (!promocodeBtn || !promoWrapperEl) return;

   
            wrapperPromocode = document.querySelector('.pcodeWrp');
            if (!wrapperPromocode) {
                wrapperPromocode = document.createElement('div');
                wrapperPromocode.classList.add('pcodeWrp');
                promocodeBtn.parentNode.insertBefore(wrapperPromocode, promocodeBtn);
            }
          
            if (promocodeBtn.parentNode !== wrapperPromocode) {
                wrapperPromocode.appendChild(promocodeBtn);
            }
           
            wrapperPromocode.classList.remove('blok-promo');

            
            errorEl = document.querySelector('.pcode-error');
            if (!errorEl) {
                errorEl = document.createElement('div');
                errorEl.className = 'pcode-error t-text';
                errorEl.style.display = 'none';
                promoWrapperEl.parentNode.insertBefore(errorEl, promoWrapperEl.nextSibling);
            }
        }

        setupDom();
        saveinputPC = document.querySelector('.t-inputpromocode__wrapper').innerHTML;

        function showError(html) {
            if (!errorEl) setupDom();
            if (!errorEl) return;
            errorEl.innerHTML = html;
            errorEl.style.display = 'block';
        }
        function clearError() {
            if (!errorEl) return;
            errorEl.innerHTML = '';
            errorEl.style.display = 'none';
        }

       
        function getInputPromo() {
            const input = document.querySelector('.t-inputpromocode__input')
                       || document.querySelector('.t-inputpromocode__wrapper input');
            return (input?.value || '').trim().toUpperCase();
        }

        function getAppliedPromo() {
            const pc = window.tcart?.promocode;
            if (!pc) return '';
            const raw = pc.promocode || pc.code || pc.title || pc.name || '';
            return String(raw).trim().toUpperCase();
        }

        function checkPromo(promo) {
            if (!promo || !(promo in PROMO_LIMITS)) return { restricted: false };
            const limit = PROMO_LIMITS[promo];
            const summ = +tcart.prodamount;
            return { restricted: true, limit, insufficient: summ < limit };
        }

        
        document.addEventListener('click', function (event) {
            const btn = event.target.closest('.t-inputpromocode__btn');
            if (!btn) return;

            const promo = getInputPromo();
            const check = checkPromo(promo);

            if (check.restricted && check.insufficient) {
                showError(getErrorText(check.limit));
                event.preventDefault();
                event.stopPropagation();
                event.stopImmediatePropagation();
                return false;
            }

            clearError();
        }, true);

        
        document.addEventListener('input', function (event) {
            if (event.target.closest('.t-inputpromocode__wrapper')) {
                clearError();
            }
        });

        
        function changePromo() {
            const summ = +tcart.prodamount;
            const promo = getAppliedPromo();
            const check = checkPromo(promo);

            if (check.restricted && check.insufficient) {
            
                if (window.tcart.promocode?.message === 'OK') {
                    delete window.tcart.promocode;
                    tcart__updateTotalProductsinCartObj();
                    tcart__reDrawTotal();
                    document.querySelector('.t-inputpromocode__wrapper').innerHTML = saveinputPC;
                    const promocodeTitle = document.querySelector('.t-input-group_pc .t-input-title');
                    if (promocodeTitle) promocodeTitle.style.visibility = '';
                    t_input_promocode_init(cartID, pcLid);

                    
                    setupDom();
                }
                showError(getErrorText(check.limit));
            } else {
                clearError();
            }
        }

        changePromo();

        const observer = new MutationObserver(function () {
            changePromo();
        });
        const elem = document.querySelector('.t706__cartwin-products');
        if (elem) {
            observer.observe(elem, {
                childList: true,
                subtree: true,
                characterDataOldValue: true
            });
        }
    }
})();
</script>

<style>
.t-inputpromocode__wrapper {
    display: flex !important;
}
.t-inputpromocode__btn {
    height: 56px !important;
}
.pcodeWrp {
    cursor: pointer;
}
.pcodeWrp.blok-promo > div {
    pointer-events: none;
}
.pcode-error {
    color: red;
    font-size: 14px;
    font-weight: 400;
    margin-top: 8px;
    line-height: 1.3;
}
</style>
Made on
Tilda