diff --git a/bin/bash b/bin/bash index 65f38a4..a17b24a 100755 --- a/bin/bash +++ b/bin/bash @@ -1,2 +1,2 @@ #!/usr/bin/env bash -docker compose exec php-app bash \ No newline at end of file +bin/cli bash \ No newline at end of file diff --git a/screenshot1.png b/screenshot1.png index bada133..d9b677e 100644 Binary files a/screenshot1.png and b/screenshot1.png differ diff --git a/src/Controller/NewController.php b/src/Controller/NewController.php index f52b0f9..3a54105 100644 --- a/src/Controller/NewController.php +++ b/src/Controller/NewController.php @@ -9,10 +9,11 @@ use Symfony\Component\Routing\Attribute\Route; final class NewController extends BaseController { - #[Route('/promos', name: 'app_new')] + #[Route('/new', name: 'app_new')] public function __invoke(): Response { - $products = Product::whereHas('created_at', now()->subDays(30)->format('Y-m-d')) + $date = (new \DateTime())->modify('-30 days')->format('Y-m-d'); + $products = Product::where('created_at', '>', $date) ->orderByDesc('starred') ->orderByDesc('created_by') ->with(['currentPrice']) diff --git a/src/Models/Product.php b/src/Models/Product.php index 4ddb836..f2a1ce2 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -31,7 +31,7 @@ class Product extends Model public function isStarred(): bool { - return (bool) $this->starred; + return (bool)$this->starred; } public function currentPrice(): HasOne @@ -65,4 +65,10 @@ class Product extends Model set: fn(array $value) => json_encode($value), ); } + + public function isnew(): bool + { + $newDate = (new \DateTime())->modify('-30 days')->format('Y-m-d'); + return $this->created_at->format('Y-m-d') > $newDate; + } } diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 0012c59..48a0ce5 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -35,7 +35,8 @@ class AppExtension extends AbstractExtension public function newCount(): int { - return Product::whereHas('created_at', now()->subDays(30)->format('Y-m-d'))->count(); + $date = (new \DateTime())->modify('-30 days')->format('Y-m-d'); + return Product::where('created_at', '>', $date)->count(); } public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null diff --git a/templates/productList.html.twig b/templates/productList.html.twig index e8ce0f3..af16217 100644 --- a/templates/productList.html.twig +++ b/templates/productList.html.twig @@ -25,13 +25,16 @@ {% else %} out of stock {% endif %} + {% if product.isnew() %} + is new + {% endif %} {{ product.subTitle }}