Files
new.rybstock.ru/views/catalog/index.php
T
2026-06-05 19:57:23 +03:00

79 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
/** @var array<int, array<string, mixed>> $categories */
/** @var array<string, mixed>|null $currentCategory */
/** @var array<int, array<string, mixed>> $products */
/** @var array<string, mixed> $pagination */
$heading = $currentCategory['h1'] ?? $currentCategory['name'] ?? 'Каталог продукции';
$pagination = $pagination ?? [
'base_path' => '/catalog',
'total' => count($products),
'shown' => count($products),
'page' => 1,
'pages' => 1,
'per_page' => 48,
'has_more' => false,
'next_limit' => count($products),
];
?>
<section class="catalog-layout">
<aside class="catalog-sidebar">
<div class="panel sticky-panel">
<h2>Категории</h2>
<?php
$items = $categories;
$depth = 0;
$currentSlug = $currentCategory['slug'] ?? '';
require base_path('views/partials/category-tree.php');
?>
</div>
</aside>
<section class="catalog-content">
<div class="catalog-heading">
<p class="eyebrow"><?= $currentCategory === null ? 'Полный каталог' : 'Категория' ?></p>
<h1><?= e($heading) ?></h1>
<?php if (!empty($currentCategory['description'])): ?>
<p><?= e($currentCategory['description']) ?></p>
<?php else: ?>
<p class="muted">Выберите категорию слева или смотрите товары сразу в каталоге.</p>
<?php endif; ?>
</div>
<?php if ($products === []): ?>
<div class="panel">
<p class="muted">В этой категории товары появятся после переноса каталога со старого сайта.</p>
</div>
<?php else: ?>
<div class="catalog-count-panel">
<span>Показано <?= e((string) $pagination['shown']) ?> из <?= e((string) $pagination['total']) ?> товаров</span>
<?php if (!empty($pagination['has_more'])): ?>
<a href="<?= e((string) $pagination['base_path']) ?>?limit=<?= e((string) $pagination['next_limit']) ?>">Показать еще</a>
<?php endif; ?>
</div>
<div class="product-grid catalog-product-grid">
<?php foreach ($products as $product): ?>
<?php require base_path('views/partials/product-card.php'); ?>
<?php endforeach; ?>
</div>
<?php if ((int) $pagination['pages'] > 1): ?>
<nav class="catalog-pagination" aria-label="Страницы каталога">
<?php for ($pageNumber = 1; $pageNumber <= (int) $pagination['pages']; $pageNumber++): ?>
<a
class="<?= $pageNumber === (int) $pagination['page'] && empty($pagination['cumulative']) ? 'is-current' : '' ?>"
href="<?= e((string) $pagination['base_path']) ?>?page=<?= e((string) $pageNumber) ?>"
>
<?= e((string) $pageNumber) ?>
</a>
<?php endfor; ?>
</nav>
<?php endif; ?>
<?php endif; ?>
</section>
</section>