diff --git a/src/Controller/PromosController.php b/src/Controller/PromosController.php index e412566..d391763 100644 --- a/src/Controller/PromosController.php +++ b/src/Controller/PromosController.php @@ -11,17 +11,22 @@ final class PromosController extends BaseController #[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'.$promo]); + if ($this->cache->getItem('list_promos')->isHit()) { + return $this->render('productList.html.twig', ['listType' => 'promos' . $promo]); } $products = Product::when(is_null($promo), fn($q) => $q->whereRaw('priceCurrent < productStandardPrice')) ->orderByDesc('starred') ->orderByDesc('created_by') ->with(['currentPrice', 'lowestPrice']) - ->when(!is_null($promo), fn ($q) => $q->whereRaw("json_extract(promotions, '$.slug') LIKE ?", $promo)) + ->when(!is_null($promo), fn($q) => $q->whereRaw("json_extract(promotions, '$.slug') LIKE ?", $promo)) ->get(); - return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos'.$promo]); + + $promos = Product::select($this->database->getConnection()->raw("distinct json_extract(promotions, '$.slug') as slug, json_extract(promotions, '$.tag') as tag")) + ->whereRaw("json_extract(promotions, '$.tag') is not null") + ->get(); + + return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos' . $promo, 'promos' => $promos->toArray()]); } } diff --git a/templates/productList.html.twig b/templates/productList.html.twig index 7ef955c..8300052 100644 --- a/templates/productList.html.twig +++ b/templates/productList.html.twig @@ -7,6 +7,12 @@ {{ renderCategoryTree(categoryTree, category) | raw }} {% endif %} + {% if listType starts with 'promos' %} + {% for promo in promos %} + PROMO: {{ promo.tag }} + {% endfor %} + {% endif %} + {% if (listType starts with 'category_' and category == null) or not (listType starts with 'category_') or (listType starts with 'category_' and category is not null) %}