From 62cced0e1a936abae6eaea06c9525623855af11b Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 16 Jun 2025 12:21:38 +0300 Subject: [PATCH] =?UTF-8?q?Andrei=20|=20fix=20=D0=B8=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BF=D0=BB=D0=B0=D1=88=D0=B5=D0=BA=20=D1=84=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D1=82=D1=80=D0=B0=20(=D0=BD=D0=B5=20=D0=B2=D1=8B=D0=B2=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B8=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D1=8F=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B5?= =?UTF-8?q?=D1=81=D0=BB=D0=B8=20=D0=B2=D1=8B=D0=B1=D1=80=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D0=BE=D0=B4=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catalog/component-controller.php | 2 +- .../_pages/shop/archive-product.twig | 57 ++++--- .../archive-product/archive-product.twig | 157 ------------------ 3 files changed, 36 insertions(+), 180 deletions(-) delete mode 100644 wp-content/themes/cosmopet/templates/archive-product/archive-product.twig diff --git a/wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php index 41ce8bf..2eccb89 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php @@ -19,7 +19,7 @@ $raw_taxonomy = str_replace('wpf_filter_', '', $key); error_log("→ Обнаружен фильтр: $raw_taxonomy"); - $slugs = is_array($value) ? $value : explode(',', $value); + $slugs = is_array($value) ? $value : preg_split('/[\|,]/', $value); error_log("→ Slugs: " . implode(', ', $slugs)); // Попробуем с pa_ и без, в зависимости от существования таксономии diff --git a/wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig b/wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig index 4e8c738..fd1da69 100644 --- a/wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig +++ b/wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig @@ -103,35 +103,48 @@ document.addEventListener("DOMContentLoaded", () => { }); }); - // Обработка клика на отдельные теги активных фильтров - const activeFilterTags = document.querySelectorAll('.active-filter-tag'); - activeFilterTags.forEach(tag => { - tag.addEventListener('click', () => { - const slug = tag.dataset.filterSlug; - const taxonomy = tag.dataset.filterTaxonomy; +// Обработка клика на теги активных фильтров +document.querySelectorAll('.active-filter-tag').forEach(tag => { + tag.addEventListener('click', function(e) { + e.preventDefault(); + const slug = this.dataset.filterSlug; + const taxonomy = this.dataset.filterTaxonomy; + const urlParam = 'wpf_filter_' + taxonomy.replace('pa_', ''); + + const url = new URL(window.location.href); + const params = new URLSearchParams(url.search); + + if (params.has(urlParam)) { + const currentValue = params.get(urlParam); - // Убираем префикс pa_ если есть для формирования параметра URL - const rawTaxonomy = taxonomy.replace('pa_', ''); - const param = 'wpf_filter_' + rawTaxonomy; + // Разделяем значения, учитывая как закодированные, так и обычные разделители + let values = currentValue.split(/\||%7C|,/); - const url = new URL(window.location.href); - const params = new URLSearchParams(url.search); - - if (params.has(param)) { - let values = params.get(param).split(','); - values = values.filter(v => v !== slug); - - if (values.length > 0) { - params.set(param, values.join(',')); - } else { - params.delete(param); + // Декодируем и фильтруем значения + const newValues = values.filter(v => { + return decodeURIComponent(v.trim()) !== slug.trim(); + }); + + // Обновляем URL параметры + if (newValues.length > 0) { + // Используем | как разделитель (можно заменить на ',', если нужно) + params.set(urlParam, newValues.join('|')); + } else { + params.delete(urlParam); + // Дополнительно очищаем связанные параметры + if (urlParam.includes('price')) { + params.delete('wpf_min_price'); + params.delete('wpf_max_price'); } + params.delete('wpf_fbv'); } + // Обновляем URL и перезагружаем страницу url.search = params.toString(); - window.location.href = url.toString(); - }); + window.location.href = url.href; + } }); +}); // Обработка кнопки "Очистить все" const clearAllBtn = document.querySelector('.active-filters__clear'); diff --git a/wp-content/themes/cosmopet/templates/archive-product/archive-product.twig b/wp-content/themes/cosmopet/templates/archive-product/archive-product.twig deleted file mode 100644 index fc1e64d..0000000 --- a/wp-content/themes/cosmopet/templates/archive-product/archive-product.twig +++ /dev/null @@ -1,157 +0,0 @@ -{% set bodyClass = 'bg-white' %} -{% set mainClass = 'wrapper' %} -{% extends 'layout.twig' %} - -{% block content %} - - {% if site_region == 'ru' %} - - {% endif %} - - - -
-
-

- {% if category %} - {{ category.name }} - {% else %} - {{ function('pll_e', 'Продукция') }} - {% endif %} -

- - -
- - {% if active_filters|length > 0 %} -
- {% if active_filters is not empty %} -
- {% for filter in active_filters %} - - {{ filter.name }} × - - {% endfor %} -
- {% endif %} - - -
- {% endif %} - -
- {% for post in posts %} - {% include 'archive-product/archive-product-tease.twig' with {post: post} %} - {% endfor %} -
- - -
- - - - -{% endblock %} \ No newline at end of file