diff --git a/README.md b/README.md index 5882189..c7b8b36 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 1. Clone repository using `git clone https://git.techtube.pl/krzysiej/ryobi-crawler.git` 2. Cd into project directory `cd ryobi-crawler` -3. Build and start docker container `docker compose up -d` +3. Build and start docker container `docker compose up -d --build --force-recreate` 4. Run `docker compose exec php-app php console.php app:migrate` file to create `database.sqlite` and create tables. 5. Run `docker compose exec php-app php console.php app:scrape` command to scrape all the products from the ryobi website. 6. Access web interface using `localhost:9001` address in web browser. diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 7d612da..e7e6cbd 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -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(); diff --git a/src/Models/Product.php b/src/Models/Product.php index cbafa89..3878df2 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -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); diff --git a/templates/productList.html.twig b/templates/productList.html.twig index ad0672b..c121300 100644 --- a/templates/productList.html.twig +++ b/templates/productList.html.twig @@ -46,6 +46,7 @@ link {{ product.price.last.price | format_currency('PLN', {}, 'pl') }} + {{ product.lowestPrice.price | format_currency('PLN', {}, 'pl') }}
{% if product.price.last.price != product.price.last.productStandardPrice %}