diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index 250cc0d..575606e 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -32,14 +32,21 @@ add_filter('timber/post/classmap', function ($classmap) { return $classmap; }, 100); +<<<<<<< HEAD add_filter('timber/post/classmap', function ($classmap) { $classmap['product'] = CosmopetProduct::class; return $classmap; }, 100); +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) function allow_svg_upload($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } +<<<<<<< HEAD add_filter('upload_mimes', 'allow_svg_upload'); +======= +add_filter('upload_mimes', 'allow_svg_upload'); +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) diff --git a/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php b/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php index 5fb4ebd..841a530 100644 --- a/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php +++ b/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php @@ -7,6 +7,7 @@ use Timber\Integrations\WooCommerce\Product as TimberProduct; class CosmopetProduct extends TimberProduct { protected $sibling_categories = [ +<<<<<<< HEAD <<<<<<< HEAD 'pa_compound', 'pa_dog-size', @@ -19,6 +20,13 @@ class CosmopetProduct extends TimberProduct { 'pa_compound', 'pa_reproductive-status', >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + 'pa_compound', + 'pa_dog-size', + 'pa_reproductive-status', + 'pa_age-of-the-cat', + 'pa_age-of-the-dog', +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) 'pa_series', ]; @@ -53,11 +61,15 @@ class CosmopetProduct extends TimberProduct { // Получаем галерею изображений if ($this->product && method_exists($this->product, 'get_gallery_image_ids')) { +<<<<<<< HEAD <<<<<<< HEAD $gallery_image_ids = $this->product->get_gallery_image_ids(); ======= $gallery_image_ids = $this->product->get_gallery_image_ids(); >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + $gallery_image_ids = $this->product->get_gallery_image_ids(); +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) } else { $gallery_image_ids = []; } @@ -88,11 +100,15 @@ class CosmopetProduct extends TimberProduct { } else{ if ($this->product && method_exists($this->product, 'get_weight')) { +<<<<<<< HEAD <<<<<<< 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 $this->product->get_weight() ? $this->product->get_weight() . ' ' . $custom_measurement : ''; +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) } return ''; } @@ -250,11 +266,15 @@ class CosmopetProduct extends TimberProduct { // Extract just the posts in sorted order $sorted_siblings = array_map(function($item) { return $item['post']; +<<<<<<< HEAD <<<<<<< HEAD }, $siblings_with_weights); ======= }, $siblings_with_weights); >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + }, $siblings_with_weights); +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) return $sorted_siblings; } @@ -302,6 +322,7 @@ class CosmopetProduct extends TimberProduct { } } +<<<<<<< HEAD <<<<<<< HEAD @@ -347,15 +368,41 @@ class CosmopetProduct extends TimberProduct { error_log("Текущий вес (числовой): " . $current_weight); error_log("Всего товаров в коллекции: " . count($all_products)); error_log("Атрибуты текущего товара: " . print_r($current_product_attributes, true)); +======= + +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) + + // Получаем упорядоченные таксономии + $ordered_taxonomies = $this->getOrderedTaxonomies(); - // Группируем товары по атрибутам + // Инициализируем конструктор для всех таксономий foreach ($this->sibling_categories as $taxonomy) { - // Проверяем, есть ли у текущего товара значение для этой категории - if (!isset($current_product_attributes[$taxonomy])) { - error_log("Пропускаем $taxonomy - нет значения у текущего товара"); - continue; // Пропускаем, если у товара нет значения для этой категории + if (isset($current_product_attributes[$taxonomy])) { + $constructor[$taxonomy] = [ + 'taxonomy' => $taxonomy, + 'label' => $this->getAttributeLabel($taxonomy), + 'current_value' => $this->getCurrentAttributeValue($taxonomy), + 'options' => [] + ]; + } + } + + // ОБХОДИМ МАССИВ ТОВАРОВ ТОЛЬКО ОДИН РАЗ + foreach ($all_products as $product) { + // Получаем все атрибуты сравниваемого товара за один раз + $compare_attributes = []; + $compare_weight = $product->getNumericWeight(); + + foreach ($this->sibling_categories as $taxonomy) { + $terms = get_the_terms($product->id, $taxonomy); + if ($terms && !is_wp_error($terms)) { + $compare_attributes[$taxonomy] = array_map(function($term) { + return $term->term_id; + }, $terms); + } } +<<<<<<< HEAD $constructor[$taxonomy] = [ 'taxonomy' => $taxonomy, 'label' => $this->getAttributeLabel($taxonomy), @@ -377,10 +424,18 @@ class CosmopetProduct extends TimberProduct { }, $terms); } >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + // Проверяем, подходит ли товар для каждой таксономии + foreach ($this->sibling_categories as $taxonomy) { + // Пропускаем, если у текущего товара нет значения для этой категории + if (!isset($current_product_attributes[$taxonomy])) { + continue; +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) } // Проверяем, совпадают ли все остальные атрибуты и вес $attributes_match = true; +<<<<<<< HEAD <<<<<<< HEAD // Проверяем все атрибуты кроме текущей таксономии @@ -389,6 +444,10 @@ class CosmopetProduct extends TimberProduct { // Проверяем только атрибуты из sibling_categories >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + + // Проверяем все атрибуты кроме текущей таксономии +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) foreach ($this->sibling_categories as $compare_taxonomy) { if ($compare_taxonomy === $taxonomy) { continue; // Пропускаем проверяемую категорию @@ -400,9 +459,12 @@ class CosmopetProduct extends TimberProduct { if (!isset($compare_attributes[$compare_taxonomy])) { $attributes_match = false; <<<<<<< HEAD +<<<<<<< HEAD ======= $differences[] = "Нет атрибута $compare_taxonomy у сравниваемого товара"; >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) break; } @@ -414,9 +476,12 @@ class CosmopetProduct extends TimberProduct { array_diff($compare_values, $current_values) !== []) { $attributes_match = false; <<<<<<< HEAD +<<<<<<< HEAD ======= $differences[] = "Не совпадают значения для $compare_taxonomy"; >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) break; } } @@ -426,15 +491,19 @@ class CosmopetProduct extends TimberProduct { if (isset($compare_attributes[$compare_taxonomy])) { $attributes_match = false; <<<<<<< HEAD +<<<<<<< HEAD ======= $differences[] = "У сравниваемого товара есть атрибут $compare_taxonomy, а у текущего нет"; >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) break; } } } // Проверяем вес (числовое сравнение) +<<<<<<< HEAD <<<<<<< HEAD if (abs($current_weight - $compare_weight) > 0.01) { $attributes_match = false; @@ -444,14 +513,21 @@ class CosmopetProduct extends TimberProduct { $attributes_match = false; $differences[] = "Не совпадает вес: текущий '$current_weight' vs сравниваемый '$compare_weight'"; >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + if (abs($current_weight - $compare_weight) > 0.01) { + $attributes_match = false; +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) } // Если все атрибуты и вес совпадают, добавляем товар в группу if ($attributes_match) { <<<<<<< HEAD +<<<<<<< HEAD ======= error_log("Товар {$product->id} подходит для атрибута $taxonomy"); >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) $product_terms = get_the_terms($product->id, $taxonomy); if ($product_terms && !is_wp_error($product_terms)) { foreach ($product_terms as $term) { @@ -459,6 +535,7 @@ class CosmopetProduct extends TimberProduct { if (!isset($constructor[$taxonomy]['options'][$option_key])) { $constructor[$taxonomy]['options'][$option_key] = [ 'term_id' => $term->term_id, +<<<<<<< HEAD <<<<<<< HEAD 'name' => $this->getTermName($term->term_id, $taxonomy), 'slug' => $term->slug, @@ -467,12 +544,18 @@ class CosmopetProduct extends TimberProduct { 'name' => $term->name, 'slug' => $term->slug, >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + 'name' => $this->getTermName($term->term_id, $taxonomy), + 'slug' => $term->slug, + 'icon' => $this->getTermIcon($term->term_id, $taxonomy), +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) 'products' => [] ]; } $constructor[$taxonomy]['options'][$option_key]['products'][] = $product; } } +<<<<<<< HEAD <<<<<<< HEAD } } @@ -525,22 +608,55 @@ class CosmopetProduct extends TimberProduct { error_log("Опция $option_id ({$option['name']}): " . count($option['products']) . " товаров"); foreach ($option['products'] as $product) { error_log(" - Товар {$product->id}: {$product->title}"); +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) + } + } + } + + // Сортируем опции по порядку терминов для каждой таксономии + foreach ($constructor as $taxonomy => $taxonomy_data) { + if (isset($ordered_taxonomies[$taxonomy])) { + $ordered_options = []; + foreach ($ordered_taxonomies[$taxonomy] as $term) { + if (isset($constructor[$taxonomy]['options'][$term->term_id])) { + $ordered_options[$term->term_id] = $constructor[$taxonomy]['options'][$term->term_id]; + } } + $constructor[$taxonomy]['options'] = $ordered_options; + } + + } + + // Сортируем итоговый конструктор по порядку таксономий + $ordered_constructor = []; + foreach ($this->sibling_categories as $taxonomy) { + if (isset($constructor[$taxonomy])) { + $ordered_constructor[$taxonomy] = $constructor[$taxonomy]; } } - error_log("Итоговый конструктор: " . print_r($constructor, true)); - return $constructor; + return $ordered_constructor; } protected function getAttributeLabel($taxonomy) { + // Fallback на старые метки $labels = [ +<<<<<<< HEAD 'pa_age-of-the-cat' => 'ВОЗРАСТ КОШКИ', 'pa_age-of-the-dog' => 'ВОЗРАСТ СОБАКИ', 'pa_compound' => 'ВКУС КОРМА', 'pa_reproductive-status' => 'РЕПРОДУКТИВНЫЙ СТАТУС', 'pa_series' => 'СЕРИЯ', >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= + 'pa_age-of-the-cat' => pll__('ВОЗРАСТ КОШКИ'), + 'pa_age-of-the-dog' => pll__('ВОЗРАСТ СОБАКИ'), + 'pa_dog-size' => pll__('РАЗМЕР СОБАКИ'), + 'pa_compound' => pll__('ВКУС КОРМА'), + 'pa_reproductive-status' => pll__('ВИД КОШКИ'), + 'pa_series' => pll__('СЕРИЯ'), +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) ]; return $labels[$taxonomy] ?? wc_attribute_label($taxonomy); @@ -555,6 +671,9 @@ class CosmopetProduct extends TimberProduct { } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 51869ae1 (Task 7719 | натяжка верстки single товара.) /** * Получает таксономии в правильном порядке с учетом сортировки * @return array Массив таксономий с их порядком @@ -720,8 +839,11 @@ class CosmopetProduct extends TimberProduct { +<<<<<<< HEAD ======= >>>>>>> 909cd3ca (Task 7719 | натяжка верстки single страницы товара) +======= +>>>>>>> 51869ae1 (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 4453365..04a0666 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,7 +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 + } @@ -900,6 +900,3 @@ 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 deleted file mode 100644 index 9e903c1..0000000 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/component-controller.php +++ /dev/null @@ -1,13 +0,0 @@ - - - - {{ function('pll_e', 'Главная') }} - - - {{ function('pll_e', 'Продукция') }} - - {% if category %} - - {{ category_title }} - - {% 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 %} - -
- - {% if posts|length > 0 %} - {% for post in posts %} - - - {% set class = post.getTasteClass %} - {% set section = class ~ ' product-archive-card' %} - - - {% include 'shop/product-card.twig' with {_product : fn('wc_get_product', post.id), section: section} %} - - - {% endfor %} - {% else %} -
- -
{{ fn('pll_e', 'coming soon') }}
-
{{ fn('pll_e', 'This item is not on our website yet, but it will be here very soon') }}
-
- {% endif %} -
- - -
- -{% endblock %} \ No newline at end of file diff --git a/wp-content/themes/cosmopet/views/shop/single-product.twig b/wp-content/themes/cosmopet/views/shop/single-product.twig deleted file mode 100644 index c47eab8..0000000 --- a/wp-content/themes/cosmopet/views/shop/single-product.twig +++ /dev/null @@ -1,321 +0,0 @@ -{% set bodyClass = 'bg-white' %} -{% set mainClass = '' %} -{% extends 'layout.twig' %} - -{% block content %} -
-
- -
-
-

- {{post.title}} -

-
-

{{ fn('pll_e', 'СОСТАВ') }}

-
{{ post.getComposition }}
-
-
-

{{ fn('pll_e', 'ПИЩЕВАЯ ЦЕННОСТЬ') }}

-
- - {% set nutritional_value = post.nutritional_value %} - {% if nutritional_value.protein %} -
-
{{ fn('pll_e', 'Сырой белок') }}
-
{{nutritional_value.protein}}
-
- {% endif %} - {% if nutritional_value.fat %} -
-
{{ fn('pll_e', 'Сырой жир') }}
-
{{nutritional_value.fat}}
-
- {% endif %} - {% if nutritional_value.fiber %} -
-
{{ fn('pll_e', 'Сырая клетчатка') }}
-
{{nutritional_value.fiber}}
-
- {% endif %} - {% if nutritional_value.ash %} -
-
{{ fn('pll_e', 'Сырая зола') }}
-
{{nutritional_value.ash}}
-
- {% endif %} - {% if nutritional_value.wat %} -
-
{{ fn('pll_e', 'Влажность') }}
-
{{nutritional_value.wat}}
-
- {% endif %} - {% if nutritional_value.calcium %} -
-
{{ fn('pll_e', 'Кальций') }}
-
{{nutritional_value.calcium}}
-
- {% endif %} - {% if nutritional_value.phosphorus %} -
-
{{ fn('pll_e', 'Фосфор') }}
-
{{nutritional_value.phosphorus}}
-
- {% endif %} - {% if nutritional_value.omega_6 %} -
-
{{ fn('pll_e', 'Омега 6') }}
-
{{nutritional_value.omega_6}}
-
- {% endif %} - {% if nutritional_value.omega_3 %} -
-
{{ fn('pll_e', 'Омега 3') }}
-
{{nutritional_value.omega_3}}
-
- {% endif %} -
- {% set vitamins = post.vitamins %} - {% if vitamins %} -
-
- {{ fn('pll_e', 'Витамины на кг') }} -
-
- - {% if vitamins.vitamin_a_me %} -
A, ME — {{vitamins.vitamin_a_me}}
- {% endif %} - {% if vitamins.vitamin_d3_me %} -
D3, ME — {{vitamins.vitamin_d3_me}}
- {% endif %} - {% if vitamins.vitamin_e %} -
E — {{vitamins.vitamin_e}}
- {% endif %} - {% if vitamins.tiamin %} -
{{ fn('pll_e', 'Тиамин') }} — {{vitamins.tiamin}}
- {% endif %} - {% if vitamins.riboflavin %} -
{{ fn('pll_e', 'Рибофлавин') }} — {{vitamins.riboflavin}}
- {% endif %} - {% if vitamins.pantothenic_acid %} -
{{ fn('pll_e', 'Пантотеновая кислота') }} — {{vitamins.pantothenic_acid}}
- {% endif %} - {% if vitamins.niaczin %} -
{{ fn('pll_e', 'Ниацин') }} — {{vitamins.niaczin}}
- {% endif %} - {% if vitamins.piridoksin %} -
{{ fn('pll_e', 'Пиридоксин') }} — {{vitamins.piridoksin}}
- {% endif %} - {% if vitamins.folic_acid %} -
{{ fn('pll_e', 'Фолиевая кислота') }} — {{vitamins.folic_acid}}
- {% endif %} - {% if vitamins.vitamin_b12 %} -
{{ fn('pll_e', 'Витамин B12') }} — {{vitamins.vitamin_b12}}
- {% endif %} - {% if vitamins.holin %} -
{{ fn('pll_e', 'Холин') }} — {{vitamins.holin}}
- {% endif %} -
-
- {% endif %} -
-
-
- -

- {{post.title}} -

-
-
- {% set constructor = post.getProductConstructor %} - {% for taxonomy, attribute_data in constructor %} - - {% endfor %} - - {% set size_siblings = post.getSizeSiblings %} - {% if size_siblings %} -
-
{{fn('pll_e', 'ВЕС УПАКОВКИ')}}
-
- {% for sibling in size_siblings %} - -
{{sibling.get_weight}}
-
- {% endfor %} -
-
- {% endif %} - -
-
- {{post.getPrice}} -
- {% if post.getRegularPrice %} -
-
{{post.getRegularPrice}}
-
- {{ post.getPriceDifferenceInPercent }} -
-
- {% endif %} -
- {% set in_stock = post.meta('_stock_status') == 'instock' %} - {% if in_stock %} - {{ function('do_action', 'woocommerce_' ~ product.get_type() ~ '_add_to_cart') }} - {% else %} -
- -
- {% endif %} -
-
- -
-
- {{ fn('pll_e', 'ОПИСАНИЕ') }} -
-
- {{post.content}} - -
-
-
- -
-
-
- {{ fn('pll_e', 'Отзывы Специалистов') }} -
-
- - -
-
-
-
- {% for slide in post.getReviews %} - {% include "shop/reviews-slide_element.twig" with {slide: slide} %} - {% endfor %} -
-
- -
- - -
-
- - {% if post.getRelatedProducts %} -
-
-
- {{ fn('pll_e', 'вашему питомцу может понравиться') }} -
-
- - -
- -
-
-
- {% for related_product in post.getRelatedProducts %} - - {% set class = related_product.getTasteClass %} - {% set section = class ~ ' swiper-slide' %} - - - {% include 'shop/product-card.twig' with {_product : fn('wc_get_product', related_product.id), section: section} %} - - - {% endfor %} -
-
-
- - -
-
- {% endif %} - -
- {% for slide in reviews %} - - {% include 'modal/rewiew_modal.twig' with {slide : slide} %} - - {% endfor %} -{% endblock %} \ No newline at end of file