Compare commits
51 Commits
54488f0b19
...
feature/fl
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fbd555bb3 | |||
| de4915972c | |||
| 9c2405dd3f | |||
| da6a8f86c2 | |||
| 2c40fb0e61 | |||
| 5314a6a70a | |||
|
|
f772532309 | ||
|
|
17159e811f | ||
|
|
76d8b7d9cf | ||
|
|
f30304cbe9 | ||
| dc287aadc6 | |||
| 708a5eeae0 | |||
|
|
7352eea270 | ||
|
|
e97d976705 | ||
| beb717f9b9 | |||
| 2471a61076 | |||
|
|
a01174b414 | ||
| 512de51d08 | |||
|
|
e6e8f2fc15 | ||
| 6246ad8692 | |||
|
|
d18abc6159 | ||
| 5832ac583f | |||
|
|
8f87a6bbf0 | ||
| ef1b7b8a9e | |||
| b0134accfa | |||
|
|
ae0f9b3be7 | ||
|
|
5c2777999a | ||
|
|
71279025ae | ||
| f334ba0232 | |||
|
|
81f9c863c7 | ||
| 7eb7bf3eb2 | |||
|
|
ac1f0af5ae | ||
| 35aea9dd7e | |||
|
|
62239bd052 | ||
| 22e59a2438 | |||
|
|
585f1336d2 | ||
| a26ad401df | |||
|
|
3705990be1 | ||
| c65f0fdb3e | |||
| d6bcffc3e1 | |||
| faf9c8a480 | |||
| 14104f61a4 | |||
| 44254ed12a | |||
|
|
d9740a86d0 | ||
|
|
bd62a23854 | ||
| 2dc4dc778d | |||
|
|
85e32554ef | ||
| ebd48cfbf6 | |||
|
|
369bacc38c | ||
| 277257fda2 | |||
|
|
0e5d76313f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
/vendor/
|
/vendor/
|
||||||
.idea
|
.idea
|
||||||
database.sqlite
|
*.sqlite
|
||||||
var/cache/
|
var/cache/
|
||||||
.env.local
|
.env.local
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
FROM php:8.3-cli
|
FROM php:8.3-cli
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
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 \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
unzip \
|
unzip \
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
1. Clone repository using `git clone https://git.techtube.pl/krzysiej/ryobi-crawler.git`
|
1. Clone repository using `git clone https://git.techtube.pl/krzysiej/ryobi-crawler.git`
|
||||||
2. Cd into project directory `cd ryobi-crawler`
|
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.
|
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.
|
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.
|
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`
|
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`
|
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
|
## Running Cron
|
||||||
|
|
||||||
For now only way of running `app:scrape` command on schedule is to use host crontab.
|
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`
|
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.
|
3. Save and exit file editor. Cron will execute `app:scrape` once per day.
|
||||||
|
|
||||||
|
|||||||
2
bin/cacheclean
Executable file
2
bin/cacheclean
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
bin/cli rm -rf var/cache
|
||||||
2
bin/cachewarmup
Executable file
2
bin/cachewarmup
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
bin/cli php console.php app:cache:warm-twig
|
||||||
3
bin/cli
Executable file
3
bin/cli
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
|
||||||
|
docker compose exec php-app "$@"
|
||||||
3
bin/composer
Executable file
3
bin/composer
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
[ -z "$1" ] && bin/cli composer list && exit
|
||||||
|
bin/cli composer "$@"
|
||||||
5
bin/update
Executable file
5
bin/update
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
echo "Updating project"
|
||||||
|
git pull origin master
|
||||||
|
bin/cli rm -rf var/cache
|
||||||
|
echo "Project updated"
|
||||||
@@ -11,7 +11,9 @@
|
|||||||
"symfony/twig-bundle": "^7.1",
|
"symfony/twig-bundle": "^7.1",
|
||||||
"symfony/dotenv": "^7.1",
|
"symfony/dotenv": "^7.1",
|
||||||
"twig/intl-extra": "^3.13",
|
"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": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
1474
composer.lock
generated
1474
composer.lock
generated
File diff suppressed because it is too large
Load Diff
14
console.php
14
console.php
@@ -2,18 +2,16 @@
|
|||||||
|
|
||||||
include_once 'vendor/autoload.php';
|
include_once 'vendor/autoload.php';
|
||||||
|
|
||||||
use Krzysiej\RyobiCrawler\Command\Migrate;
|
use Krzysiej\RyobiCrawler\Kernel;
|
||||||
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
|
|
||||||
use Symfony\Component\Console\Application;
|
|
||||||
|
|
||||||
if (php_sapi_name() !== 'cli') {
|
if (php_sapi_name() !== 'cli') {
|
||||||
header('Location: browser.php');
|
header('Location: browser.php');
|
||||||
echo 'Execute this script in cli only';
|
echo 'Execute this script in cli only';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
$kernel = new Kernel('dev', true);
|
||||||
$application = new Application('Ryobi website scraper application', '1.1.1');
|
$application = new Application($kernel);
|
||||||
$application->add(new ScrapeWebsite());
|
$application->setName('Ryobi website scraper application');
|
||||||
$application->add(new Migrate());
|
$application->setVersion('1.2.0');
|
||||||
$application->run();
|
$application->run();
|
||||||
|
|||||||
37
index.php
37
index.php
@@ -1,46 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
use Krzysiej\RyobiCrawler\Kernel;
|
||||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
|
||||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
|
||||||
use Symfony\Component\Dotenv\Dotenv;
|
use Symfony\Component\Dotenv\Dotenv;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
|
||||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
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');
|
(new Dotenv())->bootEnv(__DIR__.'/.env');
|
||||||
|
|
||||||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
|
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
|
||||||
|
|||||||
BIN
screenshot1.png
BIN
screenshot1.png
Binary file not shown.
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 199 KiB |
84
src/Command/CacheWarmCommand.php
Normal file
84
src/Command/CacheWarmCommand.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,15 +21,13 @@ class ScrapeWebsite extends Command
|
|||||||
{
|
{
|
||||||
private Client $client;
|
private Client $client;
|
||||||
|
|
||||||
|
public function __construct(protected Capsule $database)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$capsule = new Capsule;
|
|
||||||
$capsule->addConnection([
|
|
||||||
'driver' => 'sqlite',
|
|
||||||
'database' => __DIR__ . '/../../database.sqlite',
|
|
||||||
]);
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
$this->client = new Client();
|
$this->client = new Client();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +38,6 @@ class ScrapeWebsite extends Command
|
|||||||
$products = $this->getProducts();
|
$products = $this->getProducts();
|
||||||
$progress->setMaxSteps(count($products));
|
$progress->setMaxSteps(count($products));
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
//dd($product);
|
|
||||||
$this->saveProduct($product);
|
$this->saveProduct($product);
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
}
|
}
|
||||||
@@ -91,6 +88,7 @@ class ScrapeWebsite extends Command
|
|||||||
$productModel->variantCode = $product->variantCode;
|
$productModel->variantCode = $product->variantCode;
|
||||||
$productModel->modelCode = $product->modelCode;
|
$productModel->modelCode = $product->modelCode;
|
||||||
$productModel->url = $product->url;
|
$productModel->url = $product->url;
|
||||||
|
$productModel->touch('updated_at');
|
||||||
$productModel->save();
|
$productModel->save();
|
||||||
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
|
||||||
@@ -10,11 +11,7 @@ class BaseController extends AbstractController
|
|||||||
{
|
{
|
||||||
protected Environment $twig;
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,19 @@ final class CategoryController extends BaseController
|
|||||||
#[Route('/category/{category}', name: 'app_category')]
|
#[Route('/category/{category}', name: 'app_category')]
|
||||||
public function __invoke(string $category): Response
|
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.*')
|
->selectRaw('products.*')
|
||||||
|
->distinct('products.id')
|
||||||
->fromRaw('products, json_each(products.categories)')
|
->fromRaw('products, json_each(products.categories)')
|
||||||
->whereRaw('json_each.value = ?', [$category])
|
->whereRaw('json_each.value = ?', [$category])
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->get();
|
->get();
|
||||||
return $this->render('productList.html.twig', ['products' => $products]);
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_'.$category]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/Controller/DiscontinuedController.php
Normal file
27
src/Controller/DiscontinuedController.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
|
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', 'lowestPrice'])
|
||||||
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'discontinued']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,10 +11,14 @@ final class IndexController extends BaseController
|
|||||||
#[Route('/', name: 'app_home')]
|
#[Route('/', name: 'app_home')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
$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('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->get();
|
->get();
|
||||||
return $this->render('productList.html.twig', ['products' => $products]);
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'all']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/Controller/NewController.php
Normal file
28
src/Controller/NewController.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
|
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('created_by')
|
||||||
|
->with(['currentPrice', 'lowestPrice'])
|
||||||
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
@@ -19,6 +20,10 @@ final class ProductController extends BaseController
|
|||||||
#[Route('/product/{productId<\d+>}', name: 'app_product')]
|
#[Route('/product/{productId<\d+>}', name: 'app_product')]
|
||||||
public function __invoke(int $productId): Response
|
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([
|
$product = Product::with([
|
||||||
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||||
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||||
@@ -26,9 +31,26 @@ final class ProductController extends BaseController
|
|||||||
if (null === $product) {
|
if (null === $product) {
|
||||||
throw $this->createNotFoundException('Product not found');
|
throw $this->createNotFoundException('Product not found');
|
||||||
}
|
}
|
||||||
|
$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();
|
||||||
|
|
||||||
$priceList = $product->price()->pluck('price')->implode(',');
|
return $this->render('product.html.twig', [
|
||||||
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->implode("','");
|
'product' => $product,
|
||||||
return $this->render('product.html.twig', ['product' => $product, 'price_list' => $priceList, 'price_dates' => $priceDates]);
|
'price_list' => $this->prepareChartData($priceDates, $priceList),
|
||||||
|
'stock_list' => $this->prepareChartData($stockDates, $stockList),
|
||||||
|
'price_dates' => implode("','", $priceDates),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,15 @@ final class PromosController extends BaseController
|
|||||||
#[Route('/promos', name: 'app_promos')]
|
#[Route('/promos', name: 'app_promos')]
|
||||||
public function __invoke(): Response
|
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'))
|
$products = Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->with(['currentPrice'])
|
->with(['currentPrice', 'lowestPrice'])
|
||||||
->get();
|
->get();
|
||||||
return $this->render('productList.html.twig', ['products' => $products]);
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ final class SearchController extends BaseController
|
|||||||
public function __invoke(Request $request): Response
|
public function __invoke(Request $request): Response
|
||||||
{
|
{
|
||||||
$search = $request->query->get('search');
|
$search = $request->query->get('search');
|
||||||
//dd();
|
|
||||||
$products = Product::with('price')
|
$products = Product::with('price')
|
||||||
->orWhere([['name', 'like', "%$search%"]])
|
->orWhere([['name', 'like', "%$search%"]])
|
||||||
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
->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
14
src/DatabaseFactory.php
Normal 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
53
src/Kernel.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property integer $skuID
|
* @property integer $skuID
|
||||||
* @property string $name
|
* @property string $name
|
||||||
@@ -39,6 +41,11 @@ class Product extends Model
|
|||||||
return $this->hasOne(Price::class)->latestOfMany('created_at');
|
return $this->hasOne(Price::class)->latestOfMany('created_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function lowestPrice(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
|
||||||
|
}
|
||||||
|
|
||||||
public function stock(): HasMany
|
public function stock(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Stock::class);
|
return $this->hasMany(Stock::class);
|
||||||
@@ -65,4 +72,13 @@ class Product extends Model
|
|||||||
set: fn(array $value) => json_encode($value),
|
set: fn(array $value) => json_encode($value),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDiscontinued(): bool
|
||||||
|
{
|
||||||
|
return $this->updated_at->format('Y-m-d') < now()->format('Y-m-d');
|
||||||
|
}
|
||||||
|
public function isNew(): bool
|
||||||
|
{
|
||||||
|
return $this->created_at->format('Y-m-d') > now()->modify('-30 days')->format('Y-m-d');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,17 @@ use Twig\Extension\AbstractExtension;
|
|||||||
use Twig\TwigFilter;
|
use Twig\TwigFilter;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
class AppExtension extends AbstractExtension
|
class AppExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
public function getFunctions(): array
|
public function getFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFunction('promosCount', [$this, 'promosCount']),
|
new TwigFunction('promosCount', [$this, 'promosCount']),
|
||||||
|
new TwigFunction('allCount', [$this, 'allCount']),
|
||||||
|
new TwigFunction('newCount', [$this, 'newCount']),
|
||||||
|
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,10 +31,24 @@ class AppExtension extends AbstractExtension
|
|||||||
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
|
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
public function allCount(): int
|
||||||
|
{
|
||||||
|
return Product::count();
|
||||||
|
}
|
||||||
|
|
||||||
public function promosCount(): int
|
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
|
||||||
|
{
|
||||||
|
return Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function discontinuedCount(): int
|
||||||
|
{
|
||||||
|
return Product::where('updated_at', '<', now()->format('Y-m-d'))->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
||||||
|
|||||||
6
templates/css/bootstrap.min.css
vendored
Normal file
6
templates/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
4
templates/js/script.js
Normal file
4
templates/js/script.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
(function() {
|
||||||
|
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||||
|
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
|
||||||
|
})();
|
||||||
@@ -1,31 +1,38 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% cache 'product' ~ product.id %}
|
||||||
|
<div class="table-responsive">
|
||||||
<table class='table table-hover'>
|
<table class='table table-hover'>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
<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 %}★{% else %} ☆ {% endif %}</a></td>
|
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||||
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
||||||
<td><a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a></td>
|
|
||||||
<td>{{ product.subTitle }}</td>
|
|
||||||
<td>
|
<td>
|
||||||
<ul class='nav'>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
|
<ol class="breadcrumb">
|
||||||
{% for category in product.categories %}
|
{% for category in product.categories %}
|
||||||
<li class="nav-item"><a class="nav-link" href="{{ path('app_category', {'category': category}) }}"> {{ category }} </a></li>
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none"
|
||||||
|
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ol>
|
||||||
|
</nav>
|
||||||
</td>
|
</td>
|
||||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4">
|
<td colspan="5">
|
||||||
<div style="width: 800px;">
|
<div style="width: 800px;">
|
||||||
<canvas id="price"></canvas>
|
<canvas id="price"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4">
|
<td colspan="5">
|
||||||
<table class='table table-hover table-sm mb-0'>
|
<table class='table table-hover table-sm mb-0'>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -48,29 +55,36 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const ctx = document.getElementById('price');
|
const ctx = document.getElementById('price').getContext('2d');
|
||||||
|
|
||||||
new Chart(ctx, {
|
new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: ['{{ price_dates|raw }}'],
|
labels: ['{{ price_dates|raw }}'],
|
||||||
datasets: [{
|
datasets: [
|
||||||
|
{
|
||||||
label: 'Price (PLN)',
|
label: 'Price (PLN)',
|
||||||
data: [{{ price_list }}],
|
data: {{ price_list|raw }},
|
||||||
|
yAxisID: 'yPrice',
|
||||||
|
tension: 0.1,
|
||||||
borderWidth: 1
|
borderWidth: 1
|
||||||
}]
|
},
|
||||||
|
{
|
||||||
|
label: 'Stock (units)',
|
||||||
|
data: {{ stock_list|raw }},
|
||||||
|
yAxisID: 'yStock',
|
||||||
|
tension: 0.1,
|
||||||
|
borderWidth: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
|
responsive: true,
|
||||||
animation: false,
|
animation: false,
|
||||||
plugins: {
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'Price in time'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
title: {
|
title: {
|
||||||
@@ -78,16 +92,44 @@
|
|||||||
text: 'Date'
|
text: 'Date'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
y: {
|
yPrice: {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'left',
|
||||||
beginAtZero: true,
|
beginAtZero: true,
|
||||||
title: {
|
title: {
|
||||||
display: true,
|
display: true,
|
||||||
text: 'Price'
|
text: 'Price (PLN)'
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
drawOnChartArea: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
yStock: {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'right',
|
||||||
|
beginAtZero: true,
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Stock (units)'
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
drawOnChartArea: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
position: 'top'
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Price and Stock in time'
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
{% endcache %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<table class='table table-hover'>
|
{% cache 'list_' ~ listType %}
|
||||||
<thead>
|
<div class="table-responsive">
|
||||||
<tr>
|
{# <table class='table table-hover'>#}
|
||||||
<th></th>
|
{# <thead>#}
|
||||||
<th></th>
|
{# <tr>#}
|
||||||
<th>Name</th>
|
{# <th></th>#}
|
||||||
<th>Categories</th>
|
{# <th></th>#}
|
||||||
<th></th>
|
{# <th>Name</th>#}
|
||||||
<th>Price</th>
|
{# <th>Categories</th>#}
|
||||||
<th></th>
|
{# <th></th>#}
|
||||||
</tr>
|
{# <th class="text-end">Lowest Price</th>#}
|
||||||
</thead>
|
{# <th class="text-end">Current Price</th>#}
|
||||||
|
{# <th></th>#}
|
||||||
|
{# </tr>#}
|
||||||
|
{# </thead>#}
|
||||||
{% for product in products %}
|
{% 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"
|
<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>
|
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='border rounded p-1' alt='{{ product.name }}'/></td>
|
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
{% if product.currentStock.stock > 0 %}
|
{% if product.currentStock.stock > 0 %}
|
||||||
@@ -25,21 +29,37 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<span class="badge text-bg-warning">out of stock</span>
|
<span class="badge text-bg-warning">out of stock</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if product.isDiscontinued() %}
|
||||||
|
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" data-bs-title="Last update: {{ product.updated_at }}">is discontinued</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if product.isNew() %}
|
||||||
|
<span class="badge text-bg-success">is new</span>
|
||||||
|
{% endif %}
|
||||||
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<ul class='nav'>
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
||||||
|
<ol class="breadcrumb mb-0">
|
||||||
{% for category in product.categories %}
|
{% for category in product.categories %}
|
||||||
<li class="nav-item"><a class="nav-link" href="{{ path('app_category', {'category': category}) }}"> {{ category }} </a></li>
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ol>
|
||||||
|
</nav>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></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">{% if product.price.last.price != product.price.last.productStandardPrice %}<span
|
<td class="align-middle text-end">{{ product.price.last.price | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
class="badge text-bg-warning text-decoration-line-through">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span> <span
|
<td class="align-middle">
|
||||||
class="badge text-bg-success">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>{% else %}{% endif %}</td>
|
<div class="d-flex flex-row">
|
||||||
</tr>
|
{% 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> <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>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
{# </table>#}
|
||||||
|
</div>
|
||||||
|
{% endcache %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<title>Ryobi crawler</title>
|
<title>Ryobi crawler</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
|
<link href="/templates/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
crossorigin="anonymous"/>
|
<script src="/templates/js/script.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||||
@@ -18,13 +18,26 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
|
{% cache "menu_count" %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
|
<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>
|
||||||
|
<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>
|
</ul>
|
||||||
<form class="d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
|
||||||
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}" aria-label="Search">
|
<form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
||||||
|
<input class="form-control me-2 form-control-sm" type="search" id="floatingInputValue" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}">
|
||||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||||
|
<label for="floatingInputValue">Search term eg. 36v or RCS18X</label>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user