<script>
$(document).ready(function(){
//Контроль скидки по итоговой сумме или кол-ву товара
let discountTrigger = "price"; // price - цена, quantity - кол-во
// 5% - скидка в процентах, 3000 - вычесть число от суммы
let codeList = [// триггер, скидка, имя помокода,
[ 8700, '3%' , 'D3' ],
[ 11800, '5%' , 'D5' ],
[ 15600, '7%' , 'D7' ],
[ 21900, '10%' , 'D10' ]
];
let warning = `<div class="warn-wrap">До скидки <span class="d-percent"></span> осталось <span class="d-summ"></span> руб</div>`;
setTimeout(function(){
$('.t706__cartwin-totalamount-wrap').append(warning);
}, 1000);
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++;
};
if (minTotal == codeList.length && upswing) {
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){
$('.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() {
$.each(codeList , function(index, val) {
let prSumm = +tcart.prodamount;
let sumCode = +val[0];
if( prSumm<sumCode){
$('.warn-wrap').show();
$('.d-percent').html(val[1]);
$('.d-summ').html( (sumCode-prSumm).toLocaleString());
return false;
}else{
$('.warn-wrap').hide();
};
});
if (discountTrigger=="price"){triggerValue = window.tcart.prodamount;}else{triggerValue = window.tcart.total}; getDiscountInfo(triggerValue);
});
});
</script>
<style>
.warn-wrap {
color: #FF5722;
}
.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>