Files
new.rybstock.ru/app/Controllers/CatalogController.php
T
2026-06-04 01:30:45 +03:00

61 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controllers;
use App\Repositories\CategoryRepository;
use App\Repositories\ProductRepository;
final class CatalogController
{
public function index(): void
{
$categoryRepository = new CategoryRepository();
$productRepository = new ProductRepository();
view('catalog/index', [
'title' => 'Каталог продукции - Рыбсток',
'metaDescription' => 'Полный каталог Рыбсток: рыба, морепродукты, икра, мясо, сыры, полуфабрикаты и продукты с доставкой.',
'metaKeywords' => 'каталог Рыбсток, рыба, морепродукты, мясо, сыры, полуфабрикаты',
'breadcrumbs' => [
['title' => 'Главная', 'url' => '/'],
['title' => 'Каталог'],
],
'categories' => $categoryRepository->tree(),
'currentCategory' => null,
'products' => $productRepository->catalogPreview(48),
]);
}
public function category(string $slug): void
{
$categoryRepository = new CategoryRepository();
$productRepository = new ProductRepository();
$category = $categoryRepository->findBySlug($slug);
if ($category === null) {
http_response_code(404);
view('pages/404', [
'title' => 'Категория не найдена - Рыбсток',
'breadcrumbs' => [
['title' => 'Главная', 'url' => '/'],
['title' => 'Каталог', 'url' => '/catalog'],
['title' => 'Категория не найдена'],
],
]);
return;
}
view('catalog/index', [
'title' => ($category['seo_title'] ?: $category['name']) . ' - Рыбсток',
'metaDescription' => $category['seo_description'] ?: '',
'metaKeywords' => $category['seo_keywords'] ?: '',
'breadcrumbs' => $categoryRepository->breadcrumbs((int) $category['id']),
'categories' => $categoryRepository->tree(),
'currentCategory' => $category,
'products' => $productRepository->forCategory((int) $category['id'], 48),
]);
}
}