Add the lowest price column to every product list view

This commit is contained in:
Krzysztof Płaczek
2025-05-14 10:28:58 +02:00
parent beb717f9b9
commit 7352eea270
6 changed files with 11 additions and 10 deletions

View File

@@ -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)')

View File

@@ -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']);
}

View File

@@ -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')

View File

@@ -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']);
}

View File

@@ -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']);
}