/* Автор скрипта - Александр Нагиян */ /* ТГ-канал - https://t.me/nagiyan_gc */ /* Магазин готовых решений - https://script-shop.ru/main?utm_source=school&utm_medium=js&utm_campaign=procents-in-offer */ $(function(){ if (window.location.href.includes('/pl/sales/offer/update')) { let discountSum = $('.source-price').val() $('.only-with-discount[style]').before(`
В процентах
`) $('.standard-money-field').after(`
%
`) $('.bonus-limit-field').append(`
%
`) //Скидка if ($('.only-with-discount input.discount-value').val() !== '') { let discountVal = ($('.only-with-discount input.discount-value').val() / $('.source-price').val() * 100).toFixed(2) $('.only-with-discount.percent input').val(discountVal) } $('.only-with-discount.percent input').on('input', function(){ let discountVal = ($('.source-price').val() * $(this).val() / 100).toFixed(2) $('.only-with-discount input.discount-value').val(discountVal) $('.only-with-discount input.discount-value').change() }) $('.only-with-discount input.discount-value').on('input', function(){ let discountPercentVal = ($(this).val() / $('.source-price').val() * 100).toFixed(2) $('.only-with-discount.percent input').val(discountPercentVal) }) //Сумма частичной оплаты if ($('.standard-money-field:not(.percent) input').val() !== '') { let discountVal = ($('.standard-money-field:not(.percent) input').val() / $('.source-price').val() * 100).toFixed(2) $('.standard-money-field.percent input').val(discountVal) } $('.standard-money-field.percent input').on('input', function(){ let partialPayVal = ($('.source-price').val() * $(this).val() / 100).toFixed(2) $('.standard-money-field:not(.percent) input').val(partialPayVal) }) $('.standard-money-field:not(.percent) input').on('input', function(){ let partialPayValPercent = ($(this).val() / $('.source-price').val() * 100).toFixed(2) $('.standard-money-field.percent input').val(partialPayValPercent) }) //Бонусные рубли if ($('.bonus-limit-block .highlight-addon .discount-value').val() !== '') { let bonusVal = ($('.bonus-limit-block .highlight-addon .discount-value').val() / $('.source-price').val() * 100).toFixed(2) $('.percent-bonus-block input').val(bonusVal) } $('.percent-bonus-block input').on('input', function(){ let bonusVal = ($('.source-price').val() * $(this).val() / 100).toFixed(2) $('.bonus-limit-block .highlight-addon .discount-value').val(bonusVal) }) $('.bonus-limit-block .highlight-addon .discount-value').on('input', function(){ let bonusValPercent = ($(this).val() / $('.source-price').val() * 100).toFixed(2) $('.percent-bonus-block input').val(bonusValPercent) }) } })