feat(Product): Ajoute les getters et setters pour updatedAt dans l'entité Product.

 feat(ReserverController): Ajoute une route pour afficher les options de réservation.
 feat(SiteMapListener): Ajoute les URLs des options au sitemap et utilise updatedAt.
 feat(Options): Ajoute la fonction slug pour générer un slug à partir de l'ID et du nom.
This commit is contained in:
Serreau Jovann
2026-01-22 09:27:22 +01:00
parent 5ab4b06d7d
commit 1d7102ec07
4 changed files with 55 additions and 1 deletions

View File

@@ -71,6 +71,13 @@ class ReserverController extends AbstractController
]);
}
#[Route('/reservation/options/{id}', name: 'reservation_options_show')]
public function revervationShowOpitons(string $id, ProductRepository $productRepository): Response
{
}
#[Route('/reservation/produit/{id}', name: 'reservation_product_show')]
public function revervationShowProduct(string $id, ProductRepository $productRepository): Response
{

View File

@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Repository\OptionsRepository;
use Cocur\Slugify\Slugify;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -172,4 +173,11 @@ class Options
{
return $this->updatedAt;
}
public function slug()
{
$s = new Slugify();
return$s->slugify($this->id."-".$this->name);
}
}

View File

@@ -316,4 +316,20 @@ class Product
return $this;
}
/**
* @param \DateTimeImmutable|null $updatedAt
*/
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
/**
* @return \DateTimeImmutable|null
*/
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Security;
use App\Entity\Product;
use App\Repository\OptionsRepository;
use App\Repository\ProductRepository;
use Doctrine\ORM\EntityManagerInterface;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
@@ -19,6 +20,7 @@ class SiteMapListener implements EventSubscriberInterface
{
public function __construct(
private readonly UploaderHelper $uploaderHelper,
private readonly OptionsRepository $optionsRepository,
private readonly ProductRepository $productRepository,
private readonly EntityManagerInterface $entityManager
) {
@@ -92,7 +94,7 @@ class SiteMapListener implements EventSubscriberInterface
);
$decoratedUrl = new GoogleImageUrlDecorator(
new UrlConcrete($productUrl, $t, UrlConcrete::CHANGEFREQ_WEEKLY, 0.5)
new UrlConcrete($productUrl, $product->getUpdatedAt(), UrlConcrete::CHANGEFREQ_WEEKLY, 0.5)
);
$imagePath = $this->uploaderHelper->asset($product, 'imageFile');
@@ -105,6 +107,27 @@ class SiteMapListener implements EventSubscriberInterface
$urlContainer->addUrl($decoratedUrl, 'reservation_product');
}
foreach ($this->optionsRepository->findAll() as $product) {
$productUrl = $urlGenerator->generate(
'reservation_options_show',
['id' => $product->slug()],
UrlGeneratorInterface::ABSOLUTE_URL
);
$decoratedUrl = new GoogleImageUrlDecorator(
new UrlConcrete($productUrl, $product->getUpdatedAt(), UrlConcrete::CHANGEFREQ_WEEKLY, 0.5)
);
$imagePath = $this->uploaderHelper->asset($product, 'imageFile');
if ($imagePath) {
$usedList = [];
// Appel de votre fonction avec l'objet product
$this->addImageToSitemap($decoratedUrl, $usedList, $rootUrl, $imagePath, $product);
}
$urlContainer->addUrl($decoratedUrl, 'reservation_options');
}
}
/**