From c332059a29ff7065135c098426f8b8db4b4f2fa4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 14 Jun 2025 15:40:27 +0300 Subject: [PATCH] =?UTF-8?q?Andrei=20|=20wip:=20=D1=80=D0=B5=D1=84=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BD=D0=BE=D1=88=D1=83=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B8=20wocommerce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catalog/component-controller.php | 122 ++++++++++++++++++ .../temp-functions/woocommerce-logic.php | 2 +- .../shop}/archive-product-ajaxload.twig | 2 +- .../_blocks/shop}/archive-product-tease.twig | 0 .../_pages/shop}/archive-product.twig | 2 +- .../cosmopet/woocommerce/archive-product.php | 119 +---------------- .../archive-product-modal.twig | 0 7 files changed, 126 insertions(+), 121 deletions(-) create mode 100644 wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php rename wp-content/themes/cosmopet/{woocommerce/archive-product => templates/_blocks/shop}/archive-product-ajaxload.twig (70%) rename wp-content/themes/cosmopet/{woocommerce/archive-product => templates/_blocks/shop}/archive-product-tease.twig (100%) rename wp-content/themes/cosmopet/{woocommerce/archive-product => templates/_pages/shop}/archive-product.twig (95%) delete mode 100644 wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-modal.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 new file mode 100644 index 0000000..41ce8bf --- /dev/null +++ b/wp-content/themes/cosmopet/modules/shop/components/catalog/component-controller.php @@ -0,0 +1,122 @@ + $value) { + error_log("Ключ: $key => " . print_r($value, true)); + + if (strpos($key, 'wpf_filter_') === 0) { + $raw_taxonomy = str_replace('wpf_filter_', '', $key); + error_log("→ Обнаружен фильтр: $raw_taxonomy"); + + $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"); + $filters[] = [ + 'id' => $term->term_id, + 'name' => $term->name, + 'slug' => $term->slug, + 'taxonomy' => $taxonomy, + ]; + } else { + error_log("✖ Термин не найден: $slug в таксономии: $taxonomy"); + } + } + } + } + + if (empty($filters)) { + error_log('Ни один активный фильтр не найден.'); + } + + return $filters; +} + + + $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(); + + 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); + } + + $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 diff --git a/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php b/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php index 594bb6d..e2f8c0c 100644 --- a/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php @@ -85,7 +85,7 @@ function get_products() { $context['ended'] = true; } - Timber::render( 'woocommerce/archive-product/archive-product-ajaxload.twig', $context ); + Timber::render( '_blocks/shop/archive-product-ajaxload.twig', $context ); die(); } diff --git a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-ajaxload.twig b/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-ajaxload.twig similarity index 70% rename from wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-ajaxload.twig rename to wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-ajaxload.twig index 47846f6..8a7ec0c 100644 --- a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-ajaxload.twig +++ b/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-ajaxload.twig @@ -1,5 +1,5 @@ {% for post in posts %} - {% include '/woocommerce/archive-product/archive-product-tease.twig' with {post: post} %} + {% include '_blocks/shop/archive-product-tease.twig' with {post: post} %} {% endfor %} {% if not ended %} diff --git a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig b/wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-tease.twig similarity index 100% rename from wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-tease.twig rename to wp-content/themes/cosmopet/templates/_blocks/shop/archive-product-tease.twig diff --git a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product.twig b/wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig similarity index 95% rename from wp-content/themes/cosmopet/woocommerce/archive-product/archive-product.twig rename to wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig index 6126fa2..4e8c738 100644 --- a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product.twig +++ b/wp-content/themes/cosmopet/templates/_pages/shop/archive-product.twig @@ -61,7 +61,7 @@
{% for post in posts %} - {% include '/woocommerce/archive-product/archive-product-tease.twig' with {post: post} %} + {% include '_blocks/shop/archive-product-tease.twig' with {post: post} %} {% endfor %}
diff --git a/wp-content/themes/cosmopet/woocommerce/archive-product.php b/wp-content/themes/cosmopet/woocommerce/archive-product.php index 321f92a..5fa7019 100644 --- a/wp-content/themes/cosmopet/woocommerce/archive-product.php +++ b/wp-content/themes/cosmopet/woocommerce/archive-product.php @@ -1,122 +1,5 @@ $value) { - error_log("Ключ: $key => " . print_r($value, true)); - - if (strpos($key, 'wpf_filter_') === 0) { - $raw_taxonomy = str_replace('wpf_filter_', '', $key); - error_log("→ Обнаружен фильтр: $raw_taxonomy"); - - $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"); - $filters[] = [ - 'id' => $term->term_id, - 'name' => $term->name, - 'slug' => $term->slug, - 'taxonomy' => $taxonomy, - ]; - } else { - error_log("✖ Термин не найден: $slug в таксономии: $taxonomy"); - } - } - } - } - - if (empty($filters)) { - error_log('Ни один активный фильтр не найден.'); - } - - return $filters; -} - - - $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(); - - 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); - } - - $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('archive-product/archive-product.twig', $context); + include_component('shop', 'catalog') ?> \ No newline at end of file diff --git a/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-modal.twig b/wp-content/themes/cosmopet/woocommerce/archive-product/archive-product-modal.twig deleted file mode 100644 index e69de29..0000000