<script>
$(document).ready(function(){
let deliveriIndex = 2; //Номер позиции Самовывоза в списке
let discountTrigger = "price";
let codeList = [
[ 50, '10%' , 'DELIVERY' ], //Промокод в системе и размер его скидки в процентах
];
deliveriIndex--;
let triggerValue=0;
let currentDiscount = [];
let upswing=false;
let saveinputPC='';
let cartID = $('div[data-record-type="706"]').attr('id').replace(/[^0-9]/g, '');
let pcLid = $('.t-input-group_pc').attr('data-input-lid');
setTimeout(function(){ saveinputPC = $('.t-inputpromocode__wrapper').html()}, 1000);
function getDiscountInfo(trval){
let prevLine = 0;let minTotal = 0;
for(let i=0;i<codeList.length;i++){
if(trval >= codeList[i][0] && codeList[i][0] > prevLine ){prevLine = codeList[i][0];
for (let j=0;j<2;j++){currentDiscount[j]=codeList[i][j+1]};upswing=true;
}else if(trval < codeList[i][0]) minTotal++;
};
let radioIdx = $('input.t-radio_delivery').index($('input.t-radio_delivery:checked'));
if (minTotal == codeList.length && upswing || radioIdx < 1 ) {
currentDiscount = [];clearDiscount();upswing=false;
if(pcLid != undefined ){
$('.t-input-group_pc').show();
$('.t-inputpromocode__wrapper').html(saveinputPC);
t_input_promocode_init(cartID,pcLid);
};
};
if(currentDiscount.length && radioIdx>0 ){
$('.t-input-group_pc').hide();
window.tcart.promocode = {};
let totalWrap = $('.t706__cartwin-totalamount-wrap');
if(currentDiscount[0].indexOf('%') > 0 ){
window.tcart.promocode.discountpercent = (+currentDiscount[0].replace(/[^0-9.]/g, '')).toFixed(2);
clearTotalWrapClass();totalWrap.addClass('prcode_act_percent');
}else{
window.tcart.promocode.discountsum = currentDiscount[0]
clearTotalWrapClass();totalWrap.addClass('prcode_act_summ');
};
window.tcart.promocode.message = "OK";
window.tcart.promocode.promocode = currentDiscount[1];
tcart__updateTotalProductsinCartObj();
};
};
function clearTotalWrapClass(){ $('.t706__cartwin-totalamount-wrap').removeClass('prcode_act_percent prcode_act_summ')};
function clearDiscount(){
if ( window.tcart.hasOwnProperty("promocode") ){
delete window.tcart.promocode; tcart__updateTotalProductsinCartObj();clearTotalWrapClass();
};
};
$(".t706__cartwin-prodamount").bind( 'DOMSubtreeModified',function() {
if (discountTrigger=="price"){triggerValue = window.tcart.prodamount;}else{triggerValue = window.tcart.total}; getDiscountInfo(triggerValue);
});
});
</script>
<style>
.t706__cartwin-totalamount-wrap {
display: block !important;
order: -1;
margin-bottom: 25px;
}
span.t706__cartwin-totalamount-label:before {
content: "Сумма к оплате:";
position: absolute;
right: 10px;
width: 300%;
color: #000;
}
span.t706__cartwin-totalamount-label, .prcode_act_percent .t706__cartwin-totalamount-info span:nth-of-type(3) {
position: relative;
color: transparent;
}
.prcode_act_percent .t706__cartwin-totalamount-info span:nth-of-type(3):before {
content: "Скидка за самовывоз:";
position: absolute;
right: 1px;
width: 300%;
color: #000;
}
.prcode_act_summ .t706__cartwin-totalamount-info span:nth-of-type(3),
.prcode_act_summ .t706__cartwin-totalamount-info span:nth-of-type(4),
.prcode_act_summ .t706__cartwin-totalamount-info span:nth-of-type(4)+br {
display: none;
}
.t706 .t-form__inputsbox {
display: flex;
flex-direction: column;
}
.t706__cartwin-bottom {display: none}
.t706__orderform { margin-top: -5px}
</style>