diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index fa92afa..11e2321 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -31,3 +31,9 @@ add_filter('timber/post/classmap', function ($classmap) { return $classmap; }, 100); + +function allow_svg_upload($mimes) { + $mimes['svg'] = 'image/svg+xml'; + return $mimes; +} +add_filter('upload_mimes', 'allow_svg_upload'); \ No newline at end of file diff --git a/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php b/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php index af3a010..bf01f21 100644 --- a/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php +++ b/wp-content/themes/cosmopet/modules/shop/CosmopetProduct.php @@ -7,10 +7,11 @@ use Timber\Integrations\WooCommerce\Product as TimberProduct; class CosmopetProduct extends TimberProduct { protected $sibling_categories = [ - 'pa_age-of-the-cat', - 'pa_age-of-the-dog', 'pa_compound', + 'pa_dog-size', 'pa_reproductive-status', + 'pa_age-of-the-cat', + 'pa_age-of-the-dog', 'pa_series', ]; @@ -45,7 +46,7 @@ class CosmopetProduct extends TimberProduct { // Получаем галерею изображений if ($this->product && method_exists($this->product, 'get_gallery_image_ids')) { - $gallery_image_ids = $this->product->get_gallery_image_ids(); + $gallery_image_ids = $this->product->get_gallery_image_ids(); } else { $gallery_image_ids = []; } @@ -76,7 +77,7 @@ class CosmopetProduct extends TimberProduct { } else{ if ($this->product && method_exists($this->product, 'get_weight')) { - return $this->product->get_weight() ? $this->product->get_weight() . ' ' . $custom_measurement : ''; + return $this->product->get_weight() ? $this->product->get_weight() . ' ' . $custom_measurement : ''; } return ''; } @@ -221,7 +222,7 @@ class CosmopetProduct extends TimberProduct { // Extract just the posts in sorted order $sorted_siblings = array_map(function($item) { return $item['post']; - }, $siblings_with_weights); + }, $siblings_with_weights); return $sorted_siblings; } @@ -269,48 +270,49 @@ class CosmopetProduct extends TimberProduct { } } - // Отладочная информация - error_log("=== Конструктор товара ==="); - error_log("Текущий товар ID: " . $this->id); - error_log("Текущий вес (числовой): " . $current_weight); - error_log("Всего товаров в коллекции: " . count($all_products)); - error_log("Атрибуты текущего товара: " . print_r($current_product_attributes, true)); + + + // Получаем упорядоченные таксономии + $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(); - $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 ($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); + } + } - 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); - } + // Проверяем, подходит ли товар для каждой таксономии + foreach ($this->sibling_categories as $taxonomy) { + // Пропускаем, если у текущего товара нет значения для этой категории + if (!isset($current_product_attributes[$taxonomy])) { + continue; } // Проверяем, совпадают ли все остальные атрибуты и вес $attributes_match = true; - $differences = []; - // Проверяем только атрибуты из sibling_categories + // Проверяем все атрибуты кроме текущей таксономии foreach ($this->sibling_categories as $compare_taxonomy) { if ($compare_taxonomy === $taxonomy) { continue; // Пропускаем проверяемую категорию @@ -321,7 +323,6 @@ class CosmopetProduct extends TimberProduct { // Проверяем, есть ли у сравниваемого товара значение для этой категории if (!isset($compare_attributes[$compare_taxonomy])) { $attributes_match = false; - $differences[] = "Нет атрибута $compare_taxonomy у сравниваемого товара"; break; } @@ -332,7 +333,6 @@ class CosmopetProduct extends TimberProduct { if (array_diff($current_values, $compare_values) !== [] || array_diff($compare_values, $current_values) !== []) { $attributes_match = false; - $differences[] = "Не совпадают значения для $compare_taxonomy"; break; } } @@ -341,22 +341,18 @@ class CosmopetProduct extends TimberProduct { else { if (isset($compare_attributes[$compare_taxonomy])) { $attributes_match = false; - $differences[] = "У сравниваемого товара есть атрибут $compare_taxonomy, а у текущего нет"; break; } } } // Проверяем вес (числовое сравнение) - $compare_weight = $product->getNumericWeight(); - if (abs($current_weight - $compare_weight) > 0.01) { // Используем небольшой допуск для float + if (abs($current_weight - $compare_weight) > 0.01) { $attributes_match = false; - $differences[] = "Не совпадает вес: текущий '$current_weight' vs сравниваемый '$compare_weight'"; } // Если все атрибуты и вес совпадают, добавляем товар в группу if ($attributes_match) { - error_log("Товар {$product->id} подходит для атрибута $taxonomy"); $product_terms = get_the_terms($product->id, $taxonomy); if ($product_terms && !is_wp_error($product_terms)) { foreach ($product_terms as $term) { @@ -364,41 +360,53 @@ class CosmopetProduct extends TimberProduct { if (!isset($constructor[$taxonomy]['options'][$option_key])) { $constructor[$taxonomy]['options'][$option_key] = [ 'term_id' => $term->term_id, - 'name' => $term->name, + 'name' => $this->getTermName($term->term_id, $taxonomy), 'slug' => $term->slug, + 'icon' => $this->getTermIcon($term->term_id, $taxonomy), 'products' => [] ]; } $constructor[$taxonomy]['options'][$option_key]['products'][] = $product; } } - } 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}"); + } + + // Сортируем опции по порядку терминов для каждой таксономии + 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 = [ - 'pa_age-of-the-cat' => 'ВОЗРАСТ КОШКИ', - 'pa_age-of-the-dog' => 'ВОЗРАСТ СОБАКИ', - 'pa_compound' => 'ВКУС КОРМА', - 'pa_reproductive-status' => 'РЕПРОДУКТИВНЫЙ СТАТУС', - 'pa_series' => 'СЕРИЯ', + '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__('СЕРИЯ'), ]; return $labels[$taxonomy] ?? wc_attribute_label($taxonomy); @@ -412,6 +420,171 @@ class CosmopetProduct extends TimberProduct { return null; } + /** + * Получает таксономии в правильном порядке с учетом сортировки + * @return array Массив таксономий с их порядком + */ + protected function getOrderedTaxonomies() { + $ordered_taxonomies = []; + + foreach ($this->sibling_categories as $taxonomy) { + // Получаем все термины для данной таксономии + $terms = get_terms([ + 'taxonomy' => $taxonomy, + 'hide_empty' => false, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ]); + + // Если menu_order не работает, пробуем сортировку по name + if (is_wp_error($terms) || empty($terms)) { + $terms = get_terms([ + 'taxonomy' => $taxonomy, + 'hide_empty' => false, + 'orderby' => 'name', + 'order' => 'ASC' + ]); + } + + if (!is_wp_error($terms) && !empty($terms)) { + $ordered_taxonomies[$taxonomy] = $terms; + } + } + + return $ordered_taxonomies; + } + + /** + * Получает таксономии в правильном порядке для отображения + * @return array Массив таксономий в порядке отображения + */ + public function getOrderedSiblingCategories() { + return $this->sibling_categories; + } + + /** + * Получает таксономии с их метками в правильном порядке + * @return array Массив таксономий с метками + */ + public function getOrderedTaxonomiesWithLabels() { + $taxonomies_with_labels = []; + + foreach ($this->sibling_categories as $taxonomy) { + $label = $this->getAttributeLabel($taxonomy); + $taxonomies_with_labels[$taxonomy] = $label; + } + + return $taxonomies_with_labels; + } + + /** + * Получает иконку термина из ACF поля + * @param int $term_id ID термина + * @param string $taxonomy Таксономия + * @return string|false URL иконки или false если иконка не найдена + */ + public function getTermIcon($term_id, $taxonomy) { + // Проверяем, есть ли ACF поле 'icon' у термина + $icon = get_field('icon', $taxonomy . '_' . $term_id); + + if ($icon) { + return $icon; + } + + // Если ACF поле не найдено, возвращаем false + return false; + } + + /** + * Получает название термина с приоритетом описания + * @param int $term_id ID термина + * @param string $taxonomy Таксономия + * @return string Название термина + */ + public function getTermName($term_id, $taxonomy) { + $term = get_term($term_id, $taxonomy); + + if (!$term || is_wp_error($term)) { + return ''; + } + + // Сначала пытаемся получить описание термина + $description = get_term_meta($term_id, 'description', true); + + // Также пробуем получить из ACF поля + $acf_description = get_field('description', $taxonomy . '_' . $term_id); + + // Пробуем получить из стандартного поля термина + $term_description = $term->description; + + // Пробуем ACF поле сначала + if (!empty($acf_description)) { + return $acf_description; + } + + // Потом стандартное поле термина + if (!empty($term_description)) { + return $term_description; + } + + // Потом обычное мета-поле + if (!empty($description)) { + return $description; + } + + return $term->name; + } + + /** + * Получает количество товара в корзине + * @return int Количество товара в корзине + */ + public function getCartQuantity() { + if (!function_exists('WC') || !WC()->cart) { + return 0; + } + + $cart = WC()->cart; + $cart_item_key = $this->getCartItemKey(); + + if ($cart_item_key) { + $cart_item = $cart->get_cart_item($cart_item_key); + return $cart_item ? $cart_item['quantity'] : 0; + } + + return 0; + } + + /** + * Получает ключ товара в корзине + * @return string|false Ключ товара в корзине или false если товар не найден + */ + public function getCartItemKey() { + if (!function_exists('WC') || !WC()->cart) { + return false; + } + + $cart = WC()->cart; + + foreach ($cart->get_cart() as $cart_item_key => $cart_item) { + if ($cart_item['product_id'] == $this->id) { + return $cart_item_key; + } + } + + return false; + } + + /** + * Проверяет, есть ли товар в корзине + * @return bool True если товар в корзине, false если нет + */ + public function isInCart() { + return $this->getCartQuantity() > 0; + } + + + public function getAllAttributes() { $attributes = []; foreach ($this->sibling_categories as $taxonomy) { diff --git a/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js b/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js index 32ee157..d49d9b9 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js +++ b/wp-content/themes/cosmopet/modules/shop/components/cart/assets/js/cart.js @@ -1,4 +1,26 @@ jQuery(document).ready(function($) { + + $(document).on('click', '.product-incart__btn--plus', function(e) { + e.preventDefault(); + const key = $(this).data('key'); + const quantity = parseInt($(this).siblings('.product-incart__count').text()) + 1; + updateCart(key, quantity); + $('.product-incart__wrap').addClass('loading'); + }); + + // // Уменьшение количества + $(document).on('click', '.product-incart__btn--minus', function(e) { + e.preventDefault(); + const key = $(this).data('key'); + const quantity = parseInt($(this).siblings('.product-incart__count').text()) - 1; + $('.product-incart__wrap').addClass('loading'); + if (quantity <= 0) { + removeItem(key); // Вызываем удаление, если количество становится 0 + } else { + updateCart(key, quantity); // Обновляем количество, если больше 0 + } + }); + // Открытие/закрытие модалки // $(document).on('click', '.cart-contents, .continue-shopping, .modal__close', function(e) { // e.preventDefault(); @@ -19,7 +41,7 @@ jQuery(document).ready(function($) { }); - $(document).on('click', '.modal__basket .counter__button.plus', function(e) { + $(document).on('click', '.modal__basket .counter__button.plus, .product-incart__btn--plus', function(e) { e.preventDefault(); const key = $(this).data('key'); const input = $(this).siblings('.counter__input'); @@ -28,7 +50,7 @@ jQuery(document).ready(function($) { }); // // Уменьшение количества - $(document).on('click', '.modal__basket .counter__button.minus', function(e) { + $(document).on('click', '.modal__basket .counter__button.minus, .product-incart__btn--minus', function(e) { e.preventDefault(); const key = $(this).data('key'); const input = $(this).siblings('.counter__input'); @@ -144,6 +166,9 @@ jQuery(document).ready(function($) { updateCartFragment(); updateNotices(); + + // Обновляем блок покупки на single странице + updateProductBuyBlock(); // $('[data-key="' + key + '"]').remove() } } @@ -182,6 +207,9 @@ jQuery(document).ready(function($) { updateCartFragment(); updateNotices(); + + // Обновляем блок покупки на single странице + updateProductBuyBlock(); } } }); @@ -241,10 +269,13 @@ jQuery(document).ready(function($) { } // Обновление корзины при добавлении товара - $(document.body).on('added_to_cart', function() { + $(document.body).on('added_to_cart', function(e, fragments, cart_hash, $button) { updateCartFragment(); updateNotices(); openBasketOnFirstAdd(); + + // Обновляем блок покупки на single странице + updateProductBuyBlock(); }); // Функция обновления количества @@ -262,11 +293,16 @@ jQuery(document).ready(function($) { }, complete: function() { $('#modal-basket').removeClass('loading'); + $('.product-incart__wrap').removeClass('loading'); }, success: function(response) { if (response.success) { updateCartFragment(update_full); updateNotices(); + + // Обновляем блок покупки на single странице + updateProductBuyBlock(); + } else { console.error('Ошибка при обновлении корзины'); } @@ -398,6 +434,9 @@ jQuery(document).ready(function($) { updateCartFragment(); updateNotices(); openBasketOnFirstAdd(); + + // Обновляем блок с кнопкой покупки на single странице + updateProductBuyBlock(); } }, complete: function() { @@ -412,6 +451,132 @@ jQuery(document).ready(function($) { }); + + // ===== ФУНКЦИИ ДЛЯ SINGLE СТРАНИЦЫ === + + // Обновление количества через input на single странице +$(document).on('change', '.product-incart__count', function () { + const $count = $(this); + const $wrap = $count.closest('.product-incart__wrap'); + const key = $count.data('key'); + const quantity = parseInt($count.text(), 10); + + if (quantity > 0) { + if (key) { + updateCart(key, quantity); + } + } else { + if (key) { + removeItem(key); + } + } +}); + +// Увеличение количества на single странице +$(document).on('click', '.product-incart__btn--plus', function(e) { + e.preventDefault(); + const $btn = $(this); + const $wrap = $btn.closest('.product-incart__wrap'); + const $count = $wrap.find('.product-incart__count'); + const key = $btn.data('key'); + const currentQuantity = parseInt($count.text()); + const newQuantity = currentQuantity + 1; + + // Показываем загрузку + $wrap.addClass('loading'); + + // Обновляем количество через updateCart + if (key) { + updateCart(key, newQuantity); + } +}); + +// Уменьшение количества на single странице +$(document).on('click', '.product-incart__btn--minus', function(e) { + e.preventDefault(); + const $btn = $(this); + const $wrap = $btn.closest('.product-incart__wrap'); + const $count = $wrap.find('.product-incart__count'); + const key = $btn.data('key'); + const currentQuantity = parseInt($count.text()); + const newQuantity = currentQuantity - 1; + + if (newQuantity <= 0) { + // Показываем загрузку + $wrap.addClass('loading'); + // Удаляем товар из корзины + if (key) { + removeItem(key); + } + } else { + // Показываем загрузку + $wrap.addClass('loading'); + // Обновляем количество через updateCart + if (key) { + updateCart(key, newQuantity); + } + } +}); + +// Функция обновления блока с кнопкой покупки +function updateProductBuyBlock() { + console.log('Updating product buy block'); + + // Проверяем, что мы на странице нового шаблона (не старого) + if ($('.detail').length > 0) { + console.log('Old template detected, skipping buy block update'); + return; + } + + const $container = $('#product-buy-block-wrapper'); + if (!$container.length) { + console.log('Product buy block wrapper not found'); + return; + } + + // Получаем product_id из текущей страницы + const productId = $container.find('[name="add-to-cart"]').val() || + $container.find('.product-incart__wrap').data('product-id') || + $('.product-single').data('product-id'); + + if (!productId) { + console.log('Product ID not found'); + return; + } + + console.log('Product ID:', productId); + + $.ajax({ + url: woocommerce_params.ajax_url, + type: 'POST', + data: { + action: 'update_product_buy_block', + product_id: productId + }, + success: function(response) { + console.log('Update product buy block response:', response); + + if (response.success) { + // Обновляем содержимое контейнера + $container.html(response.data.html); + console.log('HTML updated successfully'); + + // Если товар добавлен в корзину, обновляем фрагменты корзины + if (response.data.in_cart) { + updateCartFragment(); + } + + console.log('Product buy block updated successfully'); + } else { + console.error('Ошибка обновления блока покупки:', response); + } + }, + error: function(xhr, status, error) { + console.error('AJAX ошибка обновления блока покупки:', error); + console.error('Response:', xhr.responseText); + } + }); +} }); @@ -419,3 +584,5 @@ jQuery(document).ready(function($) { + + diff --git a/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js b/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js index 48e293a..589fef3 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js +++ b/wp-content/themes/cosmopet/modules/shop/components/catalog/assets/js/gp-main.js @@ -107,6 +107,18 @@ jQuery(document).ready(function ($) { $('#load-more-products').detach(); $('.product__main').append(data); $('#load-more-products').prependTo('.product__footer'); + var productSwiper = new Swiper('.main-food_products-card-slider', { + effect: 'fade', + fadeEffect: { crossFade: true }, + loop: true, + pagination: { + el: '.swiper-dots', + clickable: true, + bulletClass: 'swiper-pagination-bullet', + bulletActiveClass: 'swiper-pagination-bullet-active', + }, + }); + }, error: function(data) { console.log(data); 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 f1d9a38..418fbb3 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 @@ -137,5 +137,5 @@ $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); +Timber::render('woocommerce/archive-product.twig', $context); ?> \ No newline at end of file diff --git a/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/css/product-card.css b/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/css/product-card.css index cb3d230..36dd37a 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/css/product-card.css +++ b/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/css/product-card.css @@ -276,4 +276,73 @@ background: radial-gradient(278.91% 196.13% at 128.36% -48.29%, #ee6868 0%, #569 display: block; width: 100%; max-width: 350px; +} + +.product-archive-card{ + width: calc(25% - 7.5px); +} + +@media (max-width: 1200px) { + .product-archive-card{ + width: calc(33.333% - 6.666px); + } +} + +@media (max-width: 640px) { + .product-archive-card{ + width: calc(50% - 5px); + } +} + +.product__main{ + gap: 10px; +} + +/* Стили для загрузки на карточках товаров */ +.product-incart__wrap.loading { + position: relative; + pointer-events: none; + opacity: 0.7; +} + +.product-incart__wrap.loading::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(255, 255, 255, 0.8); + z-index: 10; +} + +.product-incart__wrap.loading::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + width: 20px; + height: 20px; + margin: -10px 0 0 -10px; + border: 2px solid #f3f3f3; + border-top: 2px solid #3498db; + border-radius: 50%; + animation: spin 1s linear infinite; + z-index: 11; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + +/* Стили для кнопок во время загрузки */ +.product-incart__wrap.loading .product-incart__btn { + opacity: 0.5; + pointer-events: none; +} + +/* Стили для счетчика во время загрузки */ +.product-incart__wrap.loading .product-incart__count { + opacity: 0.5; } \ No newline at end of file diff --git a/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/js/product-card.js b/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/js/product-card.js index 50e31ff..6e7b14e 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/js/product-card.js +++ b/wp-content/themes/cosmopet/modules/shop/components/product-card/assets/js/product-card.js @@ -13,7 +13,7 @@ jQuery(document).ready(function() { }, }); - jQuery('[data-image-set]').on('click', function() { + jQuery('body').on('click', '[data-image-set]', function() { // Получаем родительский элемент карточки продукта var productCard = jQuery(this).closest('.main-food_products-card'); jQuery(productCard).find('.main-food_products-card__weight-item').removeClass('active') @@ -54,4 +54,6 @@ jQuery(document).ready(function() { jQuery(productCard).find('.main-food_products-cardbottom-btn').attr('data-product_id', jQuery(this).data('product_id')) jQuery(productCard).find('.main-food_products-cardbottom-btn').attr('href', '?add-to-cart=' + jQuery(this).data('product_id')) }); -}); \ No newline at end of file +}); + + diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/css/product-style.css b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css similarity index 83% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/css/product-style.css rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css index f9466fd..6da63a0 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/css/product-style.css +++ b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/css/product-style.css @@ -677,6 +677,7 @@ line-height: 143%; .product-show{ display: flex; flex-grow: 1; + flex-direction: column; } @media (max-width: 576px) { .product_main { @@ -755,4 +756,146 @@ line-height: 143%; .stock, .quantity{ display: none; -} \ No newline at end of file +} + + +.product-incart__wrap{ + display: flex; + align-items: center; + gap: 10px; + margin-top: 20px; + +} +.product-incart__btn{ + height: 50px; + width: 50px; + position: relative; + border-radius: 50%; + background-color: var(--accent-color); +} + +.product-incart__btn--minus::before{ + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 16px; + height: 2px; + background-color: #fff; +} + +.product-incart__btn--plus::before{ + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 16px; + height: 2px; + background-color: #fff; +} + +.product-incart__btn--plus::after{ + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + height: 16px; + width: 2px; + background-color: #fff; +} + +.product-incart{ + display: flex; + align-items: center; + justify-content: space-between; + align-items: center; + padding: 23px 5px; + gap: 10px; + margin: 0 auto; + width: 159px; + height: 60px; + background: color-mix(in srgb, var(--accent-color) 25%, transparent); + border: 2px solid #FFFFFF; + border-radius: 100px; + flex: none; + order: 0; + flex-grow: 0; + font-weight: 900; + font-size: 12px; + color: #fff; +} + +.product-incart__label{ + border: 2px solid #fff; + border-radius: 100px; + padding: 12px 16px; + width: 100%; + height: 60px; + display: flex; + align-items: center; + justify-content: center; + font-weight: 900; + font-size: 12px; + text-align: center; + color: #fff; + background-color: var(--accent-color); +} + +.product-incart-btn{ + +} + + +/* Стили для загрузки корзины на single странице */ + +.product-incart__wrap.loading { + position: relative; + pointer-events: none; + opacity: 0.7; +} + +.product-incart__wrap.loading::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: var(--bg-color); + opacity: .7; + z-index: 10; +} + +.product-incart__wrap.loading::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + width: 20px; + height: 20px; + margin: -10px 0 0 -10px; + border: 2px solid #f3f3f3; + border-top: 2px solid #3498db; + border-radius: 50%; + animation: spin 1s linear infinite; + z-index: 11; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + +/* Стили для кнопок во время загрузки */ +.product-incart__wrap.loading .product-incart__btn { + opacity: 0.5; + pointer-events: none; +} + +/* Стили для счетчика во время загрузки */ +.product-incart__wrap.loading .product-incart__count { + opacity: 0.5; +} diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/avg.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/avg.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/avg.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/avg.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/beef.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/beef.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/beef.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/beef.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/dog-face.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/dog-face.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/dog-face.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/dog-face.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/fish.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/fish.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/fish.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/fish.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/lamb.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/lamb.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/lamb.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/lamb.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/lg.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/lg.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/lg.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/lg.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/mini.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/mini.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/mini.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/mini.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/cat.png b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/cat.png similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/cat.png rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/cat.png diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/cat.png.webp b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/cat.png.webp similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/cat.png.webp rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/cat.png.webp diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/dog.png b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/dog.png similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/dog.png rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/dog.png diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/dog.png.webp b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/dog.png.webp similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/dog.png.webp rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/dog.png.webp diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/mini-dog.png b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/mini-dog.png similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/mini-dog.png rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/mini-dog.png diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/mini-dog.png.webp b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/mini-dog.png.webp similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/pet/mini-dog.png.webp rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/pet/mini-dog.png.webp diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-back.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-back.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-back.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-back.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-breadcrumbs.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-breadcrumbs.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-breadcrumbs.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-breadcrumbs.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-left.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-left.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-left.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-left.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-right.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-right.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-right.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-right.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-selected.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-selected.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/arrow-selected.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/arrow-selected.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/black-x.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/black-x.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product/assets/img/svg/main/black-x.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/svg/main/black-x.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/turkey.svg b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/turkey.svg similarity index 100% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/img/turkey.svg rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/img/turkey.svg diff --git a/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/js/cart-controls.js b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/js/cart-controls.js new file mode 100644 index 0000000..e69de29 diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/js/product-single.js b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/js/product-single.js similarity index 99% rename from wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/js/product-single.js rename to wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/js/product-single.js index 294d446..fef1d94 100644 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product_new/assets/js/product-single.js +++ b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/assets/js/product-single.js @@ -94,4 +94,5 @@ document.addEventListener('DOMContentLoaded', function() { }, 'xml'); }); -}); \ No newline at end of file +}); + diff --git a/wp-content/themes/cosmopet/modules/shop/components/product-single--new/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/component-controller.php new file mode 100644 index 0000000..f0c8046 --- /dev/null +++ b/wp-content/themes/cosmopet/modules/shop/components/product-single--new/component-controller.php @@ -0,0 +1,20 @@ + +get_attributes(); + +/* Получение категорий */ +$tags = get_the_terms($product_id, 'product_cat'); +if (!empty($tags) && !is_wp_error($tags)) { + foreach ($tags as $tag) { + $context_for_twig['product_tags'][] = $tag->name; + } +} + +/* Получение атрибутов */ +if (!empty($product_attributes)) { + foreach ($product_attributes as $taxonomy => $attribute) { + if ($attribute->is_taxonomy()) { + $terms = wc_get_product_terms($product_id, $taxonomy, ['fields' => 'all']); + // $tags = wc_get_product_terms( $product_id, 'pa_catalog_tags' ); + + if (!empty($terms)) { + $attr_values = []; + foreach ($terms as $term) { + $attr_values[] = [ + 'name' => $term->name, + 'slug' => $term->slug, + 'term_id' => $term->term_id, + 'link' => get_term_link($term->term_id, $taxonomy), + ]; + } + $attributes[wc_attribute_label($taxonomy)] = $attr_values; + } + } else { + $attributes[wc_attribute_label($taxonomy)] = $attribute->get_options(); + } + + } +} + +$context_for_twig['product_attributes'] = $attributes; + +/* Получение вариаций товара */ +if ($product->is_type('variable')) { + $available_variations = $product->get_available_variations(); + $variations_data = []; + + foreach ($available_variations as $variation) { + $variation_id = $variation['variation_id']; + $variation_obj = wc_get_product($variation_id); + + $variations_data[] = [ + 'variation_id' => $variation_id, + 'price' => $variation_obj->get_price(), + 'regular_price' => $variation_obj->get_regular_price(), + 'sale_price' => $variation_obj->get_sale_price(), + 'attributes' => $variation['attributes'] + ]; + } + + $context_for_twig['variations'] = $variations_data; +} + +/* ACF-поля и мета-данные продукта */ +$meta_fields = [ + 'composition' => get_post_meta($product_id, '_composition', true), + 'feeding_recommendations' => get_post_meta($product_id, '_feeding_recommendations', true), // Ранее выводились HTML-полем «Рекомендации по кормлению» + 'feeding_recommendations_table' => get_field('feeding_recommendations_table', get_post(get_field('p_tables_field', $product_id))) , // Таблица «Рекомендации по кормлению» + 'nutritional_value' => get_post_meta($product_id, '_nutritional_value', true), + 'vitamins' => get_post_meta($product_id, '_vitamins', true), + 'additives' => get_post_meta($product_id, '_additives', true), + 'energy_value' => get_post_meta($product_id, '_energy_value', true), + 'important' => get_post_meta($product_id, '_important', true), +]; + +$context_for_twig['product_meta'] = $meta_fields; + + +/* Товар оформляется по подписке? */ +$context_for_twig['is_subscription'] = $product->is_type( array( 'subscription', 'subscription_variation', 'variable-subscription' )) ? true : false; + +$context = Timber::get_context(); +$post = Timber::get_post(); +$context['post'] = $post; +$context['wc_breadcrumbs'] = array(); + +if (function_exists('woocommerce_breadcrumb')) { + $args = array( + 'delimiter' => '', + 'wrap_before' => '', + 'wrap_after' => '', + 'before' => '', + 'after' => '', + 'home' => _x('Home', 'breadcrumb', 'woocommerce'), + ); + + $breadcrumbs = new WC_Breadcrumb(); + $breadcrumbs->generate(); + + $formatted_breadcrumbs = array(); + foreach ($breadcrumbs->get_breadcrumb() as $crumb) { + $formatted_breadcrumbs[] = array( + 'text' => $crumb[0], + 'url' => $crumb[1] + ); + } + + $context['wc_breadcrumbs'] = $formatted_breadcrumbs; +} + +$context['product'] = $product; + +$context['related_products'] = array(); +$related_products_ids = $product->get_upsell_ids(); +if ($related_products_ids) { + foreach ($related_products_ids as $related_id) { + $related_product = wc_get_product($related_id); + if ($related_product) { + $context['related_products'][] = $related_product; + } + } +} +if (class_exists('WCS_ATT_Product_Schemes')) { + $schemes = WCS_ATT_Product_Schemes::get_subscription_schemes($product); + $context['has_subscription_options'] = !empty($schemes); +} else { + $context['has_subscription_options'] = false; +} + +Timber::render('_pages/shop/product-single.twig', $context); + +// Подключение стилей для загрузки корзины +add_action('wp_enqueue_scripts', 'single_product_cart_styles'); + +function single_product_cart_styles() { + if (is_product()) { + wp_enqueue_style( + 'single-product-cart-loading', + get_template_directory_uri() . '/modules/shop/components/single-product/assets/css/cart-loading.css', + array(), + '1.0.0' + ); + } +} diff --git a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php b/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php deleted file mode 100644 index db2afe7..0000000 --- a/wp-content/themes/cosmopet/modules/shop/components/single-product/component-controller.php +++ /dev/null @@ -1,152 +0,0 @@ -get_attributes(); - - /* Получение категорий */ - $tags = get_the_terms($product_id, 'product_cat'); - if (!empty($tags) && !is_wp_error($tags)) { - foreach ($tags as $tag) { - $context_for_twig['product_tags'][] = $tag->name; - } - } - - /* Получение атрибутов */ - if (!empty($product_attributes)) { - foreach ($product_attributes as $taxonomy => $attribute) { - if ($attribute->is_taxonomy()) { - $terms = wc_get_product_terms($product_id, $taxonomy, ['fields' => 'all']); - // $tags = wc_get_product_terms( $product_id, 'pa_catalog_tags' ); - - if (!empty($terms)) { - $attr_values = []; - foreach ($terms as $term) { - $attr_values[] = [ - 'name' => $term->name, - 'slug' => $term->slug, - 'term_id' => $term->term_id, - 'link' => get_term_link($term->term_id, $taxonomy), - ]; - } - $attributes[wc_attribute_label($taxonomy)] = $attr_values; - } - } else { - $attributes[wc_attribute_label($taxonomy)] = $attribute->get_options(); - } - - } - } - - $context_for_twig['product_attributes'] = $attributes; - - /* Получение вариаций товара */ - if ($product->is_type('variable')) { - $available_variations = $product->get_available_variations(); - $variations_data = []; - - foreach ($available_variations as $variation) { - $variation_id = $variation['variation_id']; - $variation_obj = wc_get_product($variation_id); - - $variations_data[] = [ - 'variation_id' => $variation_id, - 'price' => $variation_obj->get_price(), - 'regular_price' => $variation_obj->get_regular_price(), - 'sale_price' => $variation_obj->get_sale_price(), - 'attributes' => $variation['attributes'] - ]; - } - - $context_for_twig['variations'] = $variations_data; - } - - /* ACF-поля и мета-данные продукта */ - $meta_fields = [ - 'composition' => get_post_meta($product_id, '_composition', true), - 'feeding_recommendations' => get_post_meta($product_id, '_feeding_recommendations', true), // Ранее выводились HTML-полем «Рекомендации по кормлению» - 'feeding_recommendations_table' => get_field('feeding_recommendations_table', get_post(get_field('p_tables_field', $product_id))) , // Таблица «Рекомендации по кормлению» - 'nutritional_value' => get_post_meta($product_id, '_nutritional_value', true), - 'vitamins' => get_post_meta($product_id, '_vitamins', true), - 'additives' => get_post_meta($product_id, '_additives', true), - 'energy_value' => get_post_meta($product_id, '_energy_value', true), - 'important' => get_post_meta($product_id, '_important', true), - ]; - - $context_for_twig['product_meta'] = $meta_fields; - - - - /* Товар оформляется по подписке? */ - $context_for_twig['is_subscription'] = $product->is_type( array( 'subscription', 'subscription_variation', 'variable-subscription' )) ? true : false; -} - - -add_filter('timber/context', function ($context) use ($context_for_twig) { - return array_merge($context, $context_for_twig); -}); - - - - $context = Timber::get_context(); - $post = Timber::get_post(); - $context['post'] = $post; - - $context['wc_breadcrumbs'] = array(); - - if (function_exists('woocommerce_breadcrumb')) { - $args = array( - 'delimiter' => '', - 'wrap_before' => '', - 'wrap_after' => '', - 'before' => '', - 'after' => '', - 'home' => _x('Home', 'breadcrumb', 'woocommerce'), - ); - - $breadcrumbs = new WC_Breadcrumb(); - $breadcrumbs->generate(); - - $formatted_breadcrumbs = array(); - foreach ($breadcrumbs->get_breadcrumb() as $crumb) { - $formatted_breadcrumbs[] = array( - 'text' => $crumb[0], - 'url' => $crumb[1] - ); - } - - $context['wc_breadcrumbs'] = $formatted_breadcrumbs; - } - - $product_id = get_the_ID(); - $product = wc_get_product($product_id); - - $context['product'] = $product; - - $context['related_products'] = array(); - $related_products_ids = $product->get_upsell_ids(); - if ($related_products_ids) { - foreach ($related_products_ids as $related_id) { - $related_product = wc_get_product($related_id); - if ($related_product) { - $context['related_products'][] = $related_product; - } - } - } -if (class_exists('WCS_ATT_Product_Schemes')) { - $schemes = WCS_ATT_Product_Schemes::get_subscription_schemes($product); - $context['has_subscription_options'] = !empty($schemes); - } else { - $context['has_subscription_options'] = false; - } - - - Timber::render('_pages/shop/product-single.twig', $context); \ No newline at end of file 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 @@ - -getCartQuantity(); + error_log('Cart quantity: ' . $cart_quantity); + + // Подготавливаем контекст для Twig + $context = Timber::context(); + $context['post'] = $product; + $context['product'] = $product->product; + $context['cart_quantity'] = $cart_quantity; + $context['in_cart'] = $cart_quantity > 0; + if($cart_quantity > 0){ + $html = Timber::compile('blocks/modules/shop/product-single-add_to_cart.twig', $context); + } + else{ + $GLOBALS['product'] = $product->product; + ob_start(); + do_action( 'woocommerce_' . $product->product->get_type() . '_add_to_cart' ); + $html = ob_get_clean(); + } + // Рендерим Twig шаблон + error_log('HTML length: ' . strlen($html)); + + wp_send_json_success(array( + 'html' => $html, + 'quantity' => $cart_quantity, + 'in_cart' => $cart_quantity > 0 + )); +} diff --git a/wp-content/themes/cosmopet/modules/shop/module-controller.php b/wp-content/themes/cosmopet/modules/shop/module-controller.php index 20b0cf6..744456a 100644 --- a/wp-content/themes/cosmopet/modules/shop/module-controller.php +++ b/wp-content/themes/cosmopet/modules/shop/module-controller.php @@ -386,6 +386,7 @@ function conditional_dequeue_woocommerce_styles() { } add_action('wp_enqueue_scripts', 'conditional_dequeue_woocommerce_styles', 999); +include_component('shop', 'product-card'); //Функция для получения названия класса по аттрибуту function map_attr_slugs_to_class($slug) { diff --git a/wp-content/themes/cosmopet/page.php b/wp-content/themes/cosmopet/page.php index 49cbf5e..403566a 100644 --- a/wp-content/themes/cosmopet/page.php +++ b/wp-content/themes/cosmopet/page.php @@ -7,6 +7,9 @@ /* TO_DO сюда перенести логику home.php */ +$context = Timber::context(); +$context['post'] = Timber::get_post(); + if (is_account_page() && !is_wc_endpoint_url()){ include_module('profile'); $orders_pg = false; @@ -28,8 +31,5 @@ elseif (is_account_page() && isset($wp->query_vars['view-subscription'])){ } else{ - $context = Timber::context(); - $context['post'] = Timber::get_post(); - Timber::render('page.twig', $context); } \ No newline at end of file diff --git a/wp-content/themes/cosmopet/single-blog_author.php b/wp-content/themes/cosmopet/single-blog_author.php deleted file mode 100644 index a2ac841..0000000 --- a/wp-content/themes/cosmopet/single-blog_author.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/wp-content/themes/cosmopet/single-post.php b/wp-content/themes/cosmopet/single-post.php deleted file mode 100644 index 06a0985..0000000 --- a/wp-content/themes/cosmopet/single-post.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/wp-content/themes/cosmopet/single-product.php b/wp-content/themes/cosmopet/single-product.php deleted file mode 100644 index ff95994..0000000 --- a/wp-content/themes/cosmopet/single-product.php +++ /dev/null @@ -1,22 +0,0 @@ -getTermIcon($term_id, $taxonomy); + }; + + return $context; + }); +}, 1); diff --git a/wp-content/themes/cosmopet/views/_blocks/shop/archive-product-ajaxload.twig b/wp-content/themes/cosmopet/views/_blocks/shop/archive-product-ajaxload.twig index 8a7ec0c..737e702 100644 --- a/wp-content/themes/cosmopet/views/_blocks/shop/archive-product-ajaxload.twig +++ b/wp-content/themes/cosmopet/views/_blocks/shop/archive-product-ajaxload.twig @@ -1,5 +1,9 @@ {% for post in posts %} - {% include '_blocks/shop/archive-product-tease.twig' with {post: post} %} + + {% 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 %} {% if not ended %} diff --git a/wp-content/themes/cosmopet/views/_pages/shop/product-single.twig b/wp-content/themes/cosmopet/views/_pages/shop/product-single.twig index f369540..0addb44 100644 --- a/wp-content/themes/cosmopet/views/_pages/shop/product-single.twig +++ b/wp-content/themes/cosmopet/views/_pages/shop/product-single.twig @@ -19,7 +19,7 @@ {{ function('pll_e', 'к каталогу') }} -