Files
e-cosplay/src/Controller/ShopController.php
Serreau Jovann adefe7a1df ```
 feat(shop): Ajoute la page de détails du produit avec schema.org.
```
2025-11-20 13:25:05 +01:00

66 lines
2.4 KiB
PHP

<?php
namespace App\Controller;
use App\Entity\Account;
use App\Entity\AccountResetPasswordRequest;
use App\Entity\Products;
use App\Form\RequestPasswordConfirmType;
use App\Form\RequestPasswordRequestType;
use App\Repository\ProductsRepository;
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
use App\Service\ResetPassword\Event\ResetPasswordEvent;
use Doctrine\ORM\EntityManagerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Twig\Environment;
class ShopController extends AbstractController
{
/**
* Simulation des données produits qui seraient normalement récupérées depuis une base de données.
*/
#[Route(path: '/boutique', name: 'app_shop', options: ['sitemap' => false], methods: ['GET'])]
public function index(ProductsRepository $productsRepository): Response
{
// Correction du nom du template de 'shop.twig' à 'shop/index.html.twig'
// et passage des données centralisées.
return $this->render('shop.twig', [
'featuredProducts' => $productsRepository->findAll()
]);
}
#[Route(path: '/boutique/categorie/{slug}', name: 'app_shop_category', options: ['sitemap' => false], methods: ['GET'])]
public function indexCategorie(): Response
{
return $this->render('shop.twig', [
'featuredProducts' => []
]);
}
#[Route(path: '/boutique/produit/{slug}', name: 'app_product_show', options: ['sitemap' => false], methods: ['GET'])]
public function indexProductShow(?string $slug,ProductsRepository $productsRepository): Response
{
if(is_null($slug)) {
return $this->redirectToRoute('app_shop');
}
$slug = explode('-', $slug);
$endId = end($slug);
if(!is_numeric($endId)) {
return $this->redirectToRoute('app_shop');
}
$p = $productsRepository->find($endId);
return $this->render('shop/product_details.twig', [
'product' => $p
]);
}
}