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 %} -
| - | - | Name | -Categories | -- | Lowest Price | -Current Price | -- |
|---|---|---|---|---|---|---|---|
| {% if product.starred == true %}★{% else %} ☆ {% endif %} | -- {{ 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 %} | - {% 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 %}
-
- |
-
| + | + | Name | +Categories | ++ | Lowest Price | +Current Price | ++ |
|---|---|---|---|---|---|---|---|
| {% if product.starred == true %}★{% else %} ☆ {% endif %} + | ++ {{ 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 %} | + {% 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 %}
+
+ |
+