шаг 4 завершен

This commit is contained in:
Alisa
2026-06-04 01:30:45 +03:00
parent 62ce8c4d01
commit 238831ad3a
26 changed files with 1703 additions and 70 deletions
+45 -11
View File
@@ -4,20 +4,54 @@ declare(strict_types=1);
/** @var array<int, array<string, mixed>> $items */
/** @var int $depth */
/** @var string $currentSlug */
if (!function_exists('category_tree_has_current')) {
/**
* @param array<string, mixed> $category
*/
function category_tree_has_current(array $category, string $currentSlug): bool
{
if ($currentSlug === '') {
return false;
}
if (($category['slug'] ?? '') === $currentSlug) {
return true;
}
foreach (($category['children'] ?? []) as $child) {
if (category_tree_has_current($child, $currentSlug)) {
return true;
}
}
return false;
}
}
?>
<ul class="category-list depth-<?= e((string) $depth) ?>">
<?php foreach ($items as $category): ?>
<li>
<a href="/catalog/<?= e($category['slug']) ?>"><?= e($category['name']) ?></a>
<?php if (!empty($category['children'])): ?>
<?php
$previousItems = $items;
$items = $category['children'];
$depth++;
require __DIR__ . '/category-tree.php';
$depth--;
$items = $previousItems;
?>
<?php $isCurrent = ($currentSlug ?? '') === $category['slug']; ?>
<?php $hasChildren = !empty($category['children']); ?>
<?php $shouldOpen = category_tree_has_current($category, $currentSlug ?? ''); ?>
<li class="<?= $isCurrent ? 'is-current' : '' ?>">
<?php if ($hasChildren): ?>
<details class="category-details" <?= $shouldOpen ? 'open' : '' ?>>
<summary>
<a class="<?= $isCurrent ? 'is-current-link' : '' ?>" href="/catalog/<?= e($category['slug']) ?>"><?= e($category['name']) ?></a>
</summary>
<?php
$previousItems = $items;
$items = $category['children'];
$depth++;
require __DIR__ . '/category-tree.php';
$depth--;
$items = $previousItems;
?>
</details>
<?php else: ?>
<a href="/catalog/<?= e($category['slug']) ?>"><?= e($category['name']) ?></a>
<?php endif; ?>
</li>
<?php endforeach; ?>
+35
View File
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/** @var array<string, mixed> $product */
?>
<article class="product-card">
<p class="product-category"><?= e($product['category_name'] ?? 'Каталог') ?></p>
<h3><a href="/product/<?= e($product['slug']) ?>"><?= e($product['name']) ?></a></h3>
<p><?= e($product['variant_name'] ?? 'Выберите доступную фасовку') ?></p>
<?php if ($product['price_per_unit'] !== null): ?>
<span class="price-line">за <?= e($product['unit'] ?? 'ед.') ?>: <?= e((string) $product['price_per_unit']) ?> руб.</span>
<?php endif; ?>
<?php if ($product['package_price'] !== null): ?>
<strong>
<?php if (!empty($product['old_package_price'])): ?>
<span class="old-price"><?= e((string) $product['old_package_price']) ?> руб.</span>
<?php endif; ?>
<?= e((string) $product['package_price']) ?> руб. за фасовку
</strong>
<?php endif; ?>
<?php if (!empty($product['price_tiers'])): ?>
<ul class="price-tiers">
<?php foreach ($product['price_tiers'] as $tier): ?>
<li>
<span><?= e($tier['label']) ?></span>
<strong><?= e((string) $tier['price']) ?> руб.</strong>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</article>