diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index b4624b1..27c190b 100644 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -15,7 +15,7 @@ final class CategoryController extends BaseController return $this->render('productList.html.twig', ['listType' => 'category_'.$category]); } - $products = Product::with('price') + $products = Product::with(['price', 'lowestPrice']) ->selectRaw('products.*') ->distinct('products.id') ->fromRaw('products, json_each(products.categories)') diff --git a/src/Controller/DiscontinuedController.php b/src/Controller/DiscontinuedController.php index 2909882..d45acc5 100644 --- a/src/Controller/DiscontinuedController.php +++ b/src/Controller/DiscontinuedController.php @@ -20,7 +20,7 @@ final class DiscontinuedController extends BaseController $products = Product::where('updated_at', '<', now()->format('Y-m-d')) ->orderByDesc('starred') ->orderByDesc('created_by') - ->with(['currentPrice']) + ->with(['currentPrice', 'lowestPrice']) ->get(); return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'discontinued']); } diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index e7e6cbd..f44ddd4 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -11,9 +11,9 @@ final class IndexController extends BaseController #[Route('/', name: 'app_home')] public function __invoke(): Response { -// if($this->cache->getItem('list_all')->isHit()) { -// return $this->render('productList.html.twig', ['listType' => 'all']); -// } + if ($this->cache->getItem('list_all')->isHit()) { + return $this->render('productList.html.twig', ['listType' => 'all']); + } $products = Product::with(['currentStock', 'price', 'lowestPrice']) ->orderByDesc('starred') ->orderByDesc('created_by') diff --git a/src/Controller/NewController.php b/src/Controller/NewController.php index 18a656f..f39543e 100644 --- a/src/Controller/NewController.php +++ b/src/Controller/NewController.php @@ -21,7 +21,7 @@ final class NewController extends BaseController $products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d')) ->orderByDesc('starred') ->orderByDesc('created_by') - ->with(['currentPrice']) + ->with(['currentPrice', 'lowestPrice']) ->get(); return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']); } diff --git a/src/Controller/PromosController.php b/src/Controller/PromosController.php index 1befa8b..81c6753 100644 --- a/src/Controller/PromosController.php +++ b/src/Controller/PromosController.php @@ -19,7 +19,7 @@ final class PromosController extends BaseController $products = Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice')) ->orderByDesc('starred') ->orderByDesc('created_by') - ->with(['currentPrice']) + ->with(['currentPrice', 'lowestPrice']) ->get(); return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos']); } diff --git a/templates/productList.html.twig b/templates/productList.html.twig index c121300..c0ba7e9 100644 --- a/templates/productList.html.twig +++ b/templates/productList.html.twig @@ -11,7 +11,8 @@ Name Categories - Price + Lowest Price + Current Price @@ -45,8 +46,8 @@ link - {{ product.price.last.price | format_currency('PLN', {}, 'pl') }} - {{ product.lowestPrice.price | format_currency('PLN', {}, 'pl') }} + {% if product.lowestPrice.price != product.price.last.price %}{{ product.lowestPrice.price | format_currency('PLN', {}, 'pl') }}{% endif %} + {{ product.price.last.price | format_currency('PLN', {}, 'pl') }}
{% if product.price.last.price != product.price.last.productStandardPrice %}