diff --git a/src/Controller/PromosController.php b/src/Controller/PromosController.php index b54bc74..3767f5d 100644 --- a/src/Controller/PromosController.php +++ b/src/Controller/PromosController.php @@ -8,18 +8,19 @@ use Symfony\Component\Routing\Attribute\Route; final class PromosController extends BaseController { - #[Route('/promos', name: 'app_promos')] - public function __invoke(): Response + #[Route('/promos/{promo?}', name: 'app_promos')] + public function __invoke(?string $promo): Response { if($this->cache->getItem('list_promos')->isHit()) { - return $this->render('productList.html.twig', ['listType' => 'promos']); + return $this->render('productList.html.twig', ['listType' => 'promos'.urlencode($promo)]); } $products = Product::whereRaw('priceCurrent < productStandardPrice') ->orderByDesc('starred') ->orderByDesc('created_by') ->with(['currentPrice', 'lowestPrice']) + ->when(!is_null($promo) , fn ($q) => $q->whereRaw("json_extract(promotions, '$.tag') LIKE ?", $promo)) ->get(); - return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos']); + return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos'.urlencode($promo)]); } } diff --git a/templates/product.html.twig b/templates/product.html.twig index 0240d95..3bbc3fe 100644 --- a/templates/product.html.twig +++ b/templates/product.html.twig @@ -11,7 +11,7 @@