19 Commits

Author SHA1 Message Date
5fbd555bb3 Start of changing tabled to flexboxes 2026-01-07 08:18:56 +01:00
de4915972c Merge pull request 'Autowire database connection.' (#29) from feature/autowired-database into master
Reviewed-on: #29
2026-01-04 20:31:32 +01:00
9c2405dd3f Merge branch 'refs/heads/master' into feature/autowired-database
# Conflicts:
#	templates/productList.html.twig
2026-01-04 20:29:35 +01:00
da6a8f86c2 Update 2026-01-02 12:21:33 +01:00
2c40fb0e61 Update 2026-01-02 12:15:42 +01:00
5314a6a70a Fix search twig cache. 2026-01-01 18:46:18 +01:00
Krzysztof Płaczek
f772532309 Merge remote-tracking branch 'origin/feature/autowired-database' into feature/autowired-database 2025-05-15 11:14:31 +02:00
Krzysztof Płaczek
17159e811f Remove bottom margin for breadcrumbs 2025-05-15 11:14:00 +02:00
Krzysztof Płaczek
76d8b7d9cf Autowire database connection. 2025-05-14 15:15:49 +02:00
Krzysztof Płaczek
f30304cbe9 Autowire database connection. 2025-05-14 13:15:36 +02:00
dc287aadc6 Merge pull request 'feature/lowest-price' (#27) from feature/lowest-price into master
Reviewed-on: #27
2025-05-14 12:46:12 +02:00
708a5eeae0 Merge pull request 'Implement a caching mechanism' (#28) from feature/cache into master
Reviewed-on: #28
2025-05-14 12:45:57 +02:00
Krzysztof Płaczek
7352eea270 Add the lowest price column to every product list view 2025-05-14 10:28:58 +02:00
Krzysztof Płaczek
e97d976705 Implement a caching mechanism 2025-05-14 09:03:25 +02:00
beb717f9b9 Add lowest price first draft. 2025-05-13 23:34:51 +02:00
2471a61076 Merge pull request 'Implement a caching mechanism' (#26) from feature/cache into master
Reviewed-on: #26
2025-05-13 18:35:29 +02:00
Krzysztof Płaczek
a01174b414 Implement a caching mechanism 2025-05-13 18:29:51 +02:00
512de51d08 Merge pull request 'All products menu link' (#25) from feature/count-all-products into master
Reviewed-on: #25
2025-02-19 15:35:08 +01:00
Krzysztof Płaczek
e6e8f2fc15 All products menu link 2025-02-19 15:34:51 +01:00
27 changed files with 1117 additions and 757 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,5 @@
/vendor/
.idea
database.sqlite
*.sqlite
var/cache/
.env.local

View File

@@ -1,8 +1,8 @@
FROM php:8.3-cli
WORKDIR /usr/src/app
ENV PHP_MEMORY_LIMIT=512M
RUN echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit.ini
ENV PHP_MEMORY_LIMIT=1500M
RUN echo "memory_limit=1500M" > /usr/local/etc/php/conf.d/memory-limit.ini
RUN apt-get update && apt-get install -y \
git \
unzip \

View File

@@ -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.
@@ -17,10 +17,17 @@
3. Refresh cache on production by removing cache directory: `rm -rf var/cache`
4. Start and build image in one go with command: `docker compose up -d --build --force-recreate`
## Bonus
### Install composer package
1. Run `bin/composer require vendor/package-name`
## Running Cron
For now only way of running `app:scrape` command on schedule is to use host crontab.
1. Run `crontab -e` command to edit host crontab job file
1. Run `crontab -e` command to edit a host crontab job file
2. Add a new line with e.g. line like this `0 1 * * * cd /var/project/directory/ && docker compose exec php-app php console.php app:scrape`
3. Save and exit file editor. Cron will execute `app:scrape` once per day.

2
bin/cacheclean Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
bin/cli rm -rf var/cache

2
bin/cachewarmup Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
bin/cli php console.php app:cache:warm-twig

3
bin/composer Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
[ -z "$1" ] && bin/cli composer list && exit
bin/cli composer "$@"

View File

@@ -11,7 +11,9 @@
"symfony/twig-bundle": "^7.1",
"symfony/dotenv": "^7.1",
"twig/intl-extra": "^3.13",
"twig/extra-bundle": "^3.13"
"twig/extra-bundle": "^3.13",
"symfony/cache": "^7.2",
"twig/cache-extra": "^3.21"
},
"autoload": {
"psr-4": {

1474
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,18 +2,16 @@
include_once 'vendor/autoload.php';
use Krzysiej\RyobiCrawler\Command\Migrate;
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
use Symfony\Component\Console\Application;
use Krzysiej\RyobiCrawler\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
if (php_sapi_name() !== 'cli') {
header('Location: browser.php');
echo 'Execute this script in cli only';
exit;
}
$application = new Application('Ryobi website scraper application', '1.1.1');
$application->add(new ScrapeWebsite());
$application->add(new Migrate());
$kernel = new Kernel('dev', true);
$application = new Application($kernel);
$application->setName('Ryobi website scraper application');
$application->setVersion('1.2.0');
$application->run();

View File

@@ -1,46 +1,11 @@
<?php
use Krzysiej\RyobiCrawler\Twig\AppExtension;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Krzysiej\RyobiCrawler\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
require 'vendor/autoload.php';
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function registerBundles(): iterable
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Twig\Extra\TwigExtraBundle\TwigExtraBundle(),
];
}
protected function configureContainer(ContainerConfigurator $container): void
{
$container->extension('framework', [
'secret' => 'S0ME_SECRET'
]);
$container->services()
->load('Krzysiej\\RyobiCrawler\\Controller\\', __DIR__.'/src/Controller/*')
->autowire()
->autoconfigure()
;
$container->services()->set(AppExtension::class)->tag('twig.extension');
}
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import(__DIR__.'/src/Controller/', 'attribute');
}
}
(new Dotenv())->bootEnv(__DIR__.'/.env');
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);

View File

@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Krzysiej\RyobiCrawler\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Database\Capsule\Manager as Capsule;
use Krzysiej\RyobiCrawler\Models\Product;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
#[AsCommand(name: 'app:cache:warm-twig', description: 'Warmup twig cache')]
class CacheWarmCommand extends Command
{
public function __construct(
private Environment $twig,
private RequestStack $requestStack,
private FilesystemAdapter $cache,
) {
parent::__construct();
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$this->cache->clear();
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => __DIR__ . '/../../database.sqlite',
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$progress = new ProgressBar($output);
$progress->start();
$products = Product::with([
'price' => fn($query) => $query->orderByDesc('created_at'),
'stock' => fn($query) => $query->orderByDesc('created_at'),
])->get();
$progress->setMaxSteps(count($products));
$request = Request::create('/cache-warm');
$this->requestStack->push($request);
foreach ($products as $product) {
$priceList = $product->price()->pluck('price');
$stockList = $product->stock()->pluck('stock');
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
$stockDates = $product->stock()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
$this->twig->render('product.html.twig', [
'product' => $product,
'price_list' => $this->prepareChartData($priceDates, $priceList),
'stock_list' => $this->prepareChartData($stockDates, $stockList),
'price_dates' => implode("','", $priceDates),
]);
$progress->advance();
}
$progress->finish();
$output->writeln('');
$output->writeln('DONE');
return Command::SUCCESS;
}
private function prepareChartData($set1, $set2): string
{
$data = [];
foreach ($set1 as $key => $value) {
$data[] = ['x' => $value, 'y' => $set2[$key]];
}
$stringData = json_encode($data);
return str_replace(['"x"', '"y"'], ['x', 'y'], $stringData);
}
}

View File

@@ -21,15 +21,13 @@ class ScrapeWebsite extends Command
{
private Client $client;
public function __construct(protected Capsule $database)
{
parent::__construct();
}
protected function configure(): void
{
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => __DIR__ . '/../../database.sqlite',
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$this->client = new Client();
}

View File

@@ -2,9 +2,8 @@
namespace Krzysiej\RyobiCrawler\Controller;
use Illuminate\Database\Eloquent\Builder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Twig\Environment;
use Illuminate\Database\Capsule\Manager as Capsule;
@@ -12,26 +11,7 @@ class BaseController extends AbstractController
{
protected Environment $twig;
public function __construct()
public function __construct(protected FilesystemAdapter $cache, protected Capsule $database)
{
$capsule = new Capsule;
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../../database.sqlite']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
protected function handleOrderProducts(Builder $builder, Request $request): Builder
{
$builder->orderByDesc('starred')->orderByDesc('created_by');
if ($request->query->get('order')) {
$orderField = $request->query->get('order');
$direction = 'desc';
if (str_starts_with($orderField, '-')) {
$direction = 'asc';
}
$builder->orderBy($request->query->get('order'), $direction);
}
return $builder;
}
}

View File

@@ -11,7 +11,11 @@ final class CategoryController extends BaseController
#[Route('/category/{category}', name: 'app_category')]
public function __invoke(string $category): Response
{
$products = Product::with('price')
if($this->cache->getItem('list_category_'.$category)->isHit()) {
return $this->render('productList.html.twig', ['listType' => 'category_'.$category]);
}
$products = Product::with(['price', 'lowestPrice'])
->selectRaw('products.*')
->distinct('products.id')
->fromRaw('products, json_each(products.categories)')
@@ -19,6 +23,7 @@ final class CategoryController extends BaseController
->orderByDesc('starred')
->orderByDesc('created_by')
->get();
return $this->render('productList.html.twig', ['products' => $products]);
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_'.$category]);
}
}

View File

@@ -13,12 +13,15 @@ final class DiscontinuedController extends BaseController
#[Route('/discontinued', name: 'app_discontinued')]
public function __invoke(): Response
{
if($this->cache->getItem('list_discontinued')->isHit()) {
return $this->render('productList.html.twig', ['listType' => 'discontinued']);
}
$products = Product::where('updated_at', '<', now()->format('Y-m-d'))
->orderByDesc('starred')
->orderByDesc('created_by')
->with(['currentPrice'])
->with(['currentPrice', 'lowestPrice'])
->get();
return $this->render('productList.html.twig', ['products' => $products]);
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'discontinued']);
}
}

