Перейти к содержимому


[Fix] Баг С Количеством Товара В Корзине


  • Авторизуйтесь для ответа в теме
В этой теме нет ответов

#1 Mr.Nito

Mr.Nito

    Активный участник

  • Модераторы
  • 1 364 сообщений

Отправлено 03 Март 2021 - 15:55

В файле main.js заменить
// Корзина
function ajaxnewqty(){
$('.cartqty').change(function(){
s = $(this);
id = $(this).closest('tr').data('id');
qty = $(this).val();
if(qty < 1) {
	 s.val(1)
}
data = $('.cartForm').serializeArray();
data.push({name: 'only_body', value: 1});
$('tr[data-id="' + id + '"] .ajaxtotal').css('opacity','0');
$('.TotalSum').css('opacity','0');
$.ajax({
	 data: data,
	 cache:false,
	 success:function(d){	
	 s.val($(d).find('tr[data-id="' + id + '"] .cartqty').val())
	 $('tr[data-id="' + id + '"] .ajaxtotal').css('opacity','1');
	 $('.TotalSum').css('opacity','1');
	 tr = $('tr[data-id="' + id + '"]');
	 tr.find('.ajaxtotal').html($(d).find('tr[data-id="' + id + '"] .ajaxtotal').html());
	 $('.TotalSum').html($(d).find('.TotalSum').html());
	 $('.discounttr').each(function(){
		 $(this).remove();
	 });
	 $(d).find('.discounttr').each(function(){
		 $('.cartTable tfoot tr:first-child').before($(this));
	 });
	 c = $(d).find('tr[data-id="' + id + '"] .cartqty');
	 qw = c.val();
	 if(qty > qw){
		 $('.cartErr').remove();
		 $('.cartTable').before('<div class="cartErr warning">Вы пытаетесь положить в корзину товара больше, чем есть в наличии</div>');
		 $('.cartErr').fadeIn(500).delay(2500).fadeOut(500, function(){$('.cartErr').remove();});
		 $('.cartqty').removeAttr('readonly');
	 }
	 }
})
})
}
на
// Корзина
function ajaxnewqty(){
$('.cartqty').change(
$.debounce(300,
function(){
	 s = $(this);
	 id = $(this).closest('tr').data('id');
	 qty = $(this).val();
	 dontPutMore = $(this).data('dont-put-more');
	 if(qty < 1) {
	 s.val(1)
	 }
	 data = $('.cartForm').serializeArray();
	 data.push({name: 'only_body', value: 1});
	 $('tr[data-id="' + id + '"] .ajaxtotal').css('opacity','0');
	 $('.TotalSum').css('opacity','0');
	 $.ajax({
	 data: data,
	 cache:false,
	 success:function(d){	
		 s.val($(d).find('tr[data-id="' + id + '"] .cartqty').val())
		 $('tr[data-id="' + id + '"] .ajaxtotal').css('opacity','1');
		 $('.TotalSum').css('opacity','1');
		 tr = $('tr[data-id="' + id + '"]');
		 tr.find('.ajaxtotal').html($(d).find('tr[data-id="' + id + '"] .ajaxtotal').html());
		 $('.TotalSum').html($(d).find('.TotalSum').html());
		 $('.discounttr').each(function(){
		 $(this).remove();
		 });
		 $(d).find('.discounttr').each(function(){
		 $('.cartTable tfoot tr:first-child').before($(this));
		 });
		 c = $(d).find('tr[data-id="' + id + '"] .cartqty');
		 qw = c.val();
		 if(Number(qty) > Number(qw) && dontPutMore){
		 $('.cartErr').remove();
		 $('.cartTable').before('<div class="cartErr warning">Вы пытаетесь положить в корзину товара больше, чем есть в наличии</div>');
		 $('.cartErr').fadeIn(500).delay(2500).fadeOut(500, function(){$('.cartErr').remove();});
		 $('.cartqty').removeAttr('readonly');
		 }
	 }
	 })
})
)
}
В шаблоне Корзина заменить
<input name="form[quantity][{cart_items.GOODS_MOD_ID}]" value="{cart_items.ORDER_LINE_QUANTITY}" title="Количество, {cart_items.GOODS_MOD_MEASURE_NAME}" class="input cartqty" type="number" maxlength="5" min="1" onkeypress="return keyPress(this, event);" onpaste="return false;" />
на
<input {% IF SETTINGS_GOODS_DONT_PUT_TO_CART_MORE_THAN_AVAILABLE %}data-dont-put-more{% ENDIF %} name="form[quantity][{cart_items.GOODS_MOD_ID}]" value="{cart_items.ORDER_LINE_QUANTITY}" title="Количество, {cart_items.GOODS_MOD_MEASURE_NAME}" class="input cartqty" type="number" maxlength="5" min="1" onkeypress="return keyPress(this, event);" onpaste="return false;" />





Количество пользователей, читающих эту тему: 0

0 пользователей, 0 гостей, 0 анонимных