From d651b4f03a99ada9052af62c282b928d54fd03fa Mon Sep 17 00:00:00 2001 From: maksim Date: Mon, 16 Jun 2025 14:06:30 +0300 Subject: [PATCH] =?UTF-8?q?Task:6787=20|=20=D0=9F=D0=B5=D1=80=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20=D1=84=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D1=82=D1=80=D0=B0,=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../popup/assets/css/gp-style-desktop.css | 5 + .../catalog/component-controller.php | 187 ++++++++++-------- 2 files changed, 106 insertions(+), 86 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/popup/assets/css/gp-style-desktop.css b/wp-content/themes/cosmopet/modules/popup/assets/css/gp-style-desktop.css index 3b39de9..5f7413d 100644 --- a/wp-content/themes/cosmopet/modules/popup/assets/css/gp-style-desktop.css +++ b/wp-content/themes/cosmopet/modules/popup/assets/css/gp-style-desktop.css @@ -28,6 +28,11 @@ filter: blur(0); } +.wpfFilterLayoutVer, .wpfFilterLayoutHor { + display: grid; + grid-template-columns: repeat(2, 1fr); +} + @media (max-width: 720px) { .modal__aside { width: 100% !important; /* Полная ширина на мобильных */ 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..1adf128 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 @@ -1,17 +1,26 @@ attribute_name; + $valid_taxonomies[$taxonomy] = $attr->attribute_label; + } + error_log('→ Доступные таксономии атрибутов: ' . implode(', ', array_keys($valid_taxonomies))); + foreach ($_GET as $key => $value) { error_log("Ключ: $key => " . print_r($value, true)); @@ -19,25 +28,37 @@ $raw_taxonomy = str_replace('wpf_filter_', '', $key); error_log("→ Обнаружен фильтр: $raw_taxonomy"); - $slugs = is_array($value) ? $value : explode(',', $value); + $slugs = is_array($value) ? $value : explode('|', $value); error_log("→ Slugs: " . implode(', ', $slugs)); - // Попробуем с pa_ и без, в зависимости от существования таксономии $taxonomy = taxonomy_exists('pa_' . $raw_taxonomy) ? 'pa_' . $raw_taxonomy : $raw_taxonomy; - - foreach ($slugs as $slug) { - $term = get_term_by('slug', $slug, $taxonomy); - - if ($term) { - error_log("✔ Найден термин: {$term->name} (ID: {$term->term_id}) в таксономии: $taxonomy"); + error_log("→ Проверяемая таксономия: $taxonomy, существует: " . (taxonomy_exists($taxonomy) ? 'Да' : 'Нет')); + + if (taxonomy_exists($taxonomy)) { + foreach ($slugs as $slug) { + $term = get_term_by('slug', $slug, $taxonomy); + if ($term) { + error_log("✔ Найден термин: {$term->name} (ID: {$term->term_id}) в таксономии: $taxonomy"); + $filters[] = [ + 'id' => $term->term_id, + 'name' => $term->name, + 'slug' => $term->slug, + 'taxonomy' => $taxonomy, + ]; + } else { + error_log("✖ Термин не найден: $slug в таксономии: $taxonomy"); + } + } + } else { + error_log("→ Таксономия $taxonomy не существует, обрабатываем как кастомный фильтр"); + foreach ($slugs as $slug) { $filters[] = [ - 'id' => $term->term_id, - 'name' => $term->name, - 'slug' => $term->slug, - 'taxonomy' => $taxonomy, + 'id' => $slug, + 'name' => ucfirst(str_replace('-', ' ', $slug)), + 'slug' => $slug, + 'taxonomy' => $raw_taxonomy, ]; - } else { - error_log("✖ Термин не найден: $slug в таксономии: $taxonomy"); + error_log("✔ Добавлен кастомный фильтр: $slug для $raw_taxonomy"); } } } @@ -50,73 +71,67 @@ return $filters; } +$context = Timber::context(); +$context['criteria_for_new_product'] = date('Y-m-d', strtotime('-30 days')); +$context['posts_per_page'] = 12; - $context = Timber::context(); - //$context['posts'] = Timber::get_posts(); - $context['criteria_for_new_product'] = date('Y-m-d', strtotime('-30 days')); - - // Задаем количество постов для подзагрузки Ajax - $context['posts_per_page'] = 12; +$queried_object = get_queried_object(); - $queried_object = get_queried_object(); - - if (is_product_category() || is_tax()) { - $term_id = $queried_object->term_id; - $context['category_type'] = 'product_cat'; - $context['category_id'] = $term_id; - $context['category'] = get_term($term_id, 'product_cat'); - $context['category_link'] = get_term_link($term_id, 'product_cat'); - $context['category_title'] = single_term_title('', false); - } - - if (is_tax()) { - $context['category_type'] = $queried_object->taxonomy; - $context['category'] = get_term($term_id, $context['category_type']); - $context['category_link'] = get_term_link($term_id, $context['category_type']); - $context['category_title'] = single_term_title('', false); - } - - $args = array( - 'post_type' => 'product', - 'post_status' => 'publish', - 'posts_per_page' => $context['posts_per_page'], - 'paged' => 1, - 'has_password' => FALSE - ); - - $count_args = array( - 'post_type' => 'product', - 'post_status' => 'publish', - 'posts_per_page' => -1, - 'has_password' => FALSE - ); - - if ($context['category_id'] != NULL) { - $categories = [ - 'tax_query' => array( - array( - 'taxonomy' => $context['category_type'], - 'terms' => $context['category_id'], - 'operator' => 'IN' - ), - array( - 'taxonomy' => 'product_visibility', - 'field' => 'slug', - 'terms' => 'exclude-from-catalog', - 'operator' => 'NOT IN' - ) - ) - ]; - $args = array_merge($args, $categories); - $count_args = array_merge($count_args, $categories); - } +if (is_product_category() || is_tax()) { + $term_id = $queried_object->term_id; + $context['category_type'] = 'product_cat'; + $context['category_id'] = $term_id; + $context['category'] = get_term($term_id, 'product_cat'); + $context['category_link'] = get_term_link($term_id, 'product_cat'); + $context['category_title'] = single_term_title('', false); +} - $context['active_filters'] = get_active_woobewoo_filters_for_twig(); +if (is_tax()) { + $context['category_type'] = $queried_object->taxonomy; + $context['category'] = get_term($term_id, $context['category_type']); + $context['category_link'] = get_term_link($term_id, $context['category_type']); + $context['category_title'] = single_term_title('', false); +} - $context['posts'] = Timber::get_posts($args); - $context['count'] = count(Timber::get_posts($count_args)); - $context['sidebar_filters'] = Timber::get_widgets('sidebar_filters'); +$args = [ + 'post_type' => 'product', + 'post_status' => 'publish', + 'posts_per_page' => $context['posts_per_page'], + 'paged' => 1, + 'has_password' => false, +]; + +$count_args = [ + 'post_type' => 'product', + 'post_status' => 'publish', + 'posts_per_page' => -1, + 'has_password' => false, +]; + +if ($context['category_id'] != null) { + $categories = [ + 'tax_query' => [ + [ + 'taxonomy' => $context['category_type'], + 'terms' => $context['category_id'], + 'operator' => 'IN', + ], + [ + 'taxonomy' => 'product_visibility', + 'field' => 'slug', + 'terms' => 'exclude-from-catalog', + 'operator' => 'NOT IN', + ], + ], + ]; + $args = array_merge($args, $categories); + $count_args = array_merge($count_args, $categories); +} - Timber::render('_pages/shop/archive-product.twig', $context); +$context['active_filters'] = get_active_woobewoo_filters_for_twig(); +$context['posts'] = Timber::get_posts($args); +$context['count'] = count(Timber::get_posts($count_args)); +$context['sidebar_filters'] = Timber::get_widgets('sidebar_filters'); +Timber::render('_pages/shop/archive-product.twig', $context); ?> \ No newline at end of file