Filer items that have currently the lowest price.

This commit was merged in pull request #39.
This commit is contained in:
2026-01-11 10:32:29 +01:00
parent 653f94f9c9
commit 45343c9121
6 changed files with 41 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ class AppExtension extends AbstractExtension
new TwigFunction('allCount', [$this, 'allCount']),
new TwigFunction('newCount', [$this, 'newCount']),
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
new TwigFunction('lowestPriceCount', [$this, 'lowestPriceCount']),
];
}
@@ -52,6 +53,14 @@ class AppExtension extends AbstractExtension
return Product::where('lastSeen', '<>', now()->format('Y-m-d'))->count();
}
public function lowestPriceCount(): int
{
return Product::whereRaw('priceCurrent = priceLowest')
->whereRaw('lastSeen = "'.now()->format('Y-m-d').'"')
->whereRaw('priceCurrent < productStandardPrice')
->count();
}
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
{
return $items->first(fn($item) => str_starts_with($item->created_at, $date));