Linking to promo pages

This commit is contained in:
2026-02-02 09:43:18 +01:00
parent cfb70a365d
commit a21e366c2c
3 changed files with 7 additions and 6 deletions

View File

@@ -8,18 +8,19 @@ use Symfony\Component\Routing\Attribute\Route;
final class PromosController extends BaseController final class PromosController extends BaseController
{ {
#[Route('/promos', name: 'app_promos')] #[Route('/promos/{promo?}', name: 'app_promos')]
public function __invoke(): Response public function __invoke(?string $promo): Response
{ {
if($this->cache->getItem('list_promos')->isHit()) { 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') $products = Product::whereRaw('priceCurrent < productStandardPrice')
->orderByDesc('starred') ->orderByDesc('starred')
->orderByDesc('created_by') ->orderByDesc('created_by')
->with(['currentPrice', 'lowestPrice']) ->with(['currentPrice', 'lowestPrice'])
->when(!is_null($promo) , fn ($q) => $q->whereRaw("json_extract(promotions, '$.tag') LIKE ?", $promo))
->get(); ->get();
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos']); return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos'.urlencode($promo)]);
} }
} }

View File

@@ -11,7 +11,7 @@
<td> <td>
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a> <a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span> <span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% if product.promotions is not null and product.promotions.hasPromotion %}<span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>{% endif %} {% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.tag}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %}
</td> </td>
<td> <td>
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';"> <nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">

View File

@@ -49,7 +49,7 @@
<span class="badge text-bg-light"><a <span class="badge text-bg-light"><a
href="{{ path('app_search', {'search': product.subTitle}) }}" href="{{ path('app_search', {'search': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span> class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% if product.promotions is not null and product.promotions.hasPromotion %}<span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>{% endif %} {% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.tag}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %}
</td> </td>
<td class="align-middle"> <td class="align-middle">
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';"> <nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">