View File

@@ -3,17 +3,22 @@
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class IndexController extends BaseController
{
#[Route('/', name: 'app_home')]
public function __invoke(Request $request): Response
public function __invoke(): Response
{
$products = Product::with(['currentStock', 'price', 'currentPrice']);
$products = $this->handleOrderProducts($products, $request)->get();
return $this->render('productList.html.twig', ['products' => $products]);
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();
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'all']);
}
}

View File

@@ -14,12 +14,15 @@ final class NewController extends BaseController
#[Route('/new', name: 'app_new')]
public function __invoke(): Response
{
if($this->cache->getItem('list_new')->isHit()) {
return $this->render('productList.html.twig', ['listType' => 'new']);
}
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
->orderByDesc('starred')
->orderByDesc('name')
->orderByDesc('created_by')
->with(['currentPrice'])
->with(['currentPrice', 'lowestPrice'])
->get();
return $this->render('productList.html.twig', ['products' => $products]);
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
}
}

View File

@@ -3,6 +3,7 @@
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;
@@ -19,6 +20,10 @@ final class ProductController extends BaseController
#[Route('/product/{productId<\d+>}', name: 'app_product')]
public function __invoke(int $productId): Response
{
if($this->cache->getItem('product'.$productId)->isHit()) {
return $this->render('product.html.twig', ['product' => ['id' => $productId]]);
}
$product = Product::with([
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),

View File

@@ -12,11 +12,15 @@ final class PromosController extends BaseController
#[Route('/promos', name: 'app_promos')]
public function __invoke(): Response
{
if($this->cache->getItem('list_promos')->isHit()) {
return $this->render('productList.html.twig', ['listType' => 'promos']);
}
$products = Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))
->orderByDesc('starred')
->orderByDesc('created_by')
->with(['currentPrice'])
->with(['currentPrice', 'lowestPrice'])
->get();
return $this->render('productList.html.twig', ['products' => $products]);
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos']);
}
}

