From 9f368a266aa17f0b283d91b230bf0ba7778eb115 Mon Sep 17 00:00:00 2001 From: Krzysiej Date: Tue, 27 Jan 2026 08:56:54 +0100 Subject: [PATCH 1/2] Display big category tree on route /category/ without parameter --- src/Controller/CategoryController.php | 6 +- templates/productList.html.twig | 151 ++++++++++++++------------ 2 files changed, 86 insertions(+), 71 deletions(-) diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index d870fa0..584c93a 100644 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -8,8 +8,8 @@ use Symfony\Component\Routing\Attribute\Route; final class CategoryController extends BaseController { - #[Route('/category/{category}', name: 'app_category')] - public function __invoke(string $category): Response + #[Route('/category/{category?}', name: 'app_category', defaults: ["category" => null])] + public function __invoke(?string $category): Response { if($this->cache->getItem('list_category_'.$category)->isHit()) { return $this->render('productList.html.twig', ['listType' => 'category_'.$category]); @@ -19,8 +19,8 @@ final class CategoryController extends BaseController $products = Product::with(['price', 'lowestPrice']) ->selectRaw('products.*') ->distinct('products.id') + ->when(!is_null($category) , fn ($q) => $q->whereRaw('json_each.value = ?', [$category])) ->fromRaw('products, json_each(products.categories)') - ->whereRaw('json_each.value = ?', [$category]) ->orderByDesc('starred') ->orderByDesc('created_by') ->get(); diff --git a/templates/productList.html.twig b/templates/productList.html.twig index 92436e6..55e415c 100644 --- a/templates/productList.html.twig +++ b/templates/productList.html.twig @@ -1,75 +1,90 @@ {% extends "template.html.twig" %} {% block content %} -{% cache 'list_' ~ listType %} + {% cache 'list_' ~ listType %} -{% if listType starts with 'category_' %} - {{ renderCategoryTree(categoryTree, category) | raw }} -{% endif %} + {% if listType starts with 'category_' %} + {{ renderCategoryTree(categoryTree, category) | raw }} + {% endif %} -
- - - - - - - - - - - - - - {% for product in products %} - - - - - - - - {% endif %} - - - - {% endfor %} -
NameCategoriesLowest PriceCurrent Price
{% if product.starred == true %}★{% else %} ☆ {% endif %}{{ product.name }} - {{ product.name }} - {% if product.stock > 0 %} - stock: {{ product.stock }} - {% else %} - out of stock - {% endif %} - {% if product.isDiscontinued() %} - is discontinued - {% endif %} - {% if product.isNew() %} - is new - {% endif %} - {{ product.subTitle }} - - - link - {% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %} - {{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }} - {% else %} - {% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{%else%}now lowest{% endif %}{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }} -
- {% if product.priceCurrent != product.productStandardPrice %}{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }} {{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}% - {% endif %} -
-
-
-{% endcache %} + {% if (listType starts with 'category_' and category == null) or not (listType starts with 'category_') or (listType starts with 'category_' and category is not null) %} +
+ + + + + + + + + + + + + + {% for product in products %} + + + + + + + + {% endif %} + + + + + {% endfor %} +
NameCategoriesLowest PriceCurrent Price
{% if product.starred == true %}★{% else %} ☆ {% endif %} + {{ product.name }} + {{ product.name }} + {% if product.stock > 0 %} + stock: {{ product.stock }} + {% else %} + out of stock + {% endif %} + {% if product.isDiscontinued() %} + is discontinued + {% endif %} + {% if product.isNew() %} + is new + {% endif %} + {{ product.subTitle }} + + + link + {% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %} + {{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }} + {% else %} + {% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{% else %} + now lowest{% endif %}{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }} +
+ {% if product.priceCurrent != product.productStandardPrice %}{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }} + {{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}% + {% endif %} +
+
+
+ {% endif %} + {% endcache %} {% endblock %} -- 2.52.0 From 5696f23f3db52c345684b039d2a67ca2dab427f5 Mon Sep 17 00:00:00 2001 From: Krzysiej Date: Tue, 27 Jan 2026 08:56:54 +0100 Subject: [PATCH 2/2] Display big category tree on route /category/ without parameter --- src/Controller/CategoryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index 584c93a..c950ae1 100644 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -8,7 +8,7 @@ use Symfony\Component\Routing\Attribute\Route; final class CategoryController extends BaseController { - #[Route('/category/{category?}', name: 'app_category', defaults: ["category" => null])] + #[Route('/category/{category?}', name: 'app_category')] public function __invoke(?string $category): Response { if($this->cache->getItem('list_category_'.$category)->isHit()) { -- 2.52.0