Add lowest price first draft.

This commit is contained in:
2025-05-13 23:34:51 +02:00
parent 2471a61076
commit beb717f9b9
4 changed files with 11 additions and 5 deletions

View File

@@ -11,10 +11,10 @@ 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']);
}
$products = Product::with(['currentStock', 'price'])
// 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')
->get();

View File

@@ -41,6 +41,11 @@ class Product extends Model
return $this->hasOne(Price::class)->latestOfMany('created_at');
}
public function lowestPrice(): HasOne
{
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
}
public function stock(): HasMany
{
return $this->hasMany(Stock::class);