View File

@@ -17,6 +17,6 @@ final class SearchController extends BaseController
->orWhere([['name', 'like', "%$search%"]])
->orWhere([['subTitle', 'like', "%$search%"]])->get();
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search]);
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search, 'listType' => 'search_'.$search]);
}
}

14
src/DatabaseFactory.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace Krzysiej\RyobiCrawler;
use Illuminate\Database\Capsule\Manager as Capsule;
class DatabaseFactory
{
public static function create(Capsule $capsule): void
{
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../database.sqlite']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
}

53
src/Kernel.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace Krzysiej\RyobiCrawler;
use Illuminate\Database\Capsule\Manager;
use Krzysiej\RyobiCrawler\Twig\AppExtension;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Twig\Extra\Cache\CacheExtension;
use Twig\Extra\Cache\CacheRuntime;
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
new TwigBundle(),
new TwigExtraBundle(),
];
}
protected function configureContainer(ContainerConfigurator $container): void
{
$container->extension('framework', [
'secret' => 'S0ME_SECRET'
]);
$services = $container->services()->defaults()->autowire()->autoconfigure();
$services->set(Manager::class)->configurator([DatabaseFactory::class, 'create']);
$services->load('Krzysiej\\RyobiCrawler\\', __DIR__ )
->exclude('../src/{Models,Twig,DatabaseFactory.php,Kernel.php}');
$services->set('twig.extension.cache', AppExtension::class)->tag('twig.extension');
$services->set(CacheExtension::class)->tag('twig.extension');
$services->set(FilesystemAdapter::class)->args([
'$directory' => __DIR__ . '/../var/cache/twig_blocks'
]);
$services->set('twig.runtime.cache', CacheRuntime::class)->args([new Reference(FilesystemAdapter::class)])->tag('twig.runtime');
}
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import(__DIR__ . '/Controller/', 'attribute');
}
}

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);

