diff --git a/src/Controller/LowestPriceController.php b/src/Controller/LowestPriceController.php new file mode 100644 index 0000000..66a1808 --- /dev/null +++ b/src/Controller/LowestPriceController.php @@ -0,0 +1,29 @@ +cache->getItem('lowest_price')->isHit()) { + return $this->render('productList.html.twig', ['listType' => $listType]); + } + + $products = Product::whereRaw('priceCurrent = priceLowest') + ->whereRaw('lastSeen = "'.now()->format('Y-m-d').'"') + ->whereRaw('priceCurrent < productStandardPrice') + ->orderByDesc('starred') + ->orderByDesc('created_by') + ->with(['currentPrice', 'lowestPrice']) + ->get(); + return $this->render('productList.html.twig', ['products' => $products, 'listType' => $listType]); + } +} diff --git a/src/Controller/NewController.php b/src/Controller/NewController.php index f39543e..cf1f3ee 100644 --- a/src/Controller/NewController.php +++ b/src/Controller/NewController.php @@ -2,7 +2,6 @@ namespace Krzysiej\RyobiCrawler\Controller; -use Illuminate\Database\Eloquent\Builder; use Krzysiej\RyobiCrawler\Models\Product; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; diff --git a/src/Controller/ProductController.php b/src/Controller/ProductController.php index eb9f629..b7d5cba 100644 --- a/src/Controller/ProductController.php +++ b/src/Controller/ProductController.php @@ -3,7 +3,6 @@ namespace Krzysiej\RyobiCrawler\Controller; use Krzysiej\RyobiCrawler\Models\Product; -use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Twig\Error\LoaderError; diff --git a/src/Controller/PromosController.php b/src/Controller/PromosController.php index a440cc6..b54bc74 100644 --- a/src/Controller/PromosController.php +++ b/src/Controller/PromosController.php @@ -2,7 +2,6 @@ namespace Krzysiej\RyobiCrawler\Controller; -use Illuminate\Database\Eloquent\Builder; use Krzysiej\RyobiCrawler\Models\Product; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index f742553..1a08554 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -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)); diff --git a/templates/template.html.twig b/templates/template.html.twig index 2fb5ba5..da00920 100644 --- a/templates/template.html.twig +++ b/templates/template.html.twig @@ -25,6 +25,9 @@