From e266a8ece75c6ff108458c284219464509acf5c4 Mon Sep 17 00:00:00 2001 From: maksim Date: Tue, 24 Jun 2025 10:31:51 +0300 Subject: [PATCH] =?UTF-8?q?Task=206875=20|=20=D0=92=D1=81=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8E=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=20=D1=81=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20twig=20(=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=BB=20Walkers=20=D0=B8=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20context)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cosmopet/temp-functions/menu-logic.php | 79 ++++++------------- .../cosmopet/temp-functions/modules-logic.php | 2 +- .../themes/cosmopet/templates/header.twig | 70 +--------------- .../cosmopet/templates/menu/main-menu.twig | 12 +++ .../cosmopet/templates/menu/mobile-menu.twig | 24 ++++++ .../cosmopet/templates/menu/product-menu.twig | 15 ++++ 6 files changed, 79 insertions(+), 123 deletions(-) create mode 100644 wp-content/themes/cosmopet/templates/menu/main-menu.twig create mode 100644 wp-content/themes/cosmopet/templates/menu/mobile-menu.twig create mode 100644 wp-content/themes/cosmopet/templates/menu/product-menu.twig diff --git a/wp-content/themes/cosmopet/temp-functions/menu-logic.php b/wp-content/themes/cosmopet/temp-functions/menu-logic.php index 72b628a..2ccad43 100644 --- a/wp-content/themes/cosmopet/temp-functions/menu-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/menu-logic.php @@ -6,65 +6,12 @@ function register_custom_menus() { 'main-menu' => 'Основное меню', 'cats-menu' => 'Меню для кошек', 'dogs-menu' => 'Меню для собак', + 'mobile-menu' => 'Мобильное меню', ]); } add_action('after_setup_theme', 'register_custom_menus'); -class Custom_Walker_Nav_Menu extends Walker_Nav_Menu { - // Открытие уровня подменю - function start_lvl( &$output, $depth = 0, $args = null ) { - $output .= ''; - } - - // Открытие элемента меню - function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { - // Для родительского элемента меню - if ($depth === 0) { - $output .= '
'; - $output .= '' . esc_html($item->title) . ''; - } else { - // Для дочерних элементов - $output .= '
  • '; - $output .= '' . esc_html($item->title) . ''; - } - } - - // Закрытие элемента меню - function end_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { - // Закрытие для родительского элемента - if ($depth === 0) { - $output .= '
  • '; // Закрытие .header-pc-menu__item - } else { - // Закрытие для дочернего элемента - $output .= ''; - } - } -} - - -function get_custom_menu($location) { - // Используем wp_nav_menu с нужными параметрами - ob_start(); // Начинаем буферизацию вывода - wp_nav_menu(array( - 'theme_location' => $location, - 'menu_class' => '', // Не добавляем класс к ul - 'container' => false, // Без контейнера - 'depth' => 2, // Уровень вложенности - 'walker' => new Custom_Walker_Nav_Menu(), // Используем кастомный walker - )); - $menu_html = ob_get_clean(); // Получаем HTML меню - - return $menu_html; -} - - - class Custom_Header_Phone_Menu_Walker extends Walker_Nav_Menu { // Открытие подменю (если есть) function start_lvl( &$output, $depth = 0, $args = null ) { @@ -100,8 +47,6 @@ class Custom_Header_Phone_Menu_Walker extends Walker_Nav_Menu { } } } - - // Функция для вызова меню и передачи HTML в Twig function get_custom_phone_menu($location = 'phone_menu') { ob_start(); // Начинаем буферизацию вывода @@ -115,4 +60,26 @@ function get_custom_phone_menu($location = 'phone_menu') { $menu_html = ob_get_clean(); // Получаем HTML меню return $menu_html; +} + + + + + + + +add_filter('timber/context', 'add_to_context'); + +/** + * Global Timber context. + * + * @param array $context Global context variables. + */ +function add_to_context($context) +{ + $context['main_menu'] = Timber::get_menu('main-menu'); + $context['cat_menu'] = Timber::get_menu('cats-menu'); + $context['dog_menu'] = Timber::get_menu('dogs-menu'); + $context['mobile_menu'] = Timber::get_menu('mobile-menu'); + return $context; } \ No newline at end of file diff --git a/wp-content/themes/cosmopet/temp-functions/modules-logic.php b/wp-content/themes/cosmopet/temp-functions/modules-logic.php index 35f2ebb..022e834 100644 --- a/wp-content/themes/cosmopet/temp-functions/modules-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/modules-logic.php @@ -336,7 +336,7 @@ include_module('layout'); add_action('wp', 'my_custom_checkout_code'); function my_custom_checkout_code() { - if (function_exists('is_checkout')) { + if (function_exists('is_checkout') && is_checkout()) { include_component('shop', 'checkout'); } } diff --git a/wp-content/themes/cosmopet/templates/header.twig b/wp-content/themes/cosmopet/templates/header.twig index cb93c1d..e405b54 100644 --- a/wp-content/themes/cosmopet/templates/header.twig +++ b/wp-content/themes/cosmopet/templates/header.twig @@ -8,63 +8,13 @@
    {# Кошки #} - {% set cat_menu = fn('get_custom_menu', 'cats-menu') %} - {{ cat_menu|raw }} + {% include 'menu/product-menu.twig' with {'child_menu': cat_menu} %} {# Собаки #} - {% set dog_menu = fn('get_custom_menu', 'dogs-menu') %} - {{ dog_menu|raw }} + {% include 'menu/product-menu.twig' with {'child_menu': dog_menu} %}
    -
    - - - {% if current_lang == 'ru' %} -
    - - ПРОДУКЦИЯ - - - {% set cat_m_menu = fn('get_custom_phone_menu', 'cats-menu') %} - {{ cat_m_menu|raw }} - {% set dog_m_menu = fn('get_custom_phone_menu', 'dogs-menu') %} - {{ dog_m_menu|raw }} -
    - {% elseif current_lang == 'en' %} -
    - - BUY - - {% set cat_m_menu = fn('get_custom_phone_menu', 'cats-menu') %} - {{ cat_m_menu|raw }} - {% set dog_m_menu = fn('get_custom_phone_menu', 'dogs-menu') %} - {{ dog_m_menu|raw }} -
    - {% endif %} - - - - - {% if CONSTANTS.DOMAIN != 'AE' %} - - {% endif %} -
    + {% include 'menu/mobile-menu.twig' %}
    - - + {% include 'menu/main-menu.twig' %}
    {% if site_region == 'ru' %} diff --git a/wp-content/themes/cosmopet/templates/menu/main-menu.twig b/wp-content/themes/cosmopet/templates/menu/main-menu.twig new file mode 100644 index 0000000..db56205 --- /dev/null +++ b/wp-content/themes/cosmopet/templates/menu/main-menu.twig @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/menu/mobile-menu.twig b/wp-content/themes/cosmopet/templates/menu/mobile-menu.twig new file mode 100644 index 0000000..f512f9b --- /dev/null +++ b/wp-content/themes/cosmopet/templates/menu/mobile-menu.twig @@ -0,0 +1,24 @@ +
    +{% for item in mobile_menu.items %} +
    + + {{ item.title }} + + {% if item.children %} + {% for child in item.children %} + {{ child.title }} + {% if child.children %} + + {% endif %} + {% endfor %} + {% endif %} +
    +{% endfor %} + +
    \ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/menu/product-menu.twig b/wp-content/themes/cosmopet/templates/menu/product-menu.twig new file mode 100644 index 0000000..1238d06 --- /dev/null +++ b/wp-content/themes/cosmopet/templates/menu/product-menu.twig @@ -0,0 +1,15 @@ +
    +{% for item in child_menu.items %} +{{ item.title }} +{% if item.children %} + +{% endif %} +{% endfor %} +
    +