View File

@@ -19,6 +19,7 @@ class AppExtension extends AbstractExtension
{
return [
new TwigFunction('promosCount', [$this, 'promosCount']),
new TwigFunction('allCount', [$this, 'allCount']),
new TwigFunction('newCount', [$this, 'newCount']),
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
];
@@ -30,10 +31,14 @@ class AppExtension extends AbstractExtension
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
];
}
public function allCount(): int
{
return Product::count();
}
public function promosCount(): int
{
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count();
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->count();
}
public function newCount(): int

View File

@@ -1,6 +1,7 @@
{% extends "template.html.twig" %}
{% block content %}
{% cache 'product' ~ product.id %}
<div class="table-responsive">
<table class='table table-hover'>
<tr>
@@ -129,5 +130,6 @@
}
});
</script>
{% endcache %}
{% endblock %}

View File

@@ -1,22 +1,24 @@
{% extends "template.html.twig" %}
{% block content %}
{% cache 'list_' ~ listType %}
<div class="table-responsive">
{{ app.request.get('order') }}
<table class='table table-hover'>
<thead>
<tr>
<th></th>
<th></th>
<th><a href="{{ path( app.request.get('_route') , {'order': app.request.get('order') is same as('-name')?'name':'-name'|default('-name')}) }}">Name</a></th>
<th>Categories</th>
<th></th>
<th><a href="{{ path( app.request.get('_route') , {'order': app.request.get('order') is same as('-price')?'price':'-price'|default('-price')}) }}">Price</a></th>
<th></th>
</tr>
</thead>
{# <table class='table table-hover'>#}
{# <thead>#}
{# <tr>#}
{# <th></th>#}
{# <th></th>#}
{# <th>Name</th>#}
{# <th>Categories</th>#}
{# <th></th>#}
{# <th class="text-end">Lowest Price</th>#}
{# <th class="text-end">Current Price</th>#}
{# <th></th>#}
{# </tr>#}
{# </thead>#}
{% for product in products %}
<tr>
<div class="d-inline-flex">
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred == true %}{% else %}{% endif %}</a></td>
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
@@ -37,7 +39,7 @@
</td>
<td class="align-middle">
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
<ol class="breadcrumb">
<ol class="breadcrumb mb-0">
{% for category in product.categories %}
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
{% endfor %}
@@ -45,17 +47,19 @@
</nav>
</td>
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
<td class="align-middle">{{ product.price.last.price | format_currency('PLN', {}, 'pl') }}</td>
<td class="align-middle text-end">{% if product.lowestPrice.price != product.price.last.price %}{{ product.lowestPrice.price | format_currency('PLN', {}, 'pl') }}{% endif %}</td>
<td class="align-middle text-end">{{ product.price.last.price | format_currency('PLN', {}, 'pl') }}</td>
<td class="align-middle">
<div class="d-flex flex-row">
{% if product.price.last.price != product.price.last.productStandardPrice %}<span
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span>&nbsp;<span
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span> <span
class="badge text-bg-success flex-fill">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>
{% endif %}
</div>
</td>
</tr>
</div>
{% endfor %}
</table>
{# </table>#}
</div>
{% endcache %}
{% endblock %}

View File

@@ -18,15 +18,20 @@
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_promos') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_new') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_new') }}">New in last 30 days <span class="badge text-bg-secondary">{{ newCount() }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_discontinued') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_discontinued') }}">Discontinued <span class="badge text-bg-secondary">{{ discontinuedCount() }}</span></a>
</li>
{% cache "menu_count" %}
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_home') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_home') }}">All products <span class="badge text-bg-secondary">{{ allCount() }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_promos') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_new') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_new') }}">New in last 30 days <span class="badge text-bg-secondary">{{ newCount() }}</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if app.request.pathinfo == path('app_discontinued') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_discontinued') }}">Discontinued <span class="badge text-bg-secondary">{{ discontinuedCount() }}</span></a>
</li>
{% endcache %}
</ul>
<form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">