diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index 486614a..250cc0d 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -32,6 +32,11 @@ add_filter('timber/post/classmap', function ($classmap) { return $classmap; }, 100); +add_filter('timber/post/classmap', function ($classmap) { + $classmap['product'] = CosmopetProduct::class; + return $classmap; +}, 100); + function allow_svg_upload($mimes) { $mimes['svg'] = 'image/svg+xml'; diff --git a/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php b/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php index 794db95..5fb4ebd 100644 --- a/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php +++ b/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php @@ -7,11 +7,18 @@ use Timber\Integrations\WooCommerce\Product as TimberProduct; class CosmopetProduct extends TimberProduct { protected $sibling_categories = [ +<<<<<<< HEAD 'pa_compound', 'pa_dog-size', 'pa_reproductive-status', 'pa_age-of-the-cat', 'pa_age-of-the-dog', +======= + 'pa_age-of-the-cat', + 'pa_age-of-the-dog', + 'pa_compound', + 'pa_reproductive-status', +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) 'pa_series', ]; @@ -46,7 +53,11 @@ class CosmopetProduct extends TimberProduct { // Получаем галерею изображений if ($this->product && method_exists($this->product, 'get_gallery_image_ids')) { +<<<<<<< HEAD $gallery_image_ids = $this->product->get_gallery_image_ids(); +======= + $gallery_image_ids = $this->product->get_gallery_image_ids(); +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) } else { $gallery_image_ids = []; } @@ -77,7 +88,11 @@ class CosmopetProduct extends TimberProduct { } else{ if ($this->product && method_exists($this->product, 'get_weight')) { +<<<<<<< HEAD return $this->product->get_weight() ? $this->product->get_weight() . ' ' . $custom_measurement : ''; +======= + return $this->product->get_weight() ? $this->product->get_weight() . ' ' . $custom_measurement : ''; +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) } return ''; } @@ -105,6 +120,7 @@ class CosmopetProduct extends TimberProduct { */ public function getTasteClass() { // Получаем категории товара +<<<<<<< HEAD $product_categories = wp_get_post_terms( $this->product->get_id(), 'product_cat' ); $is_food = false; @@ -115,6 +131,17 @@ class CosmopetProduct extends TimberProduct { if ( $cat->slug === 'korm' ) { $is_food = true; } elseif ( $cat->slug === 'lakomstva' ) { +======= + $product_categories = $this->product->get_category_ids(); + + $is_food = false; + $is_treats = false; + // Определяем тип товара (корм или лакомство) + foreach ($product_categories as $cat) { + if ($cat == 365) { + $is_food = true; + } elseif ($cat == 367) { +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) $is_treats = true; } } @@ -223,7 +250,11 @@ class CosmopetProduct extends TimberProduct { // Extract just the posts in sorted order $sorted_siblings = array_map(function($item) { return $item['post']; +<<<<<<< HEAD }, $siblings_with_weights); +======= + }, $siblings_with_weights); +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) return $sorted_siblings; } @@ -271,6 +302,7 @@ class CosmopetProduct extends TimberProduct { } } +<<<<<<< HEAD // Получаем упорядоченные таксономии @@ -308,12 +340,55 @@ class CosmopetProduct extends TimberProduct { // Пропускаем, если у текущего товара нет значения для этой категории if (!isset($current_product_attributes[$taxonomy])) { continue; +======= + // Отладочная информация + error_log("=== Конструктор товара ==="); + error_log("Текущий товар ID: " . $this->id); + error_log("Текущий вес (числовой): " . $current_weight); + error_log("Всего товаров в коллекции: " . count($all_products)); + error_log("Атрибуты текущего товара: " . print_r($current_product_attributes, true)); + + // Группируем товары по атрибутам + foreach ($this->sibling_categories as $taxonomy) { + // Проверяем, есть ли у текущего товара значение для этой категории + if (!isset($current_product_attributes[$taxonomy])) { + error_log("Пропускаем $taxonomy - нет значения у текущего товара"); + continue; // Пропускаем, если у товара нет значения для этой категории + } + + $constructor[$taxonomy] = [ + 'taxonomy' => $taxonomy, + 'label' => $this->getAttributeLabel($taxonomy), + 'current_value' => $this->getCurrentAttributeValue($taxonomy), + 'options' => [] + ]; + + error_log("Обрабатываем атрибут: $taxonomy"); + error_log("Атрибуты текущего товара для проверки: " . print_r($current_product_attributes, true)); + + foreach ($all_products as $product) { + // Получаем атрибуты сравниваемого товара + $compare_attributes = []; + foreach ($this->sibling_categories as $compare_taxonomy) { + $terms = get_the_terms($product->id, $compare_taxonomy); + if ($terms && !is_wp_error($terms)) { + $compare_attributes[$compare_taxonomy] = array_map(function($term) { + return $term->term_id; + }, $terms); + } +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) } // Проверяем, совпадают ли все остальные атрибуты и вес $attributes_match = true; +<<<<<<< HEAD // Проверяем все атрибуты кроме текущей таксономии +======= + $differences = []; + + // Проверяем только атрибуты из sibling_categories +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) foreach ($this->sibling_categories as $compare_taxonomy) { if ($compare_taxonomy === $taxonomy) { continue; // Пропускаем проверяемую категорию @@ -324,6 +399,10 @@ class CosmopetProduct extends TimberProduct { // Проверяем, есть ли у сравниваемого товара значение для этой категории if (!isset($compare_attributes[$compare_taxonomy])) { $attributes_match = false; +<<<<<<< HEAD +======= + $differences[] = "Нет атрибута $compare_taxonomy у сравниваемого товара"; +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) break; } @@ -334,6 +413,10 @@ class CosmopetProduct extends TimberProduct { if (array_diff($current_values, $compare_values) !== [] || array_diff($compare_values, $current_values) !== []) { $attributes_match = false; +<<<<<<< HEAD +======= + $differences[] = "Не совпадают значения для $compare_taxonomy"; +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) break; } } @@ -342,18 +425,33 @@ class CosmopetProduct extends TimberProduct { else { if (isset($compare_attributes[$compare_taxonomy])) { $attributes_match = false; +<<<<<<< HEAD +======= + $differences[] = "У сравниваемого товара есть атрибут $compare_taxonomy, а у текущего нет"; +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) break; } } } // Проверяем вес (числовое сравнение) +<<<<<<< HEAD if (abs($current_weight - $compare_weight) > 0.01) { $attributes_match = false; +======= + $compare_weight = $product->getNumericWeight(); + if (abs($current_weight - $compare_weight) > 0.01) { // Используем небольшой допуск для float + $attributes_match = false; + $differences[] = "Не совпадает вес: текущий '$current_weight' vs сравниваемый '$compare_weight'"; +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) } // Если все атрибуты и вес совпадают, добавляем товар в группу if ($attributes_match) { +<<<<<<< HEAD +======= + error_log("Товар {$product->id} подходит для атрибута $taxonomy"); +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) $product_terms = get_the_terms($product->id, $taxonomy); if ($product_terms && !is_wp_error($product_terms)) { foreach ($product_terms as $term) { @@ -361,15 +459,21 @@ class CosmopetProduct extends TimberProduct { if (!isset($constructor[$taxonomy]['options'][$option_key])) { $constructor[$taxonomy]['options'][$option_key] = [ 'term_id' => $term->term_id, +<<<<<<< HEAD 'name' => $this->getTermName($term->term_id, $taxonomy), 'slug' => $term->slug, 'icon' => $this->getTermIcon($term->term_id, $taxonomy), +======= + 'name' => $term->name, + 'slug' => $term->slug, +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) 'products' => [] ]; } $constructor[$taxonomy]['options'][$option_key]['products'][] = $product; } } +<<<<<<< HEAD } } } @@ -408,6 +512,35 @@ class CosmopetProduct extends TimberProduct { 'pa_compound' => pll__('ВКУС КОРМА'), 'pa_reproductive-status' => pll__('ВИД КОШКИ'), 'pa_series' => pll__('СЕРИЯ'), +======= + } else { + error_log("Товар {$product->id} НЕ подходит для атрибута $taxonomy. Причины: " . implode(', ', $differences)); + } + } + + error_log("Найдено опций для $taxonomy: " . count($constructor[$taxonomy]['options'])); + + // Показываем детали найденных опций + foreach ($constructor[$taxonomy]['options'] as $option_id => $option) { + error_log("Опция $option_id ({$option['name']}): " . count($option['products']) . " товаров"); + foreach ($option['products'] as $product) { + error_log(" - Товар {$product->id}: {$product->title}"); + } + } + } + + error_log("Итоговый конструктор: " . print_r($constructor, true)); + return $constructor; + } + + protected function getAttributeLabel($taxonomy) { + $labels = [ + 'pa_age-of-the-cat' => 'ВОЗРАСТ КОШКИ', + 'pa_age-of-the-dog' => 'ВОЗРАСТ СОБАКИ', + 'pa_compound' => 'ВКУС КОРМА', + 'pa_reproductive-status' => 'РЕПРОДУКТИВНЫЙ СТАТУС', + 'pa_series' => 'СЕРИЯ', +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) ]; return $labels[$taxonomy] ?? wc_attribute_label($taxonomy); @@ -421,6 +554,7 @@ class CosmopetProduct extends TimberProduct { return null; } +<<<<<<< HEAD /** * Получает таксономии в правильном порядке с учетом сортировки * @return array Массив таксономий с их порядком @@ -586,6 +720,8 @@ class CosmopetProduct extends TimberProduct { +======= +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) public function getAllAttributes() { $attributes = []; foreach ($this->sibling_categories as $taxonomy) { diff --git a/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css index 6da63a0..4453365 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css +++ b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css @@ -756,6 +756,7 @@ line-height: 143%; .stock, .quantity{ display: none; +<<<<<<< HEAD:wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css } @@ -899,3 +900,6 @@ line-height: 143%; .product-incart__wrap.loading .product-incart__count { opacity: 0.5; } +======= +} +>>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара):wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/css/product-style.css diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/single-product_new/component-controller.php new file mode 100644 index 0000000..9e903c1 --- /dev/null +++ b/wp-content/themes/cosmopet/modules/shop/components/single-product_new/component-controller.php @@ -0,0 +1,13 @@ + +>>>>>> 7499a8aa (Task 7719 | натяжка верстки single страницы товара) diff --git a/wp-content/themes/cosmopet/single-product.php b/wp-content/themes/cosmopet/single-product.php new file mode 100644 index 0000000..ff95994 --- /dev/null +++ b/wp-content/themes/cosmopet/single-product.php @@ -0,0 +1,22 @@ + - {% include 'profile/order-list.twig' %} - - -{% endblock %} \ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/profile/profile.twig b/wp-content/themes/cosmopet/templates/profile/profile.twig deleted file mode 100644 index 4744dc0..0000000 --- a/wp-content/themes/cosmopet/templates/profile/profile.twig +++ /dev/null @@ -1,14 +0,0 @@ -{% set profile_pg = 1 %} - -{% extends 'profile/profile-base.twig' %} - -{% block profile_content%} -
- - - -{# TO_DO нужен ли тут