diff --git a/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/js/script.js b/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/js/script.js index fafa1a1..e5e05eb 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/js/script.js +++ b/wp-content/themes/cosmopet/modules/shop/components/checkout/assets/js/script.js @@ -151,182 +151,14 @@ jQuery(document).ready(function ($) { $('#delete_coupon').on('click', function(){ $('.woocommerce-remove-coupon[data-coupon=' + $(this).data('coupon') + ']').click() + $('#promo_form').show() + $('#promo_delete').hide() }) $('.woocommerce-remove-coupon').on('click', function(){ - $('#promo_form').show() - $('#promo_delete').hide() + $('#promo_delete').hide() }) }); -jQuery(document).ready(function($) { - // Функция для получения активных фильтров из URL - function getActiveFilters() { - const params = new URLSearchParams(window.location.search); - const filters = []; - - params.forEach((value, key) => { - if (key.startsWith('filter_') || key === 'min_price' || key === 'max_price') { - let filterName = key.replace('filter_', '').replace('_', ' '); - let filterValue = value.split(',').map(val => decodeURIComponent(val.replace(/\+/g, ' '))); - - if (key === 'min_price') { - filterName = 'Цена от'; - filterValue = [value + ' ₽']; - } else if (key === 'max_price') { - filterName = 'Цена до'; - filterValue = [value + ' ₽']; - } - - filters.push({ - key: key, - name: filterName.charAt( W1).toUpperCase() + filterName.slice(1), - values: filterValue - }); - } - }); - - return filters; - } - - // Функция для отображения активных фильтров - function displayActiveFilters() { - const $filterList = $('.active-filters__list'); - const $filterContainer = $('.active-filters'); - const $clearButton = $('.active-filters__clear'); - $filterList.empty(); - - const activeFilters = getActiveFilters(); - - if (activeFilters.length > 0) { - $filterContainer.show(); - $clearButton.show(); - - activeFilters.forEach(filter => { - filter.values.forEach(value => { - const $filterTag = $('', { - class: 'active-filters__tag', - html: `${filter.name}: ${value} ×` - }); - $filterList.append($filterTag); - }); - }); - W2 else { - $filterContainer.hide(); - $clearButton.hide(); - } - } - - // Инициализация при загрузке страницы - displayActiveFilters(); - - // Обновление фильтров после AJAX-фильтрации - $(document).on('wcpf_after_filtering', function() { - displayActiveFilters(); - }); - - // Удаление фильтра - $(document).on('click', '.active-filters__remove', function() { - const key = $(this).data('key'); - const value = $(this).data('value'); - const params = new URLSearchParams(window.location.search); - - if (key === 'min_price' || key === 'max_price') { - params.delete(key); - } else { - let values = params.get(key) ? params.get(key).split(',') : []; - values = values.filter(val => decodeURIComponent(val.replace(/\+/g, ' ')) !== value); - if (values.length > 0) { - params.set(key, values.join(',')); - } else { - params.delete(key); - } - } - - const newUrl = window.location.pathname + (params.toString() ? '?' + params.toString() : ''); - window.history.pushState({}, '', newUrl); - - // Запуск AJAX-фильтрации - $.ajax({ - url: wc_checkout_params.ajax_url, - type: 'POST', - data: { - action: 'wcpf_filter', - query: params.toString(), - category_id: $('#load-more-products').data('category_id'), - category_type: $('#load-more-products').data('category_type') - }, - success: function(response) { - if (response.success) { - $('.product__main').html(response.data.products); - displayActiveFilters(); - $(document.body).trigger('wc_fragments_refreshed'); - } - }, - error: function() { - alert('Ошибка при обновлении фильтров'); - } - }); - }); - - // Очистка всех фильтров - $(document).on('click', '.active-filters__clear', function() { - const params = new URLSearchParams(window.location.search); - const newUrl = window.location.pathname; - window.history.pushState({}, '', newUrl); - - $.ajax({ - url: wc_checkout_params.ajax_url, - type: 'POST', - data: { - action: 'wcpf_filter', - query: '', - category_id: $('#load-more-products').data('category_id'), - category_type: $('#load-more-products').data('category_type') - }, - success: function(response) { - if (response.success) { - $('.product__main').html(response.data.products); - displayActiveFilters(); - $(document.body).trigger('wc_fragments_refreshed'); - } - }, - error: function() { - alert('Ошибка при очистке фильтров'); - } - }); - }); - // Обработка загрузки дополнительных продуктов - $(document).on('click', '#load-more-products', function() { - const $button = $(this); - const categoryId = $button.data('category_id'); - const categoryType = $button.data('category_type'); - const page = parseInt($button.data('page') || 1) + 1; - - $.ajax({ - url: wc_checkout_params.ajax_url, - type: 'POST', - data: { - action: 'load_more_products', - category_id: categoryId, - category_type: categoryType, - page: page, - query: window.location.search - }, - success: function(response) { - if (response.success) { - $('.product__main').append(response.data.products); - $button.data('page', page); - if (!response.data.has_more) { - $button.hide(); - } - } - }, - error: function() { - alert('Ошибка при загрузке продуктов'); - } - }); - }); -});