шаг 4 завершен
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user