Калькулятор доходности
650
р.
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>
document.addEventListener("DOMContentLoaded", function() {
    setTimeout(function() {
        t_onReady(function() {
            setTimeout(function() {
                t_onFuncLoad('tcart__init', function() {
                    setTimeout(initDeliveryTracking, 1500);
                });
            }, 200);
        });
    }, 0);
});

function initDeliveryTracking() {
    const deliveryWrapper = document.querySelector('.t-radio__wrapper-delivery');
    if (!deliveryWrapper) return;
    
    const DELIVERY_PHRASE = "с примеркой";
    const PAYMENT_INFO_TEXT = "Оплата товара после примерки";
    
    
    
    
    const PAYMENT_INFO_CLASS = "payment-info";
    

    let isCartOpenHandlerAdded = false;
    
    function getCurrentDelivery() {
        if (deliveryWrapper.id === "customdelivery") {
            return document.querySelector('input[name="tildadelivery-type"]:checked')?.value;
        } else {
            return document.querySelector('input.t-radio_delivery:checked')?.value;
        }
    }
    
    function updatePaymentInfo(show) {
        const totalRow = document.querySelector('.t706__cartwin-totalamount-row_total');
        if (!totalRow) return;
        
        let paymentInfo = document.querySelector('.' + PAYMENT_INFO_CLASS);
        
        if (show) {
            if (!paymentInfo) {
                paymentInfo = document.createElement('div');
                paymentInfo.className = PAYMENT_INFO_CLASS;
                paymentInfo.textContent = PAYMENT_INFO_TEXT;
                totalRow.parentNode.insertBefore(paymentInfo, totalRow);
            } else {
                paymentInfo.textContent = PAYMENT_INFO_TEXT;
                const nextSibling = paymentInfo.nextElementSibling;
                if (nextSibling !== totalRow) {
                    totalRow.parentNode.insertBefore(paymentInfo, totalRow);
                }
            }
        } else {
            if (paymentInfo) {
                paymentInfo.remove();
            }
        }
    }
    
   
    function applyDeliveryLogic() {
        const currentDelivery = getCurrentDelivery();
        if (currentDelivery) {
            handleDeliveryChange(currentDelivery);
        } else {
 
            setTimeout(function() {
                const retryDelivery = getCurrentDelivery();
                if (retryDelivery) {
                    handleDeliveryChange(retryDelivery);
                }
            }, 300);
        }
    }
    
    function handleDeliveryChange(deliveryText) {
        if (!deliveryText) {
            updatePaymentInfo(false);
            return;
        }
        
        const hasFitting = deliveryText.includes(DELIVERY_PHRASE);
        updatePaymentInfo(hasFitting);
        
        if (hasFitting) {
            if (typeof tcart !== 'undefined' && tcart.delivery) {
                tcart.amount = tcart.delivery.price;
                if (typeof tcart__reDrawTotal === 'function') {
                    tcart__reDrawTotal();
                }
            }
        }
    }
    

    function setupCartOpenHandler() {
        if (isCartOpenHandlerAdded) return;
        
        const openCartOriginal = window.tcart__openCart;
        if (typeof openCartOriginal !== 'function') {
      
            setTimeout(setupCartOpenHandler, 500);
            return;
        }
        
        isCartOpenHandlerAdded = true;
        
        window.tcart__openCart = function(...args) {
           
            setTimeout(function() {
                applyDeliveryLogic();
            }, 300);
            
            return openCartOriginal.apply(this, args);
        };
    }
    
    function initializeOnLoad() {
        setTimeout(function() {
            applyDeliveryLogic();
         
            setupCartOpenHandler();
        }, 300);
    }

    if (deliveryWrapper.id === "customdelivery") {
        let observer = new MutationObserver(function() {
            setTimeout(function() {
                const checkedDelivery = document.querySelector('input[name="tildadelivery-type"]:checked');
                if (checkedDelivery) {
                    handleDeliveryChange(checkedDelivery.value);
                }
            }, 300);
        });
        observer.observe(deliveryWrapper, { childList: true, subtree: true });
        initializeOnLoad();
    } else {
        deliveryWrapper.addEventListener('change', function(event) {
            if (event.target.matches('input.t-radio_delivery')) {
                setTimeout(function() {
                    const checkedDelivery = document.querySelector('input.t-radio_delivery:checked');
                    if (checkedDelivery) {
                        handleDeliveryChange(checkedDelivery.value);
                    }
                }, 100);
            }
        });
        initializeOnLoad();
    }
}
</script>

<style>
.t706__cartwin-totalamount-row_total {
    order: 10;
}
.payment-info {
    order: 9;
    padding-top: 10px;
    margin-bottom: 10px;
    color: #17212c;
    text-transform: uppercase;
    font-size: 16px;
    font-weight: 600;
    border-top: 1px solid rgba(0, 0, 0, .1);
}
.t706__cartwin-totalamount-wrap_flextotals .t706__cartwin-totalamount-row_before-total {
    padding-bottom: 10px;
}    
</style>
Made on
Tilda