task: 6753 | убрал функцию отмены удаления в корзине

dev_10_refactoring
parent 995a09cc2d
commit 7825f00ae6
  1. 3
      wp-content/themes/cosmopet/modules/blog/assets/css/gp-style-desktop.css
  2. 61
      wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js
  3. 1
      wp-content/themes/cosmopet/static/front-page/css/style.css
  4. 68
      wp-content/themes/cosmopet/temp-functions/cart-logic.php

@ -88,3 +88,6 @@ main{
margin-left: auto;
width: max-content;
}

@ -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);

@ -4552,7 +4552,6 @@ color: #f4f1f0;
.modal__aside {
position: fixed;
transition: right 0.3s ease-in-out;
right: -400px;
}
.modal__aside.active {

@ -1,70 +1,2 @@
<?php
add_action('wp_ajax_get_cart_fragment', 'get_cart_fragment_callback');
add_action('wp_ajax_nopriv_get_cart_fragment', 'get_cart_fragment_callback');
function get_cart_fragment_callback() {
// Проверяем nonce для безопасности
check_ajax_referer('woocommerce-cart', 'security', false);
// Получаем содержимое корзины
ob_start();
wc_get_template('shop/cart-contents.twig', [], '', get_template_directory() . '/templates/');
$contents = ob_get_clean();
// Получаем футер корзины
ob_start();
wc_get_template('modal-basket-footer.twig', [], '', get_template_directory() . '/templates/');
$footer = ob_get_clean();
// Получаем данные корзины
$cart = WC()->cart;
$count = $cart->get_cart_contents_count();
$total = $cart->get_total('raw'); // Числовая сумма
$total_html = wc_cart_totals_order_total_html(); // Форматированная сумма
wp_send_json_success([
'contents' => $contents,
'footer' => $footer,
'count' => $count,
'total' => $total_html,
'total_raw' => $total
]);
}
add_action('template_redirect', 'custom_redirect_cart_page');
function custom_redirect_cart_page() {
if (is_cart()) {
wp_redirect(home_url('/'));
exit;
}
}
add_action('wp_enqueue_scripts', 'remove_woocommerce_styles_on_checkout', 9999);
function remove_woocommerce_styles_on_checkout() {
// Проверяем, что мы на странице чекаута
if (function_exists('is_checkout') && is_checkout() && !is_order_received_page()) {
wp_deregister_style('woocommerce-layout');
wp_deregister_style('woocommerce-smallscreen');
wp_deregister_style('woocommerce-general');
// Дополнительно: отключить другие стили WooCommerce
wp_dequeue_style('select2');
wp_deregister_style('select2');
}
}
add_action('wp_head', 'custom_checkout_padding');
function custom_checkout_padding() {
// Проверяем, что это страница Checkout
if (is_checkout() && !is_admin()) {
?>
<style type="text/css">
main.wrapper {
padding-top: 100px;
padding-bottom: 50px;
}
</style>
<?php
}
}

Loading…
Cancel
Save