Task:6787 | Переработка фильтра, правка стилей

pull/34/head^2
parent a4f88d789c
commit d651b4f03a
  1. 5
      wp-content/themes/cosmopet/modules/popup/assets/css/gp-style-desktop.css
  2. 65
      wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php

@ -28,6 +28,11 @@
filter: blur(0); filter: blur(0);
} }
.wpfFilterLayoutVer, .wpfFilterLayoutHor {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
@media (max-width: 720px) { @media (max-width: 720px) {
.modal__aside { .modal__aside {
width: 100% !important; /* Полная ширина на мобильных */ width: 100% !important; /* Полная ширина на мобильных */

@ -1,6 +1,6 @@
<?php <?php
wp_enqueue_script( 'shop_scripts', get_template_directory_uri() . '/woocommerce/assets/js/gp-main.js', 'jquery', '', true); wp_enqueue_script('shop_scripts', get_template_directory_uri() . '/woocommerce/assets/js/gp-main.js', ['jquery'], '', true);
wp_enqueue_style('shop_styles_core', get_template_directory_uri() . '/woocommerce/assets/css/gp-style-core.css'); wp_enqueue_style('shop_styles_core', get_template_directory_uri() . '/woocommerce/assets/css/gp-style-core.css');
wp_enqueue_style('shop_styles_desktop', get_template_directory_uri() . '/woocommerce/assets/css/gp-style-desktop.css'); wp_enqueue_style('shop_styles_desktop', get_template_directory_uri() . '/woocommerce/assets/css/gp-style-desktop.css');
wp_enqueue_style('shop_styles_tablet', get_template_directory_uri() . '/woocommerce/assets/css/gp-style-tablet.css'); wp_enqueue_style('shop_styles_tablet', get_template_directory_uri() . '/woocommerce/assets/css/gp-style-tablet.css');
@ -12,6 +12,15 @@
$filters = []; $filters = [];
error_log('=== WooBeWoo: фильтры проверяются ==='); error_log('=== WooBeWoo: фильтры проверяются ===');
// Получаем все атрибуты WooCommerce
$attribute_taxonomies = wc_get_attribute_taxonomies();
$valid_taxonomies = [];
foreach ($attribute_taxonomies as $attr) {
$taxonomy = 'pa_' . $attr->attribute_name;
$valid_taxonomies[$taxonomy] = $attr->attribute_label;
}
error_log('→ Доступные таксономии атрибутов: ' . implode(', ', array_keys($valid_taxonomies)));
foreach ($_GET as $key => $value) { foreach ($_GET as $key => $value) {
error_log("Ключ: $key => " . print_r($value, true)); error_log("Ключ: $key => " . print_r($value, true));
@ -19,15 +28,15 @@
$raw_taxonomy = str_replace('wpf_filter_', '', $key); $raw_taxonomy = str_replace('wpf_filter_', '', $key);
error_log("→ Обнаружен фильтр: $raw_taxonomy"); error_log("→ Обнаружен фильтр: $raw_taxonomy");
$slugs = is_array($value) ? $value : explode(',', $value); $slugs = is_array($value) ? $value : explode('|', $value);
error_log("→ Slugs: " . implode(', ', $slugs)); error_log("→ Slugs: " . implode(', ', $slugs));
// Попробуем с pa_ и без, в зависимости от существования таксономии
$taxonomy = taxonomy_exists('pa_' . $raw_taxonomy) ? 'pa_' . $raw_taxonomy : $raw_taxonomy; $taxonomy = taxonomy_exists('pa_' . $raw_taxonomy) ? 'pa_' . $raw_taxonomy : $raw_taxonomy;
error_log("→ Проверяемая таксономия: $taxonomy, существует: " . (taxonomy_exists($taxonomy) ? 'Да' : 'Нет'));
if (taxonomy_exists($taxonomy)) {
foreach ($slugs as $slug) { foreach ($slugs as $slug) {
$term = get_term_by('slug', $slug, $taxonomy); $term = get_term_by('slug', $slug, $taxonomy);
if ($term) { if ($term) {
error_log("✔ Найден термин: {$term->name} (ID: {$term->term_id}) в таксономии: $taxonomy"); error_log("✔ Найден термин: {$term->name} (ID: {$term->term_id}) в таксономии: $taxonomy");
$filters[] = [ $filters[] = [
@ -40,6 +49,18 @@
error_log("✖ Термин не найден: $slug в таксономии: $taxonomy"); error_log("✖ Термин не найден: $slug в таксономии: $taxonomy");
} }
} }
} else {
error_log("→ Таксономия $taxonomy не существует, обрабатываем как кастомный фильтр");
foreach ($slugs as $slug) {
$filters[] = [
'id' => $slug,
'name' => ucfirst(str_replace('-', ' ', $slug)),
'slug' => $slug,
'taxonomy' => $raw_taxonomy,
];
error_log("✔ Добавлен кастомный фильтр: $slug для $raw_taxonomy");
}
}
} }
} }
@ -50,12 +71,8 @@
return $filters; return $filters;
} }
$context = Timber::context(); $context = Timber::context();
//$context['posts'] = Timber::get_posts();
$context['criteria_for_new_product'] = date('Y-m-d', strtotime('-30 days')); $context['criteria_for_new_product'] = date('Y-m-d', strtotime('-30 days'));
// Задаем количество постов для подзагрузки Ajax
$context['posts_per_page'] = 12; $context['posts_per_page'] = 12;
$queried_object = get_queried_object(); $queried_object = get_queried_object();
@ -76,47 +93,45 @@
$context['category_title'] = single_term_title('', false); $context['category_title'] = single_term_title('', false);
} }
$args = array( $args = [
'post_type' => 'product', 'post_type' => 'product',
'post_status' => 'publish', 'post_status' => 'publish',
'posts_per_page' => $context['posts_per_page'], 'posts_per_page' => $context['posts_per_page'],
'paged' => 1, 'paged' => 1,
'has_password' => FALSE 'has_password' => false,
); ];
$count_args = array( $count_args = [
'post_type' => 'product', 'post_type' => 'product',
'post_status' => 'publish', 'post_status' => 'publish',
'posts_per_page' => -1, 'posts_per_page' => -1,
'has_password' => FALSE 'has_password' => false,
); ];
if ($context['category_id'] != NULL) { if ($context['category_id'] != null) {
$categories = [ $categories = [
'tax_query' => array( 'tax_query' => [
array( [
'taxonomy' => $context['category_type'], 'taxonomy' => $context['category_type'],
'terms' => $context['category_id'], 'terms' => $context['category_id'],
'operator' => 'IN' 'operator' => 'IN',
), ],
array( [
'taxonomy' => 'product_visibility', 'taxonomy' => 'product_visibility',
'field' => 'slug', 'field' => 'slug',
'terms' => 'exclude-from-catalog', 'terms' => 'exclude-from-catalog',
'operator' => 'NOT IN' 'operator' => 'NOT IN',
) ],
) ],
]; ];
$args = array_merge($args, $categories); $args = array_merge($args, $categories);
$count_args = array_merge($count_args, $categories); $count_args = array_merge($count_args, $categories);
} }
$context['active_filters'] = get_active_woobewoo_filters_for_twig(); $context['active_filters'] = get_active_woobewoo_filters_for_twig();
$context['posts'] = Timber::get_posts($args); $context['posts'] = Timber::get_posts($args);
$context['count'] = count(Timber::get_posts($count_args)); $context['count'] = count(Timber::get_posts($count_args));
$context['sidebar_filters'] = Timber::get_widgets('sidebar_filters'); $context['sidebar_filters'] = Timber::get_widgets('sidebar_filters');
Timber::render('_pages/shop/archive-product.twig', $context); Timber::render('_pages/shop/archive-product.twig', $context);
?> ?>
Loading…
Cancel
Save