<?php
namespace App\Controller\Front;
use App\Repository\CategoryRepository;
use App\Repository\ProductPageRepository;
use App\Repository\SubCategoryRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class ProductPageController extends AbstractController
{
/**
* @var CategoryRepository
*/
private CategoryRepository $categoryRepository;
/**
* @var SubCategoryRepository
*/
private SubCategoryRepository $subCategoryRepository;
/**
* @var ProductPageRepository
*/
private ProductPageRepository $productPageRepository;
public function __construct(
CategoryRepository $categoryRepository,
SubCategoryRepository $subCategoryRepository,
ProductPageRepository $productPageRepository)
{
$this->categoryRepository = $categoryRepository;
$this->subCategoryRepository = $subCategoryRepository;
$this->productPageRepository = $productPageRepository;
}
/**
* @Route("/product-services/{category_slug}/{subcategory_slug}/{slug_page}", name="front_product_page")
*/
public function productPage(string $category_slug, string $subcategory_slug, string $slug_page)
{
$productPage = $this->productPageRepository->findOneBy(['slug' => $slug_page]);
$subCategory = $productPage->getSubCategory();
$allProductsPage = $subCategory->getProductPages();
$nextProductPage = null;
foreach ($allProductsPage as $key => $allProductPage) {
if ($allProductPage->getId() === $productPage->getId()) {
$nextProductPage = $allProductsPage[$key + 1];
}
}
return $this->render('front/product/product_single.html.twig', [
'productPage' => $productPage,
'nextProductPage' => $nextProductPage
]);
}
}