Files
new.rybstock.ru/views/partials/mega-category-menu.php
T
2026-06-08 10:58:47 +03:00

60 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
/** @var array<int, array<string, mixed>> $megaCategories */
require_once __DIR__ . '/category-icons.php';
if (!function_exists('render_mega_category_children')) {
/**
* @param array<int, array<string, mixed>> $children
*/
function render_mega_category_children(array $children, int $depth = 1): void
{
if ($children === [] || $depth > 3) {
return;
}
?>
<ul class="mega-submenu depth-<?= e((string) $depth) ?>">
<?php foreach ($children as $child): ?>
<li>
<a href="/catalog/<?= e((string) $child['slug']) ?>"><?= e((string) $child['name']) ?></a>
<?php render_mega_category_children($child['children'] ?? [], $depth + 1); ?>
</li>
<?php endforeach; ?>
</ul>
<?php
}
}
?>
<?php if ($megaCategories !== []): ?>
<nav class="category-mega-bar" aria-label="Категории товаров">
<div class="category-mega-inner">
<a class="mega-root mega-all-link" href="/catalog">Весь каталог</a>
<a class="mega-root mega-virtual-link is-promo" href="/promo">Акции</a>
<a class="mega-root mega-virtual-link is-new" href="/new">Новинки</a>
<?php foreach ($megaCategories as $category): ?>
<?php
$hiddenTopCategorySlugs = ['myasnaya-gastronomiya', 'molochnaya-produkciya'];
$hiddenTopCategoryNames = ['Мясная гастрономия', 'Молочная продукция'];
if (
in_array((string) ($category['slug'] ?? ''), $hiddenTopCategorySlugs, true)
|| in_array((string) ($category['name'] ?? ''), $hiddenTopCategoryNames, true)
) {
continue;
} ?>
<?php $iconName = category_tree_icon((string) $category['name']); ?>
<div class="mega-item">
<a class="mega-root" href="/catalog/<?= e((string) $category['slug']) ?>">
<span class="mega-category-icon category-icon is-<?= e($iconName) ?>" aria-hidden="true"><?= category_tree_icon_svg($iconName) ?></span>
<span><?= e((string) $category['name']) ?></span>
</a>
<?php render_mega_category_children($category['children'] ?? []); ?>
</div>
<?php endforeach; ?>
</div>
</nav>
<?php endif; ?>