|
|
|
@ -143,59 +143,7 @@ jQuery(document).ready(function($) { |
|
|
|
|
const variationId = $item.data('variation_id') || 0; |
|
|
|
|
const quantity = parseInt($item.find('.counter__input').val()); |
|
|
|
|
|
|
|
|
|
// Сохраняем во временное хранилище
|
|
|
|
|
const removedItems = JSON.parse(localStorage.getItem(removedItemsStorageKey)) || []; |
|
|
|
|
removedItems.push({ product_id: productId, variation_id: variationId, quantity: quantity, key: key }); |
|
|
|
|
localStorage.setItem(removedItemsStorageKey, JSON.stringify(removedItems)); |
|
|
|
|
|
|
|
|
|
// Показываем кнопку восстановления
|
|
|
|
|
$item.html(` |
|
|
|
|
<p class="modal-basket-item__title"> |
|
|
|
|
Removing an item from the cart: <span id="${key}_timer" class="timer_counter">5</span>с |
|
|
|
|
</p> |
|
|
|
|
<div class="modal-basket-item__return-wrapper"> |
|
|
|
|
<button class="modal-basket-item__return" data-key="${key}"> |
|
|
|
|
${woocommerce_params.i18n_restore_item || 'Restore'} |
|
|
|
|
</button> |
|
|
|
|
</div> |
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
// Проверяем количество товаров в корзине
|
|
|
|
|
$.ajax({ |
|
|
|
|
type: 'POST', |
|
|
|
|
url: woocommerce_params.ajax_url, |
|
|
|
|
data: { |
|
|
|
|
action: 'check_cart_count' |
|
|
|
|
}, |
|
|
|
|
success: function(response) { |
|
|
|
|
if (response.success && response.data.count <= 1) { |
|
|
|
|
// Если после удаления корзина станет пустой (1 товар сейчас, удаляем его)
|
|
|
|
|
$('.proceed-to-checkout').css('display', 'none'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Удаляем через 5 секунд, если не восстановили
|
|
|
|
|
const removeTimeout = setTimeout(() => { |
|
|
|
|
permanentRemoveItem(key, productId, variationId); |
|
|
|
|
}, 5000); |
|
|
|
|
|
|
|
|
|
const product_remove_timer = setInterval(() => { |
|
|
|
|
let number = Number($(`#${key}_timer`).html()) - 1; |
|
|
|
|
$(`#${key}_timer`).html(number); |
|
|
|
|
}, 1000); |
|
|
|
|
|
|
|
|
|
// Обработчик восстановления
|
|
|
|
|
$(document).off('click', `[data-key="${key}"] .modal-basket-item__return`).on('click', `[data-key="${key}"] .modal-basket-item__return`, function(e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
clearTimeout(removeTimeout); |
|
|
|
|
clearInterval(product_remove_timer); // Очищаем интервал
|
|
|
|
|
restoreItem(key, productId, variationId, quantity); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Полное удаление товара
|
|
|
|
|
function permanentRemoveItem(key, productId, variationId) { |
|
|
|
|
$('#modal-basket').addClass('loading'); |
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
@ -217,13 +165,15 @@ jQuery(document).ready(function($) { |
|
|
|
|
); |
|
|
|
|
localStorage.setItem(removedItemsStorageKey, JSON.stringify(updatedItems)); |
|
|
|
|
|
|
|
|
|
updateCartFragment(false); |
|
|
|
|
$('[data-key="' + key + '"]').remove() |
|
|
|
|
updateCartFragment(); |
|
|
|
|
// $('[data-key="' + key + '"]').remove()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Восстановление товара
|
|
|
|
|
function restoreItem(key, productId, variationId, quantity) { |
|
|
|
|
$('#modal-basket').addClass('loading'); |
|
|
|
@ -359,8 +309,9 @@ jQuery(document).ready(function($) { |
|
|
|
|
beforeSend: function() { |
|
|
|
|
$('#modal-basket').addClass('loading'); |
|
|
|
|
}, |
|
|
|
|
complete: function() { |
|
|
|
|
complete: function(response) { |
|
|
|
|
$('#modal-basket').removeClass('loading'); |
|
|
|
|
console.log(response) |
|
|
|
|
}, |
|
|
|
|
success: function(response) { |
|
|
|
|
console.log(response); |
|
|
|
|