Compare commits
141
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e731516b9d | ||
|
|
028297a4fe | ||
|
|
c16ab192ed | ||
|
|
fc89944cf1 | ||
|
|
a3b36df64e | ||
|
|
ce1fa049d1 | ||
|
|
f01398603d | ||
|
|
8a520b11d6 | ||
|
|
7eb9d42f97 | ||
|
|
52c16470e6 | ||
|
|
ad0ef20fc2 | ||
|
|
e68389bccc | ||
|
|
e1dbdc539b | ||
|
|
f0f26ad64d | ||
|
|
c6c11d5f7f | ||
|
|
7373657d78 | ||
|
|
3431c0c131 | ||
|
|
a2109a601b | ||
|
|
fc63580305 | ||
|
|
695da689ac | ||
|
|
69dd3ce823 | ||
|
|
88daeef9ec | ||
|
|
b553c15578 | ||
|
|
7bb3320e51 | ||
|
|
befcef9e8d | ||
|
|
cba20f6a61 | ||
|
|
074de13175 | ||
|
|
7e2658b174 | ||
|
|
1303b4ad8a | ||
|
|
67019e3933 | ||
|
|
a545bfe2ab | ||
|
|
ddc4cf9997 | ||
|
|
6556ba0f88 | ||
|
|
6da4f4257e | ||
|
|
5696f23f3d | ||
|
|
9f368a266a | ||
|
|
62c6538b89 | ||
|
|
2d1861caba | ||
|
|
5b424a2345 | ||
|
|
710c31551e | ||
|
|
0042fda5cc | ||
|
|
646383fb6a | ||
|
|
f9c58edccd | ||
|
|
9ec3291a6a | ||
|
|
373fd1641b | ||
|
|
46065dae1a | ||
|
|
3bbf82f897 | ||
|
|
a388b53cff | ||
|
|
295a968581 | ||
|
|
ebe40785fa | ||
|
|
4cf1c2f90b | ||
|
|
e40391eb4c | ||
|
|
4095037b69 | ||
|
|
b7ebf7374a | ||
|
|
45343c9121 | ||
|
|
653f94f9c9 | ||
|
|
632f76aceb | ||
|
|
cbf143c7a0 | ||
|
|
7920172735 | ||
|
|
914310dab8 | ||
|
|
8e8ef8fe04 | ||
|
|
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 | ||
|
|
54488f0b19 | ||
|
|
a6b108cb74 | ||
|
|
0db4bacff4 | ||
|
|
37680b0c91 | ||
|
|
0e8c312f5e | ||
|
|
685bff3ffc | ||
|
|
11284e59ea | ||
|
|
50305d5b5d | ||
|
|
f963dcd4c8 | ||
|
|
48ee68f71a | ||
|
|
f1c0ec6b3a | ||
|
|
0168290340 | ||
|
|
f451bfca0e | ||
|
|
c280abe484 | ||
|
|
7053716924 | ||
|
|
a911d614e0 | ||
|
|
58562746a3 | ||
|
|
5ee1bba812 | ||
|
|
3d47726a81 | ||
|
|
fee7495cfe | ||
|
|
53b6d33ab9 | ||
|
|
3cc5d73758 | ||
|
|
d043e8efb1 | ||
|
|
2b595c1403 | ||
|
|
f2e6cba2f5 | ||
|
|
e13a0acce1 | ||
|
|
77732689d8 | ||
|
|
22cc3f699b | ||
|
|
a1b6d65137 | ||
|
|
7ee8df32f9 |
No files matched your search
@@ -0,0 +1,20 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
workflow_dispatch:
|
||||||
|
jobs:
|
||||||
|
test-job:
|
||||||
|
runs-on: server
|
||||||
|
steps:
|
||||||
|
- name: initial test
|
||||||
|
run: echo "test"
|
||||||
|
deploy-job:
|
||||||
|
runs-on: server
|
||||||
|
steps:
|
||||||
|
- name: get page
|
||||||
|
run: curl http://192.168.0.129:9001/update
|
||||||
|
- run: pwd
|
||||||
|
- run: cd ../ && pwd
|
||||||
|
- run: pwd
|
||||||
|
- run: cd /var/www/html/ryobi-crawler && bin/update
|
||||||
+3
-1
@@ -1,3 +1,5 @@
|
|||||||
/vendor/
|
/vendor/
|
||||||
.idea
|
.idea
|
||||||
database.sqlite
|
*.sqlite
|
||||||
|
var/cache/
|
||||||
|
.env.local
|
||||||
+5
-3
@@ -1,13 +1,15 @@
|
|||||||
FROM php:8.3-cli
|
FROM php:8.4-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 \
|
||||||
|
libicu-dev \
|
||||||
libzip-dev
|
libzip-dev
|
||||||
|
|
||||||
RUN docker-php-ext-install zip
|
RUN docker-php-ext-install zip intl
|
||||||
|
|
||||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,34 @@
|
|||||||
|
|
||||||
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 index.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 index.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:9000` address in web browser.
|
6. Access web interface using `localhost:9001` address in web browser.
|
||||||
|
|
||||||
|
|
||||||
|
## Update project
|
||||||
|
|
||||||
|
1. Cd into project directory
|
||||||
|
2. Run `git pull`
|
||||||
|
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 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.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
### Main screen of the web view
|
||||||
|

|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
echo "Cleaning cache"
|
||||||
|
bin/cli rm -rf var/cache
|
||||||
|
echo "cache cleaned2"
|
||||||
Executable
+2
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
bin/cli php console.php app:cache:warm-twig
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
|
||||||
|
docker compose exec php-app "$@"
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
[ -z "$1" ] && bin/cli composer list && exit
|
||||||
|
bin/cli composer "$@"
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
echo "Updating project"
|
||||||
|
git pull origin master
|
||||||
|
bin/cacheclean
|
||||||
|
bin/composer install --no-dev
|
||||||
|
echo "Project updated"
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
include_once 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
|
||||||
use Twig\{Environment, Loader\FilesystemLoader};
|
|
||||||
|
|
||||||
if (!file_exists('database.sqlite')) {
|
|
||||||
exit('Database file <code>database.sqlite</code> missing. Run docker compose <blockquote>docker compose exec php-app php index.php app:migrate</blockquote> to create it.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$capsule = new Capsule;
|
|
||||||
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/database.sqlite']);
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
$loader = new FilesystemLoader(__DIR__ . '/src/templates');
|
|
||||||
$twig = new Environment($loader);
|
|
||||||
if (isset($_GET['product_id'])) {
|
|
||||||
$template = 'product.html.twig';
|
|
||||||
$product = Product::with('price')->find($_GET['product_id']);
|
|
||||||
}
|
|
||||||
if (isset($_GET['category'])) {
|
|
||||||
$template = 'productList.html.twig';
|
|
||||||
$products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])
|
|
||||||
->orderByDesc('starred')->orderByDesc('created_by')->get();
|
|
||||||
}
|
|
||||||
if (isset($_GET['search'])) {
|
|
||||||
$template = 'productList.html.twig';
|
|
||||||
$products = Product::with('price')
|
|
||||||
->orWhere([['name', 'like', "%{$_GET['search']}%"]])
|
|
||||||
->orWhere([['subTitle', 'like', "%{$_GET['search']}%"]])->get();
|
|
||||||
}
|
|
||||||
if (isset($_GET['star'])) {
|
|
||||||
Product::find($_GET['star'])->toggleStarred()->save();
|
|
||||||
header('Location: '.$_SERVER['HTTP_REFERER']);
|
|
||||||
}
|
|
||||||
if (empty($_GET)) {
|
|
||||||
$template = 'productList.html.twig';
|
|
||||||
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get();
|
|
||||||
}
|
|
||||||
$twig->display($template, ['products' => $products ?? [], 'product' => $product ?? [], 'search' => $_GET['search'] ?? '']);
|
|
||||||
+17
-5
@@ -1,15 +1,27 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^7.0",
|
"guzzlehttp/guzzle": "^7",
|
||||||
"symfony/var-dumper": "^7.0",
|
|
||||||
"illuminate/database": "11.26.0.0",
|
"illuminate/database": "11.26.0.0",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"twig/twig": "3.14.0.0",
|
"symfony/console": "^8.0",
|
||||||
"symfony/console": "^7.0"
|
"symfony/routing": "^8.0",
|
||||||
|
"laravel/serializable-closure": "^1.3",
|
||||||
|
"symfony/http-kernel": "^8.0",
|
||||||
|
"symfony/framework-bundle": "^8.0",
|
||||||
|
"symfony/twig-bundle": "^8.0",
|
||||||
|
"symfony/dotenv": "^8.0",
|
||||||
|
"twig/intl-extra": "^3.13",
|
||||||
|
"twig/extra-bundle": "^3.13",
|
||||||
|
"symfony/cache": "^8.0",
|
||||||
|
"twig/cache-extra": "^3.21"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Krzysiej\\RyobiCrawler\\": "src/"
|
"Krzysiej\\RyobiCrawler\\": "src/"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/var-dumper": "^8.0"
|
||||||
|
},
|
||||||
|
"minimum-stability": "stable"
|
||||||
}
|
}
|
||||||
Generated
+2243
-318
File diff suppressed because it is too large.
Load diff
+17
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
$kernel = new Kernel('dev', true);
|
||||||
|
$application = new Application($kernel);
|
||||||
|
$application->setName('Ryobi website scraper application');
|
||||||
|
$application->setVersion('1.2.0');
|
||||||
|
$application->run();
|
||||||
+2
-1
@@ -1,9 +1,10 @@
|
|||||||
services:
|
services:
|
||||||
php-app:
|
php-app:
|
||||||
|
restart: unless-stopped
|
||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
- .:/usr/src/app
|
- .:/usr/src/app
|
||||||
command: >
|
command: >
|
||||||
sh -c "composer install && php -S 0.0.0.0:8000 -t /usr/src/app"
|
sh -c "composer install && php -S 0.0.0.0:8000 -t /usr/src/app"
|
||||||
ports:
|
ports:
|
||||||
- "9000:8000"
|
- "9001:8000"
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
include_once 'vendor/autoload.php';
|
use Krzysiej\RyobiCrawler\Kernel;
|
||||||
|
use Symfony\Component\Dotenv\Dotenv;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
use Krzysiej\RyobiCrawler\Command\Migrate;
|
require 'vendor/autoload.php';
|
||||||
use Krzysiej\RyobiCrawler\Command\ScrapeWebsite;
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Application;
|
(new Dotenv())->bootEnv(__DIR__.'/.env');
|
||||||
|
|
||||||
if (php_sapi_name() !== 'cli') {
|
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
|
||||||
header('Location: browser.php');
|
$request = Request::createFromGlobals();
|
||||||
echo 'Execute this script in cli only';
|
$response = $kernel->handle($request);
|
||||||
exit;
|
$response->send();
|
||||||
}
|
$kernel->terminate($request, $response);
|
||||||
|
|
||||||
$application = new Application('Ryobi website scraper application', '1.1.1');
|
|
||||||
$application->add(new ScrapeWebsite());
|
|
||||||
$application->add(new Migrate());
|
|
||||||
$application->run();
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 282 KiB |
+227
-6
@@ -6,17 +6,30 @@ namespace Krzysiej\RyobiCrawler\Command;
|
|||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Country;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
|
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
|
||||||
class Migrate extends Command
|
class Migrate extends Command
|
||||||
{
|
{
|
||||||
|
private const RECREATE_OPTION = 'recreate';
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
|
$this->addOption(self::RECREATE_OPTION, null, InputOption::VALUE_OPTIONAL, 'Recreate database file event if exist and has data.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
if ($input->getOption(self::RECREATE_OPTION)) {
|
||||||
|
unlink(__DIR__ . '/../../database.sqlite');
|
||||||
touch(__DIR__ . '/../../database.sqlite');
|
touch(__DIR__ . '/../../database.sqlite');
|
||||||
|
}
|
||||||
$capsule = new Capsule;
|
$capsule = new Capsule;
|
||||||
$capsule->addConnection([
|
$capsule->addConnection([
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
@@ -24,13 +37,12 @@ class Migrate extends Command
|
|||||||
]);
|
]);
|
||||||
$capsule->setAsGlobal();
|
$capsule->setAsGlobal();
|
||||||
$capsule->bootEloquent();
|
$capsule->bootEloquent();
|
||||||
}
|
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
|
||||||
{
|
|
||||||
$this->createProductsTable();
|
$this->createProductsTable();
|
||||||
$this->createPricesTable();
|
$this->createPricesTable();
|
||||||
$this->createStocksTable();
|
$this->createStocksTable();
|
||||||
|
$this->addColumns();
|
||||||
|
$this->createCountriesTable();
|
||||||
|
$this->index();
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -42,9 +54,7 @@ class Migrate extends Command
|
|||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->integer('skuID')->unique();
|
$table->integer('skuID')->unique();
|
||||||
$table->integer('agilityID');
|
|
||||||
$table->integer('availableQuantity');
|
$table->integer('availableQuantity');
|
||||||
$table->integer('stock');
|
|
||||||
$table->json('categories');
|
$table->json('categories');
|
||||||
$table->string('image');
|
$table->string('image');
|
||||||
$table->string('subTitle');
|
$table->string('subTitle');
|
||||||
@@ -71,6 +81,111 @@ class Migrate extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createCountriesTable(): void
|
||||||
|
{
|
||||||
|
if (!Capsule::schema()->hasTable('countries')) {
|
||||||
|
Capsule::schema()->create('countries', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->text('countryName');
|
||||||
|
$table->text('productsUrl');
|
||||||
|
$table->text('cultureCode');
|
||||||
|
$table->text('currency');
|
||||||
|
$table->text('locale');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Poland')->exists()) {
|
||||||
|
$id = Capsule::table('countries')->insertGetId(
|
||||||
|
[
|
||||||
|
'countryName' => 'Poland',
|
||||||
|
'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'pl-PL',
|
||||||
|
'currency' => 'PLN',
|
||||||
|
'locale' => 'pl',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'UK')->exists()) {
|
||||||
|
Capsule::table('countries')->insert([
|
||||||
|
'countryName' => 'UK',
|
||||||
|
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'en-GB',
|
||||||
|
'currency' => 'GBP',
|
||||||
|
'locale' => 'uk',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Netherlands')->exists()) {
|
||||||
|
Capsule::table('countries')->insert([
|
||||||
|
'countryName' => 'Netherlands',
|
||||||
|
'productsUrl' => 'https://nl.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'nl-NL',
|
||||||
|
'currency' => 'EUR',
|
||||||
|
'locale' => 'nl',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'France')->exists()) {
|
||||||
|
Capsule::table('countries')->insert([
|
||||||
|
'countryName' => 'France',
|
||||||
|
'productsUrl' => 'https://fr.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'fr-FR',
|
||||||
|
'currency' => 'EUR',
|
||||||
|
'locale' => 'fr',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Spain')->exists()) {
|
||||||
|
Capsule::table('countries')->insert([
|
||||||
|
'countryName' => 'Spain',
|
||||||
|
'productsUrl' => 'https://es.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'es-ES',
|
||||||
|
'currency' => 'EUR',
|
||||||
|
'locale' => 'es',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Poland')->exists()) {
|
||||||
|
$id = Capsule::table('countries')->insertGetId(
|
||||||
|
[
|
||||||
|
'countryName' => 'Poland',
|
||||||
|
'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'pl-PL',
|
||||||
|
'currency' => 'PLN',
|
||||||
|
'locale' => 'pl',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'UK')->exists()) {
|
||||||
|
Capsule::table('countries')->insert([
|
||||||
|
'countryName' => 'UK',
|
||||||
|
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
|
||||||
|
'cultureCode' => 'en-GB',
|
||||||
|
'currency' => 'GBP',
|
||||||
|
'locale' => 'uk',
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'country_id')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
|
||||||
|
$table->foreignId('country_id')->default($id)->references('id')->on('countries');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function createStocksTable(): void
|
public function createStocksTable(): void
|
||||||
{
|
{
|
||||||
if (!Capsule::schema()->hasTable('stocks')) {
|
if (!Capsule::schema()->hasTable('stocks')) {
|
||||||
@@ -88,4 +203,110 @@ class Migrate extends Command
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addColumns(): void
|
||||||
|
{
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'priceCurrent')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->float('priceCurrent')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'priceLowest')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->float('priceLowest')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'productStandardPrice')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->float('productStandardPrice')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'lowestProductPrice30Days')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->float('lowestProductPrice30Days')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'lastSeen')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->date('lastSeen')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'stock')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->integer('stock')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!Capsule::schema()->hasColumn('products', 'promotions')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->json('promotions')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(): void
|
||||||
|
{
|
||||||
|
if (!$this->hasIndex('products_skuid_country_id_unique')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
if ($this->hasIndex('products_skuid_unique')) {
|
||||||
|
$table->integer('skuID')->unique(false)->change();
|
||||||
|
}
|
||||||
|
$table->unique(['skuID', 'country_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->hasIndex('prices_product_id_index')) {
|
||||||
|
Capsule::schema()->table('prices', function (Blueprint $table) {
|
||||||
|
$table->index('product_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->hasIndex('products_id_index')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->index('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->hasIndex('stocks_product_id_stock_index')) {
|
||||||
|
Capsule::schema()->table('stocks', function (Blueprint $table) {
|
||||||
|
$table->index(['product_id', 'stock']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isFK('products', 'id', 'stocks', 'product_id')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->foreign('id')->references('product_id')->on('stocks');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isFK('products', 'id', 'prices', 'product_id')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->foreign('id')->references('product_id')->on('prices');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!$this->isFK('products', 'country_id', 'countries', 'id')) {
|
||||||
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
|
$table->foreign('country_id')->references('id')->on('countries');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isFK(string $table, string $column, string $fTable, string $fColumn): bool
|
||||||
|
{
|
||||||
|
$fkColumns = Capsule::schema()->getForeignKeys($table);
|
||||||
|
|
||||||
|
return !empty(array_filter($fkColumns, fn($fkColumn) => ($fkColumn['foreign_table'] == $fTable &&
|
||||||
|
in_array($fColumn, $fkColumn['foreign_columns']) &&
|
||||||
|
in_array($column, $fkColumn['columns']))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function hasIndex(string $indexName): bool
|
||||||
|
{
|
||||||
|
return !!count(Capsule::select('SELECT name FROM sqlite_master WHERE type = "index" and name = ?', [$indexName]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace Krzysiej\RyobiCrawler\Command;
|
|||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Country;
|
||||||
use Krzysiej\RyobiCrawler\Models\Price;
|
use Krzysiej\RyobiCrawler\Models\Price;
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
use Krzysiej\RyobiCrawler\Models\Stock;
|
use Krzysiej\RyobiCrawler\Models\Stock;
|
||||||
@@ -14,54 +15,85 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
#[AsCommand(name: 'app:scrape', description: 'Scrape all products from Ryobi website')]
|
#[AsCommand(name: 'app:scrape', description: 'Scrape all products from Ryobi website')]
|
||||||
class ScrapeWebsite extends Command
|
class ScrapeWebsite extends Command
|
||||||
{
|
{
|
||||||
|
const COUNTRY_ID = 'country';
|
||||||
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();
|
||||||
|
$this->addOption(self::COUNTRY_ID, 'c', InputOption::VALUE_OPTIONAL, 'Country id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
|
$countryId = intval($input->getOption(self::COUNTRY_ID));
|
||||||
|
$output->writeln('Scrape products');
|
||||||
|
$countries = Country::all()->when($countryId, fn ($query) => $query->where('id', $countryId));
|
||||||
|
foreach($countries as $country) {
|
||||||
|
$output->writeln('Country name: ' . $country->countryName);
|
||||||
|
$products = $this->getProducts($country);
|
||||||
$progress = new ProgressBar($output);
|
$progress = new ProgressBar($output);
|
||||||
$progress->start();
|
$progress->start();
|
||||||
$products = $this->getProducts();
|
|
||||||
$progress->setMaxSteps(count($products));
|
$progress->setMaxSteps(count($products));
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
$this->saveProduct($product);
|
$this->saveProduct($product, $country);
|
||||||
|
$progress->advance();
|
||||||
|
}
|
||||||
|
$progress->finish();
|
||||||
|
$output->writeln("\nScrape products - DONE\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln('Update prices');
|
||||||
|
$products = Product::all();
|
||||||
|
$progress = new ProgressBar($output);
|
||||||
|
$progress->setMaxSteps(count($products));
|
||||||
|
$progress->start();
|
||||||
|
foreach($products as $product) {
|
||||||
|
$newestPrice = $product->newestPrice;
|
||||||
|
$currentStock = $product->currentStock;
|
||||||
|
$product->priceCurrent = $newestPrice->price;
|
||||||
|
$product->productStandardPrice = $newestPrice->productStandardPrice;
|
||||||
|
$product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
|
||||||
|
$product->priceLowest = $product->lowestPrice->price;
|
||||||
|
$product->lastSeen = $newestPrice->created_at->format('Y-m-d');
|
||||||
|
$product->stock = $currentStock->stock;
|
||||||
|
$product->save(['timestamps' => false]);
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
}
|
}
|
||||||
$progress->finish();
|
$progress->finish();
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
$output->writeln('DONE');
|
$output->writeln('Update prices - DONE');
|
||||||
|
$output->writeln('COMMAND - DONE');
|
||||||
|
|
||||||
|
file_put_contents('templates/lastscrape.html.twig', date('Y-m-d H:i:s'));
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProducts(): array
|
private function getProducts(Country $country): array
|
||||||
{
|
{
|
||||||
$products = [];
|
$products = [];
|
||||||
$page = 0;
|
$page = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
$res = $this->client->request('POST', 'https://pl.ryobitools.eu/api/product-listing/get-products', [
|
$res = $this->client->request('POST', $country->productsUrl, [
|
||||||
'form_params' => [
|
'form_params' => [
|
||||||
"includePreviousPages" => false,
|
"includePreviousPages" => false,
|
||||||
"pageIndex" => $page,
|
"pageIndex" => $page,
|
||||||
"pageSize" => 100,
|
"pageSize" => 100,
|
||||||
"cultureCode" => "pl-PL",
|
"cultureCode" => $country->cultureCode,
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
$responseObject = json_decode($res->getBody()->getContents());
|
$responseObject = json_decode($res->getBody()->getContents());
|
||||||
@@ -76,23 +108,28 @@ class ScrapeWebsite extends Command
|
|||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function saveProduct(\stdClass $product): void
|
private function saveProduct(\stdClass $product, Country $country): void
|
||||||
{
|
{
|
||||||
/** @var Product $productModel */
|
/** @var Product $productModel */
|
||||||
$productModel = Product::firstOrNew(['skuID' => $product->skuID]);
|
$productModel = Product::firstOrNew(['skuID' => $product->skuID, 'country_id' => $country->id]);
|
||||||
|
|
||||||
$productModel->skuID = $product->skuID;
|
$productModel->skuID = $product->skuID;
|
||||||
$productModel->name = $product->name;
|
$productModel->name = $product->name;
|
||||||
$productModel->availableQuantity = $product->availableQuantity;
|
$productModel->availableQuantity = $product->availableQuantity;
|
||||||
$productModel->stock = $product->stock;
|
$productModel->categories = str_replace(['/', ' '], '', $product->categories);
|
||||||
$productModel->categories = json_encode($product->categories);
|
|
||||||
$productModel->image = $product->image;
|
$productModel->image = $product->image;
|
||||||
$productModel->subTitle = $product->subTitle;
|
$productModel->subTitle = $product->subTitle;
|
||||||
$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->lastSeen = date("Y-m-d");
|
||||||
|
$productModel->touch('updated_at');
|
||||||
|
$productModel->country()->associate($country);
|
||||||
|
$productModel->promotions = $product->promotions;
|
||||||
$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();
|
||||||
if (!$priceExists) {
|
|
||||||
|
if (false === $priceExists) {
|
||||||
$price = new Price();
|
$price = new Price();
|
||||||
$price->price = $product->productPrice;
|
$price->price = $product->productPrice;
|
||||||
$price->productStandardPrice = $product->productStandardPrice;
|
$price->productStandardPrice = $product->productStandardPrice;
|
||||||
@@ -100,7 +137,7 @@ class ScrapeWebsite extends Command
|
|||||||
$productModel->price()->save($price);
|
$productModel->price()->save($price);
|
||||||
}
|
}
|
||||||
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
$stockExist = $productModel->stock()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
||||||
if (!$stockExist) {
|
if (false === $stockExist) {
|
||||||
$stock = new Stock();
|
$stock = new Stock();
|
||||||
$stock->availableQuantity = $product->availableQuantity;
|
$stock->availableQuantity = $product->availableQuantity;
|
||||||
$stock->stock = $product->stock;
|
$stock->stock = $product->stock;
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
|
||||||
|
class BaseController extends AbstractController
|
||||||
|
{
|
||||||
|
protected Environment $twig;
|
||||||
|
|
||||||
|
public function __construct( protected Capsule $database)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
final class CategoryController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/category/{category?}', name: 'app_category')]
|
||||||
|
public function __invoke(?string $category): Response
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var Product[] $products */
|
||||||
|
$products = Product::with(['price', 'lowestPrice'])
|
||||||
|
->selectRaw('products.*')
|
||||||
|
->distinct('products.id')
|
||||||
|
->when(!is_null($category) , fn ($q) => $q->whereRaw('json_each.value = ?', [$category]))
|
||||||
|
->fromRaw('products, json_each(products.categories)')
|
||||||
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$categoriesTree = [];
|
||||||
|
|
||||||
|
foreach ($products as $product) {
|
||||||
|
$categoriesTree = $this->addToTree($product->categories, $categoriesTree);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_' . $category, 'category' => $category, 'categoryTree' => $categoriesTree]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addToTree(array $categories, mixed $categoriesTree)
|
||||||
|
{
|
||||||
|
$tmp = &$categoriesTree;
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
if (empty($tmp[$category])) {
|
||||||
|
$tmp[$category] = ['count' => 0];
|
||||||
|
}
|
||||||
|
$tmp = &$tmp[$category];
|
||||||
|
$tmp['count']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $categoriesTree;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?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
|
||||||
|
{
|
||||||
|
|
||||||
|
$products = Product::where('lastSeen', '<', now()->format('Y-m-d'))
|
||||||
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'discontinued']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
final class IndexController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/', name: 'app_home')]
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
$products = Product::orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'all']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?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 LowestPriceController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/lowest-price', name: 'app_lowest_price', methods: ['GET'])]
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
$listType = 'lowest_price';
|
||||||
|
|
||||||
|
$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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?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 NewController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/new', name: 'app_new')]
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
$date = now()->modify('-30 days')->format('Y-m-d');
|
||||||
|
$products = Product::where('created_at', '>', $date)
|
||||||
|
->with(['country', 'stock'])
|
||||||
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Error\RuntimeError;
|
||||||
|
use Twig\Error\SyntaxError;
|
||||||
|
|
||||||
|
final class ProductController extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws SyntaxError
|
||||||
|
* @throws RuntimeError
|
||||||
|
* @throws LoaderError
|
||||||
|
*/
|
||||||
|
#[Route('/product/{productId<\d+>}', name: 'app_product')]
|
||||||
|
public function __invoke(int $productId): Response
|
||||||
|
{
|
||||||
|
$product = Product::with([
|
||||||
|
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||||
|
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||||
|
])->find($productId);
|
||||||
|
if (null === $product) {
|
||||||
|
throw $this->createNotFoundException('Product not found');
|
||||||
|
}
|
||||||
|
$priceList = $product->price()->pluck('price', 'created_at')->mapWithKeys(fn($price, $createdAt) => [explode(' ', $createdAt)[0] => $price])->toArray();
|
||||||
|
$stockList = $product->stock()->pluck('stock', 'created_at')->mapWithKeys(fn($stock, $createdAt) => [explode(' ', $createdAt)[0] => $stock])->toArray();
|
||||||
|
|
||||||
|
ksort($stockList);
|
||||||
|
ksort($priceList);
|
||||||
|
|
||||||
|
return $this->render('product.html.twig', [
|
||||||
|
'product' => $product,
|
||||||
|
'price_list' => $this->prepareChartData($priceList),
|
||||||
|
'stock_list' => $this->prepareChartData($stockList),
|
||||||
|
'price_dates' => implode("','", $this->dateRange(array_key_first($priceList), array_key_last($priceList))),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepareChartData($set1): string
|
||||||
|
{
|
||||||
|
$dates = $this->dateRange(array_key_first($set1), array_key_last($set1));
|
||||||
|
$data = array_map(fn($date) => ['x' => $date, 'y' => $set1[$date] ?? null], $dates);
|
||||||
|
$stringData = json_encode($data);
|
||||||
|
|
||||||
|
return str_replace(['"x"', '"y"'], ['x', 'y'], $stringData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function dateRange($dateStart, $dateEnd): array
|
||||||
|
{
|
||||||
|
$from = new \DateTime($dateStart);
|
||||||
|
$to = new \DateTime($dateEnd);
|
||||||
|
$range = [];
|
||||||
|
for ($date = clone $from; $date < $to; $date->modify('+1 day')) {
|
||||||
|
$range[] = $date->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $range;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
final class PromosController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/promos/{promo?}', name: 'app_promos')]
|
||||||
|
public function __invoke(?string $promo): Response
|
||||||
|
{
|
||||||
|
$products = Product::when(is_null($promo), fn($q) => $q->whereRaw('priceCurrent < productStandardPrice'))
|
||||||
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->with(['currentPrice', 'lowestPrice'])
|
||||||
|
->when(!is_null($promo), fn($q) => $q->whereRaw("json_extract(promotions, '$.slug') LIKE ?", $promo))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
|
||||||
|
$promos = Product::select($this->database->getConnection()->raw("distinct json_extract(promotions, '$.slug') as slug, json_extract(promotions, '$.tag') as tag"))
|
||||||
|
->addSelect('countries.locale')
|
||||||
|
->whereRaw("json_extract(promotions, '$.tag') is not null")
|
||||||
|
->join('countries', 'products.country_id', '=', 'countries.id')
|
||||||
|
->get()
|
||||||
|
->groupBy('locale');
|
||||||
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos' . $promo, 'promos' => $promos->toArray()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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 SearchController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/search', name: 'app_search')]
|
||||||
|
public function __invoke(Request $request): Response
|
||||||
|
{
|
||||||
|
$search = $request->query->get('search');
|
||||||
|
$products = Product::with('price')
|
||||||
|
->orWhere([['name', 'like', "%$search%"]])
|
||||||
|
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
||||||
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search, 'listType' => 'search_'.$search]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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 StarController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/star/{productId<\d+>}', name: 'app_star')]
|
||||||
|
public function __invoke(int $productId, Request $request): Response
|
||||||
|
{
|
||||||
|
$referer = $request->headers->get('referer');
|
||||||
|
if (str_contains($referer, '/category/')) {
|
||||||
|
preg_match('#/category/(.*)#i', $referer, $matches);
|
||||||
|
}
|
||||||
|
if (str_contains($referer, '/search?search=')) {
|
||||||
|
preg_match('#/search\?search=(.*)#i', $referer, $matches);
|
||||||
|
}
|
||||||
|
|
||||||
|
Product::find($productId)->toggleStarred()->save();
|
||||||
|
return $this->redirect($referer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
final class UpdateController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/update', name: 'app_update')]
|
||||||
|
public function __invoke(Request $request): Response
|
||||||
|
{
|
||||||
|
$output = shell_exec('bin/update');
|
||||||
|
|
||||||
|
return new Response($output);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?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\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||||
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||||
|
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||||
|
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', AppExtension::class)->tag('twig.extension');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configureRoutes(RoutingConfigurator $routes): void
|
||||||
|
{
|
||||||
|
$routes->import(__DIR__ . '/Controller/', 'attribute');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $countryName
|
||||||
|
* @property string $productsUrl
|
||||||
|
* @property string $cultureCode
|
||||||
|
* @property string $currency
|
||||||
|
* @property string $locale
|
||||||
|
*/
|
||||||
|
class Country extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
public function products(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Product::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
+71
-5
@@ -2,48 +2,114 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler\Models;
|
namespace Krzysiej\RyobiCrawler\Models;
|
||||||
|
|
||||||
|
use Carbon\Traits\Date;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property integer $skuID
|
* @property integer $skuID
|
||||||
* @property integer $agilityID
|
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property integer $availableQuantity
|
* @property integer $availableQuantity
|
||||||
* @property integer $stock
|
|
||||||
* @property string[] $categories
|
* @property string[] $categories
|
||||||
* @property string $image
|
* @property string $image
|
||||||
* @property string $subTitle
|
* @property string $subTitle
|
||||||
* @property string $variantCode
|
* @property string $variantCode
|
||||||
* @property string $modelCode
|
* @property string $modelCode
|
||||||
* @property string $url
|
* @property string $url
|
||||||
* @property boolean $starred
|
* @property int $starred
|
||||||
|
* @property float $priceCurrent
|
||||||
|
* @property float $priceLowest
|
||||||
|
* @property float $productStandardPrice
|
||||||
|
* @property float $lowestProductPrice30Days
|
||||||
|
* @property Date $lastSeen
|
||||||
|
* @property integer $stock
|
||||||
|
* @property Object $promotions
|
||||||
*/
|
*/
|
||||||
class Product extends Model
|
class Product extends Model
|
||||||
{
|
{
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
public $fillable = ['skuID'];
|
public $fillable = ['skuID', 'country_id'];
|
||||||
|
|
||||||
|
public function country(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Country::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function price(): HasMany
|
public function price(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Price::class);
|
return $this->hasMany(Price::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isStarred(): bool
|
||||||
|
{
|
||||||
|
return (bool)$this->starred;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function currentPrice(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Price::class)->latestOfMany('created_at');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lowestPrice(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newestPrice(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Price::class)->latest()->take(1);
|
||||||
|
}
|
||||||
|
|
||||||
public function stock(): HasMany
|
public function stock(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Stock::class);
|
return $this->hasMany(Stock::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function currentStock(): HasOne
|
||||||
|
{
|
||||||
|
return $this->stock()->one()->ofMany()->withDefault(fn(Stock $stock) => $stock->stock = 0)->take(1);
|
||||||
|
}
|
||||||
|
|
||||||
public function toggleStarred(): self
|
public function toggleStarred(): self
|
||||||
{
|
{
|
||||||
$this->starred = !$this->starred;
|
$this->starred = !$this->starred;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function categories(): Attribute
|
public function categories(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn(string $value) => array_reverse(json_decode($value, 1)),
|
get: fn(string $value) => array_reverse(json_decode($value, 1)),
|
||||||
|
set: fn(array $value) => json_encode($value),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function promotions(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn(?string $value) => json_decode($value ?? '{"hasPromotion": false}', 1),
|
||||||
|
set: function (\stdClass $value) {
|
||||||
|
$value->slug = Str::slug($value->tag);
|
||||||
|
|
||||||
|
return json_encode($value);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDiscontinued(): bool
|
||||||
|
{
|
||||||
|
return $this->lastSeen < 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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Twig;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Price;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Stock;
|
||||||
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
|
class AppExtension extends AbstractExtension
|
||||||
|
{
|
||||||
|
public function __construct(public RouterInterface $route)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFunctions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFunction('promosCount', [$this, 'promosCount']),
|
||||||
|
new TwigFunction('allCount', [$this, 'allCount']),
|
||||||
|
new TwigFunction('newCount', [$this, 'newCount']),
|
||||||
|
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||||
|
new TwigFunction('lowestPriceCount', [$this, 'lowestPriceCount']),
|
||||||
|
new TwigFunction('renderCategoryTree', [$this, 'renderCategoryTree']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilters(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function allCount(): int
|
||||||
|
{
|
||||||
|
return Product::count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function promosCount(): int
|
||||||
|
{
|
||||||
|
return Product::whereRaw('priceCurrent < 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('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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderCategoryTree($categories, $current, $level = 0): string
|
||||||
|
{
|
||||||
|
$tree = '';
|
||||||
|
if ($level == 0) {
|
||||||
|
$tree .= '<ul class="list-group list-group-flush">';
|
||||||
|
}
|
||||||
|
foreach ($categories as $categoryName => $category) {
|
||||||
|
$currentClass = $categoryName == $current ? 'list-group-item-primary' : '';
|
||||||
|
$tree .= '<a class="list-group-item list-group-item-action '.$currentClass.' text-decoration-none ms-' . ($level * 2) . '" href="' . $this->route->generate('app_category', ['category' => $categoryName]) . '">' . $categoryName . ' <span class="badge bg-primary rounded-pill">' . $category['count'] . '</span></a>';
|
||||||
|
|
||||||
|
unset($category['count']);
|
||||||
|
if (is_array($category) && count($category) >= 1) {
|
||||||
|
foreach ($category as $subcategoryName => $subCategory) {
|
||||||
|
$tree .= $this->renderCategoryTree([$subcategoryName => $subCategory], $current, $level + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($level == 0) {
|
||||||
|
$tree .= '</ul>';
|
||||||
|
}
|
||||||
|
return $tree;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
{% extends "template.html.twig" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<table class='table table-hover'>
|
|
||||||
<tr>
|
|
||||||
<td><img src='{{ product.image }}&width=150' class='img-fluid' alt='{{ product.name }}'/></td>
|
|
||||||
<td><a href='?product_id={{ product.id }}'>{{ product.name }}</a></td>
|
|
||||||
<td>{{ product.subTitle }}</td>
|
|
||||||
<td>
|
|
||||||
<ul class='nav'>
|
|
||||||
{% for category in product.categories %}
|
|
||||||
<li class="nav-item"><a class="nav-link" href="?category={{ category }}"> {{ category }} </a></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="4">
|
|
||||||
|
|
||||||
<table class='table table-hover table-sm mb-0'>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>price</th>
|
|
||||||
<th>lowest product price in 30 days</th>
|
|
||||||
<th colspan='2'>standard price</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
{% for price in product.price %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ price.price }}</td>
|
|
||||||
<td>{{ price.lowestProductPrice30Days }}</td>
|
|
||||||
<td>{{ price.productStandardPrice }}</td>
|
|
||||||
<td>{{ price.created_at }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{% extends "template.html.twig" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<table class='table table-hover'>
|
|
||||||
{% for product in products %}
|
|
||||||
<tr>
|
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="?star={{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
|
||||||
<td><img src='{{ product.image }}&width=70' class='img-fluid' alt='{{ product.name }}'/></td>
|
|
||||||
<td class="align-middle"><a href='?product_id={{ product.id }}'>{{ product.name }}</a></td>
|
|
||||||
<td class="align-middle">{{ product.subTitle }}</td>
|
|
||||||
<td class="align-middle">
|
|
||||||
<ul class='nav'>
|
|
||||||
{% for category in product.categories %}
|
|
||||||
<li class="nav-item"><a class="nav-link" href="?category={{ category }}"> {{ category }} </a></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
|
||||||
<td class="align-middle">{{ product.price.last.price }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<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">
|
|
||||||
<title>Ryobi crawler</title>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
|
|
||||||
crossorigin="anonymous"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<nav class="navbar sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
|
||||||
<div class="container-fluid">
|
|
||||||
<a class="navbar-brand" href="/browser.php">Crawler</a>
|
|
||||||
<form class="d-flex w-50" role="search">
|
|
||||||
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search }}" aria-label="Search">
|
|
||||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
{% block content %}{% endblock %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
@charset "UTF-8";/*!
|
||||||
|
* Bootstrap v5.3.8 (https://getbootstrap.com/)
|
||||||
|
* Copyright 2011-2025 The Bootstrap Authors
|
||||||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
|
*/:root,[data-bs-theme=light]{--bs-blue:#0d6efd;--bs-indigo:#6610f2;--bs-purple:#6f42c1;--bs-pink:#d63384;--bs-red:#dc3545;--bs-orange:#fd7e14;--bs-yellow:#ffc107;--bs-green:#198754;--bs-teal:#20c997;--bs-cyan:#0dcaf0;--bs-black:#000;--bs-white:#fff;--bs-gray:#6c757d;--bs-gray-dark:#343a40;--bs-gray-100:#f8f9fa;--bs-gray-200:#e9ecef;--bs-gray-300:#dee2e6;--bs-gray-400:#ced4da;--bs-gray-500:#adb5bd;--bs-gray-600:#6c757d;--bs-gray-700:#495057;--bs-gray-800:#343a40;--bs-gray-900:#212529;--bs-primary:#0d6efd;--bs-secondary:#6c757d;--bs-success:#198754;--bs-info:#0dcaf0;--bs-warning:#ffc107;--bs-danger:#dc3545;--bs-light:#f8f9fa;--bs-dark:#212529;--bs-primary-rgb:13,110,253;--bs-secondary-rgb:108,117,125;--bs-success-rgb:25,135,84;--bs-info-rgb:13,202,240;--bs-warning-rgb:255,193,7;--bs-danger-rgb:220,53,69;--bs-light-rgb:248,249,250;--bs-dark-rgb:33,37,41;--bs-primary-text-emphasis:#052c65;--bs-secondary-text-emphasis:#2b2f32;--bs-success-text-emphasis:#0a3622;--bs-info-text-emphasis:#055160;--bs-warning-text-emphasis:#664d03;--bs-danger-text-emphasis:#58151c;--bs-light-text-emphasis:#495057;--bs-dark-text-emphasis:#495057;--bs-primary-bg-subtle:#cfe2ff;--bs-secondary-bg-subtle:#e2e3e5;--bs-success-bg-subtle:#d1e7dd;--bs-info-bg-subtle:#cff4fc;--bs-warning-bg-subtle:#fff3cd;--bs-danger-bg-subtle:#f8d7da;--bs-light-bg-subtle:#fcfcfd;--bs-dark-bg-subtle:#ced4da;--bs-primary-border-subtle:#9ec5fe;--bs-secondary-border-subtle:#c4c8cb;--bs-success-border-subtle:#a3cfbb;--bs-info-border-subtle:#9eeaf9;--bs-warning-border-subtle:#ffe69c;--bs-danger-border-subtle:#f1aeb5;--bs-light-border-subtle:#e9ecef;--bs-dark-border-subtle:#adb5bd;--bs-white-rgb:255,255,255;--bs-black-rgb:0,0,0;--bs-font-sans-serif:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--bs-font-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--bs-gradient:linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));--bs-body-font-family:var(--bs-font-sans-serif);--bs-body-font-size:1rem;--bs-body-font-weight:400;--bs-body-line-height:1.5;--bs-body-color:#212529;--bs-body-color-rgb:33,37,41;--bs-body-bg:#fff;--bs-body-bg-rgb:255,255,255;--bs-emphasis-color:#000;--bs-emphasis-color-rgb:0,0,0;--bs-secondary-color:rgba(33, 37, 41, 0.75);--bs-secondary-color-rgb:33,37,41;--bs-secondary-bg:#e9ecef;--bs-secondary-bg-rgb:233,236,239;--bs-tertiary-color:rgba(33, 37, 41, 0.5);--bs-tertiary-color-rgb:33,37,41;--bs-tertiary-bg:#f8f9fa;--bs-tertiary-bg-rgb:248,249,250;--bs-heading-color:inherit;--bs-link-color:#0d6efd;--bs-link-color-rgb:13,110,253;--bs-link-decoration:underline;--bs-link-hover-color:#0a58ca;--bs-link-hover-color-rgb:10,88,202;--bs-code-color:#d63384;--bs-highlight-color:#212529;--bs-highlight-bg:#fff3cd;--bs-border-width:1px;--bs-border-style:solid;--bs-border-color:#dee2e6;--bs-border-color-translucent:rgba(0, 0, 0, 0.175);--bs-border-radius:0.375rem;--bs-border-radius-sm:0.25rem;--bs-border-radius-lg:0.5rem;--bs-border-radius-xl:1rem;--bs-border-radius-xxl:2rem;--bs-border-radius-2xl:var(--bs-border-radius-xxl);--bs-border-radius-pill:50rem;--bs-box-shadow:0 0.5rem 1rem rgba(0, 0, 0, 0.15);--bs-box-shadow-sm:0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);--bs-box-shadow-lg:0 1rem 3rem rgba(0, 0, 0, 0.175);--bs-box-shadow-inset:inset 0 1px 2px rgba(0, 0, 0, 0.075);--bs-focus-ring-width:0.25rem;--bs-focus-ring-opacity:0.25;--bs-focus-ring-color:rgba(13, 110, 253, 0.25);--bs-form-valid-color:#198754;--bs-form-valid-border-color:#198754;--bs-form-invalid-color:#dc3545;--bs-form-invalid-border-color:#dc3545}[data-bs-theme=dark]{color-scheme:dark;--bs-body-color:#dee2e6;--bs-body-color-rgb:222,226,230;--bs-body-bg:#212529;--bs-body-bg-rgb:33,37,41;--bs-emphasis-color:#fff;--bs-emphasis-color-rgb:255,255,255;--bs-secondary-color:rgba(222, 226, 230, 0.75);--bs-secondary-color-rgb:222,226,230;--bs-secondary-bg:#343a40;--bs-secondary-bg-rgb:52,58,64;--bs-tertiary-color:rgba(222, 226, 230, 0.5);--bs-tertiary-color-rgb:222,226,230;--bs-tertiary-bg:#2b3035;--bs-tertiary-bg-rgb:43,48,53;--bs-primary-text-emphasis:#6ea8fe;--bs-secondary-text-emphasis:#a7acb1;--bs-success-text-emphasis:#75b798;--bs-info-text-emphasis:#6edff6;--bs-warning-text-emphasis:#ffda6a;--bs-danger-text-emphasis:#ea868f;--bs-light-text-emphasis:#f8f9fa;--bs-dark-text-emphasis:#dee2e6;--bs-primary-bg-subtle:#031633;--bs-secondary-bg-subtle:#161719;--bs-success-bg-subtle:#051b11;--bs-info-bg-subtle:#032830;--bs-warning-bg-subtle:#332701;--bs-danger-bg-subtle:#2c0b0e;--bs-light-bg-subtle:#343a40;--bs-dark-bg-subtle:#1a1d20;--bs-primary-border-subtle:#084298;--bs-secondary-border-subtle:#41464b;--bs-success-border-subtle:#0f5132;--bs-info-border-subtle:#087990;--bs-warning-border-subtle:#997404;--bs-danger-border-subtle:#842029;--bs-light-border-subtle:#495057;--bs-dark-border-subtle:#343a40;--bs-heading-color:inherLine truncated
|
||||||
|
/*# sourceMappingURL=bootstrap.min.css.map */
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../../scss/mixins/_banner.scss","../../scss/_root.scss","dist/css/bootstrap.css","../../scss/vendor/_rfs.scss","../../scss/mixins/_color-mode.scss","../../scss/_reboot.scss","../../scss/mixins/_border-radius.scss","../../scss/_type.scss","../../scss/mixins/_lists.scss","../../scss/_images.scss","../../scss/mixins/_image.scss","../../scss/_containers.scss","../../scss/mixins/_container.scss","../../scss/mixins/_breakpoints.scss","../../scss/_grid.scss","../../scss/mixins/_grid.scss","../../scss/_tables.scss","../../scss/mixins/_table-variants.scss","../../scss/forms/_labels.scss","../../scss/forms/_form-text.scss","../../scss/forms/_form-control.scss","../../scss/mixins/_transition.scss","../../scss/mixins/_gradients.scss","../../scss/forms/_form-select.scss","../../scss/forms/_form-check.scss","../../scss/forms/_form-range.scss","../../scss/forms/_floating-labels.scss","../../scss/forms/_input-group.scss","../../scss/mixins/_forms.scss","../../scss/_buttons.scss","../../scss/mixins/_buttons.scss","../../scss/_transitions.scss","../../scss/_dropdown.scss","../../scss/mixins/_caret.scss","../../scss/_button-group.scss","../../scss/_nav.scss","../../scss/_navbar.scss","../../scss/_card.scss","../../scss/_accordion.scss","../../scss/_breadcrumb.scss","../../scss/_pagination.scss","../../scss/mixins/_pagination.scss","../../scss/_badge.scss","../../scss/_alert.scss","../../scss/_progress.scss","../../scss/_list-group.scss","../../scss/_close.scss","../../scss/_toasts.scss","../../scss/_modal.scss","../../scss/mixins/_backdrop.scss","../../scss/_tooltip.scss","../../scss/mixins/_reset-text.scss","../../scss/_popover.scss","../../scss/_carousel.scss","../../scss/mixins/_clearfix.scss","../../scss/_spinners.scss","../../scss/_offcanvas.scss","../../scss/_placeholders.scss","../../scss/helpers/_color-bg.scss","../../scss/helpers/_colored-links.scss","../../scss/helpers/_focus-ring.scss","../../scss/helpers/_icon-link.scss","../../scss/helpers/_ratio.scss","../../scss/helpers/_position.scss","../../scss/helpers/_stacks.scss","../../scss/helpers/_visually-hidden.scss","../../scss/mixins/_visually-hidden.scss","../../scss/helpers/_stretched-link.scss","../../scss/helpers/_text-truncation.scss","../../scss/mixins/_text-truncate.scss","../../scss/helpers/_vr.scss","../../scss/mixins/_utilities.scss","../../scss/utilities/_api.scss"],"names":[],"mappings":"iBACE;;;;ACDF,MCOA,sBDEI,UAAA,QAAA,YAAA,QAAA,YAAA,QAAA,UAAA,QAAA,SAAA,QAAA,YAAA,QAAA,YAAA,QAAA,WAAA,QAAA,UAAA,QAAA,UAAA,QAAA,WAAA,KAAA,WAAA,KAAA,UAAA,QAAA,eAAA,QAIA,cAAA,QAAA,cAAA,QAAA,cAAA,QAAA,cAAA,QAAA,cAAA,QAAA,cAAA,QAAA,cAAA,QAAA,cAAA,QAAA,cAAA,QAIA,aAAA,QAAA,eAAA,QAAA,aAAA,QAAA,UAAA,QAAA,aAAA,QAAA,YAAA,QAAA,WAAA,QAAA,UAAA,QAIA,iBAAA,EAAA,CAAA,GAAA,CAAA,IAAA,mBAAA,GAAA,CAAA,GAAA,CAAA,IAAA,iBAAA,EAAA,CAAA,GAAA,CAAA,GAAA,cAAA,EAAA,CAAA,GAAA,CAAA,IAAA,iBAAA,GAAA,CAAA,GAAA,CAAA,EAAA,gBAAA,GAAA,CAAA,EAAA,CAAA,GAAA,eAAA,GAAA,CAAA,GAAA,CAAA,IAAA,cAAA,EAAA,CAAA,EAAA,CAAA,GAIA,2BAAA,QAAA,6BAAA,QAAA,2BAAA,QAAA,wBAAA,QAAA,2BAAA,QAAA,0BAAA,QAAA,yBAAA,QAAA,wBAAA,QAIA,uBAAA,QAAA,yBAAA,QAAA,uBAAA,QAAA,oBAAA,QAAA,uBAAA,QAAA,sBAAA,QAAA,qBAAA,QAAA,oBAAA,QAIA,2BAAA,QAAA,6BAAA,QAAA,2BAAA,QAAA,wBAAA,QAAA,2BAAA,QAAA,0BAAA,QAAA,yBAAA,QAAA,wBAAA,QAGF,eAAA,GAAA,CAAA,GAAA,CAAA,IACA,eAAA,CAAA,CAAA,CAAA,CAAA,EAMA,qBAAA,SAAA,CAAA,aAAA,CAAA,UAAA,CAAA,MAAA,CAAA,gBAAA,CAAA,WAAA,CAAA,iBAAA,CAAA,KAAA,CAAA,UAAA,CAAA,mBAAA,CAAA,gBAAA,CAAA,iBAAA,CAAA,mBACA,oBAAA,cAAA,CAAA,KAAA,CAAA,MAAA,CAAA,QAAA,CAAA,iBAAA,CAAA,aAAA,CAAA,UACA,cAAA,2EAOA,sBAAA,0BE2OI,oBAAA,KFzOJ,sBAAA,IACA,sBAAA,IAKA,gBAAA,QACA,oBAAA,EAAA,CAAA,EAAA,CAAA,GACA,aAAA,KACA,iBAAA,GAAA,CAAA,GAAA,CAAA,IAEA,oBAAA,KACA,wBAAA,CAAA,CAAA,CAAA,CAAA,EAEA,qBAAA,uBACA,yBAAA,EAAA,CAAA,EAAA,CAAA,GACA,kBAAA,QACA,sBAAA,GAAA,CAAA,GAAA,CAAA,IAEA,oBAAA,sBACA,wBAAA,EAAA,CAAA,EAAA,CAAA,GACA,iBAAA,QACA,qBAAA,GAAA,CAAA,GAAA,CAAA,IAGA,mBAAA,QAEA,gBAAA,QACA,oBAAA,EAAA,CAAA,GAAA,CAAA,IACA,qBAAA,UAEA,sBAAA,QACA,0BAAA,EAAA,CAAA,EAAA,CAAA,IAMA,gBAAA,QACA,qBAAA,QACA,kBAAA,QAGA,kBAAA,IACA,kBAAA,MACA,kBAAA,QACA,8BAAA,qBAEA,mBAAA,SACA,sBAAA,QACA,sBAAA,OACA,sBAAA,KACA,uBAAA,KACA,uBAAA,4BACA,wBAAA,MAGA,gBAAA,EAAA,OAAA,KAAA,oBACA,mBAAA,EAAA,SAAA,QAAA,qBACA,mBAAA,EAAA,KAAA,KAAA,qBACA,sBAAA,MAAA,EAAA,IAAA,IAAA,qBAIA,sBAAA,QACA,wBAAA,KACA,sBAAA,yBAIA,sBAAA,QACA,6BAAA,QACA,wBAAA,QACA,+BAAA,QGhHE,qBHsHA,aAAA,KAGA,gBAAA,QACA,oBAAA,GAAA,CAAA,GAAA,CAAA,IACA,aAAA,QACA,iBAAA,EAAA,CAAA,EAAA,CAAA,GAEA,oBAAA,KACA,wBAAA,GAAA,CAAA,GAAA,CAAA,IAEA,qBAAA,0BACA,yBAAA,GAAA,CAAA,GAAA,CAAA,IACA,kBAAA,QACA,sBAAA,EAAA,CAAA,EAAA,CAAA,GAEA,oBAAA,yBACA,wBAAA,GAAA,CAAA,GAAA,CAAA,IACA,iBAAA,QACA,qBAAA,EAAA,CAAA,EAAA,CAAA,GAGE,2BAAA,QAAA,6BAAA,QAAA,2BAAA,QAAA,wBAAA,QAAA,2BAAA,QAAA,0BAAA,QAAA,yBAAA,QAAA,wBAAA,QAIA,uBAAA,QAAA,yBAAA,QAAA,uBAAA,QAAA,oBAAA,QAAA,uBAAA,QAAA,sBAAA,QAAA,qBAAA,QAAA,oBAAA,QAIA,2BAAA,QAAA,6BAAA,QAAA,2BAAA,QAAA,wBAAA,QAAA,2BAAA,QAAA,0BAAA,QAAA,yBAAA,QAAA,wBAAA,QAGF,mBAAA,QAEA,gBAAA,QACA,sBAAA,QACA,oBAAA,GAAA,CAAA,GAAA,CAAA,IACA,0BAAA,GAAA,CAAA,GAAA,CAAA,IAEALine truncated
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<div class="container">
|
||||||
|
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||||
|
<div class="col-md-4 d-flex align-items-center">
|
||||||
|
<span class="mb-md-0 text-body-secondary">© 2025 Company, Inc</span>
|
||||||
|
<a class="align-items-center text-decoration-none" data-bs-theme-value="light">☀️ Light</a>
|
||||||
|
<a class="align-items-center text-decoration-none" data-bs-theme-value="dark">🌕 Dark</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 text-end text-muted">
|
||||||
|
{{ include('lastscrape.html.twig', ignore_missing: true) }}
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
/*!
|
||||||
|
* Bootstrap v5.3.8 (https://getbootstrap.com/)
|
||||||
|
* Copyright 2011-2025 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
|
*/
|
||||||
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).bootstrap=e()}(this,function(){"use strict";const t=new Map,e={set(e,i,n){t.has(e)||t.set(e,new Map);const s=t.get(e);s.has(i)||0===s.size?s.set(i,n):console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(s.keys())[0]}.`)},get:(e,i)=>t.has(e)&&t.get(e).get(i)||null,remove(e,i){if(!t.has(e))return;const n=t.get(e);n.delete(i),0===n.size&&t.delete(e)}},i="transitionend",n=t=>(t&&window.CSS&&window.CSS.escape&&(t=t.replace(/#([^\s"#']+)/g,(t,e)=>`#${CSS.escape(e)}`)),t),s=t=>null==t?`${t}`:Object.prototype.toString.call(t).match(/\s([a-z]+)/i)[1].toLowerCase(),o=t=>{t.dispatchEvent(new Event(i))},r=t=>!(!t||"object"!=typeof t)&&(void 0!==t.jquery&&(t=t[0]),void 0!==t.nodeType),a=t=>r(t)?t.jquery?t[0]:t:"string"==typeof t&&t.length>0?document.querySelector(n(t)):null,l=t=>{if(!r(t)||0===t.getClientRects().length)return!1;const e="visible"===getComputedStyle(t).getPropertyValue("visibility"),i=t.closest("details:not([open])");if(!i)return e;if(i!==t){const e=t.closest("summary");if(e&&e.parentNode!==i)return!1;if(null===e)return!1}return e},c=t=>!t||t.nodeType!==Node.ELEMENT_NODE||!!t.classList.contains("disabled")||(void 0!==t.disabled?t.disabled:t.hasAttribute("disabled")&&"false"!==t.getAttribute("disabled")),h=t=>{if(!document.documentElement.attachShadow)return null;if("function"==typeof t.getRootNode){const e=t.getRootNode();return e instanceof ShadowRoot?e:null}return t instanceof ShadowRoot?t:t.parentNode?h(t.parentNode):null},d=()=>{},u=t=>{t.offsetHeight},f=()=>window.jQuery&&!document.body.hasAttribute("data-bs-no-jquery")?window.jQuery:null,p=[],m=()=>"rtl"===document.documentElement.dir,g=t=>{var e;e=()=>{const e=f();if(e){const i=t.NAME,n=e.fn[i];e.fn[i]=t.jQueryInterface,e.fn[i].Constructor=t,e.fn[i].noConflict=()=>(e.fn[i]=n,t.jQueryInterface)}},"loading"===document.readyState?(p.length||document.addEventListener("DOMContentLoaded",()=>{for(const t of p)t()}),p.push(e)):e()},_=(t,e=[],i=t)=>"function"==typeof t?t.call(...e):i,b=(t,e,n=!0)=>{if(!n)return void _(t);const s=(t=>{if(!t)return 0;let{transitionDuration:e,transitionDelay:i}=window.getComputedStyle(t);const n=Number.parseFloat(e),s=Number.parseFloat(i);return n||s?(e=e.split(",")[0],i=i.split(",")[0],1e3*(Number.parseFloat(e)+Number.parseFloat(i))):0})(e)+5;let r=!1;const a=({target:n})=>{n===e&&(r=!0,e.removeEventListener(i,a),_(t))};e.addEventListener(i,a),setTimeout(()=>{r||o(e)},s)},v=(t,e,i,n)=>{const s=t.length;let o=t.indexOf(e);return-1===o?!i&&n?t[s-1]:t[0]:(o+=i?1:-1,n&&(o=(o+s)%s),t[Math.max(0,Math.min(o,s-1))])},y=/[^.]*(?=\..*)\.|.*/,w=/\..*/,A=/::\d+$/,E={};let T=1;const C={mouseenter:"mouseover",mouseleave:"mouseout"},O=new Set(["click","dblclick","mouseup","mousedown","contextmenu","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","selectstart","selectend","keydown","keypress","keyup","orientationchange","touchstart","touchmove","touchend","touchcancel","pointerdown","pointermove","pointerup","pointerleave","pointercancel","gesturestart","gesturechange","gestureend","focus","blur","change","reset","select","submit","focusin","focusout","load","unload","beforeunload","resize","move","DOMContentLoaded","readystatechange","error","abort","scroll"]);function x(t,e){return e&&`${e}::${T++}`||t.uidEvent||T++}function k(t){const e=x(t);return t.uidEvent=e,E[e]=E[e]||{},E[e]}function L(t,e,i=null){return Object.values(t).find(t=>t.callable===e&&t.delegationSelector===i)}function S(t,e,i){const n="string"==typeof e,s=n?i:e||i;let o=N(t);return O.has(o)||(o=t),[n,s,o]}function D(t,e,i,n,s){if("string"!=typeof e||!t)return;let[o,r,a]=S(e,i,n);if(e in C){const t=t=>function(e){if(!e.relatedTarget||e.relatedTarget!==e.delegateTarget&&!e.delegateTarget.contains(e.relatedTarget))return t.call(this,e)};r=t(r)}const l=k(t),c=l[a]||(l[a]={}),h=L(c,r,o?i:null);if(h)return void(h.oneOff=h.oneOff&&s);const d=x(r,e.replace(y,"")),u=o?function(t,e,i){return function n(s){const o=t.querySelectorAll(e);for(let{target:r}=s;r&&r!==this;r=r.parentNode)for(const a of o)if(a===r)return j(s,{delegateTarget:r}),n.oneOff&&P.off(t,s.type,e,i),i.apply(r,[s])}}(t,i,r):function(t,e){return function i(n){return j(n,{delegateTarget:t}),i.oneOff&&P.off(t,n.type,e),e.apply(t,[n])}}(t,r);u.delegationSelector=o?i:null,u.callable=r,u.oneOff=s,u.uidEvent=d,c[d]=u,t.addEventListener(a,u,o)}function $(t,e,i,n,s){const o=L(e[i],n,s);o&&(t.removeEventListener(i,o,Boolean(s)),delete e[i][o.uidEvent])}function I(t,e,i,n){const s=e[i]||{};for(const[o,r]of Object.entries(s))o.includes(n)&&$(t,e,i,r.callable,r.delegationSelector)}function N(t){return t=t.replace(w,""),C[t]||t}const P={on(t,e,i,n){D(t,e,i,n,!1)},one(t,e,i,n){D(t,e,i,n,!0)},off(t,e,i,n){if("string"!=typeof e||!t)return;const[s,o,r]=S(e,i,n),a=r!==e,l=k(t),c=l[rLine truncated
|
||||||
|
//# sourceMappingURL=bootstrap.bundle.min.js.map
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"names":["elementMap","Map","Data","set","element","key","instance","has","instanceMap","get","size","console","error","Array","from","keys","remove","delete","TRANSITION_END","parseSelector","selector","window","CSS","escape","replace","match","id","toType","object","Object","prototype","toString","call","toLowerCase","triggerTransitionEnd","dispatchEvent","Event","isElement","jquery","nodeType","getElement","length","document","querySelector","isVisible","getClientRects","elementIsVisible","getComputedStyle","getPropertyValue","closedDetails","closest","summary","parentNode","isDisabled","Node","ELEMENT_NODE","classList","contains","disabled","hasAttribute","getAttribute","findShadowRoot","documentElement","attachShadow","getRootNode","root","ShadowRoot","noop","reflow","offsetHeight","getjQuery","jQuery","body","DOMContentLoadedCallbacks","isRTL","dir","defineJQueryPlugin","plugin","callback","$","name","NAME","JQUERY_NO_CONFLICT","fn","jQueryInterface","Constructor","noConflict","readyState","addEventListener","push","execute","possibleCallback","args","defaultValue","executeAfterTransition","transitionElement","waitForTransition","emulatedDuration","transitionDuration","transitionDelay","floatTransitionDuration","Number","parseFloat","floatTransitionDelay","split","getTransitionDurationFromElement","called","handler","target","removeEventListener","setTimeout","getNextActiveElement","list","activeElement","shouldGetNext","isCycleAllowed","listLength","index","indexOf","Math","max","min","namespaceRegex","stripNameRegex","stripUidRegex","eventRegistry","uidEvent","customEvents","mouseenter","mouseleave","nativeEvents","Set","makeEventUid","uid","getElementEvents","findHandler","events","callable","delegationSelector","values","find","event","normalizeParameters","originalTypeEvent","delegationFunction","isDelegated","typeEvent","getTypeEvent","addHandler","oneOff","wrapFunction","relatedTarget","delegateTarget","this","handlers","previousFunction","domElements","querySelectorAll","domElement","hydrateObj","EventHandler","off","type","apply","bootstrapDelegationHandler","bootstrapHandler","removeHandler","Boolean","removeNamespacedHandlers","namespace","storeElementEvent","handlerKey","entries","includes","on","one","inNamespace","isNamespace","startsWith","elementEvent","slice","keyHandlers","trigger","jQueryEvent","bubbles","nativeDispatch","defaultPrevented","isPropagationStopped","isImmediatePropagationStopped","isDefaultPrevented","evt","cancelable","preventDefault","obj","meta","value","_unused","defineProperty","configurable","normalizeData","JSON","parse","decodeURIComponent","normalizeDataKey","chr","Manipulator","setDataAttribute","setAttribute","removeDataAttribute","removeAttribute","getDataAttributes","attributes","bsKeys","dataset","filter","pureKey","charAt","getDataAttribute","Config","Default","DefaultType","Error","_getConfig","config","_mergeConfigObj","_configAfterMerge","_typeCheckConfig","jsonConfig","constructor","configTypes","property","expectedTypes","valueType","RegExp","test","TypeError","toUpperCase","BaseComponent","super","_element","_config","DATA_KEY","dispose","EVENT_KEY","propertyName","getOwnPropertyNames","_queueCallback","isAnimated","getInstance","getOrCreateInstance","VERSION","eventName","getSelector","hrefAttribute","trim","map","sel","join","SelectorEngine","concat","Element","findOne","children","child","matches","parents","ancestor","prev","previous","previousElementSibling","next","nextElementSibling","focusableChildren","focusables","el","getSelectorFromElement","getElementFromSelector","getMultipleElementsFromSelector","enableDismissTrigger","component","method","clickEvent","tagName","EVENT_CLOSE","EVENT_CLOSED","Alert","close","_destroyElement","each","data","undefined","SELECTOR_DATA_TOGGLE","Button","toggle","button","EVENT_TOUCHSTART","EVENT_TOUCHMOVE","EVENT_TOUCHEND","EVENT_POINTERDOWN","EVENT_POINTERUP","endCallback","leftCallback","rightCallback","Swipe","isSupported","_deltaX","_supportPointerEvents","PointerEvent","_initEvents","_start","_eventIsPointerPenTouch","clientX","touches","_end","_handleSwipe","_move","absDeltaX","abs","direction","add","pointerType","navigator","maxTouchPoints","DATA_API_KEY","ARROW_LEFT_KEY","ARROW_RIGHT_KEY","ORDER_NEXT","ORDER_PREV","DIRECTION_LEFT","DIRECTION_RIGHT","EVENT_SLIDE","EVENT_SLID","EVENT_KEYDOWN","EVENT_MOUSEENTER","EVENT_MOUSELEAVE","EVENT_DRAG_START","EVENT_LOAD_DATA_API","EVENT_CLICK_DATA_API","CLASS_NAME_CAROUSEL","CLASS_NAME_ACTIVE","SELECTOR_ACTIVE","SELECTOR_ITEM","SELECTOR_ACTIVE_ITEM","KEY_TO_DIRECTION","ARROW_LEFT_KEY$1","ARROW_RIGHT_KEY$1","interval","keyboard","pause","ride","touch","wrap","Carousel","_interval","_activeElement","_isSliding","touchTimeout","_swipeHelper","_indicatorsElement","_addEventListeners","cycle","_slide","nextWhenVisible","hidden","_clearInterval","_updateInterval","setInterval","_maybeEnableCycle","to","items","_getItems","activeIndex","_getItemIndex",Line truncated
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
(function() {
|
||||||
|
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||||
|
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
|
||||||
|
})();
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class='table table-hover'>
|
||||||
|
<tr>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<a href="{{ path('app_search', {'search': product.subTitle}) }}"><span class="badge text-bg-secondary">{{ product.subTitle }}</span></a>
|
||||||
|
{% if product.promotions is not null and product.promotions.hasPromotion %}<a
|
||||||
|
href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>
|
||||||
|
</a>{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
{% 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 %}
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</td>
|
||||||
|
<td><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="5">
|
||||||
|
<div style="width: 800px;">
|
||||||
|
<canvas id="price"></canvas>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="5">
|
||||||
|
<table class='table table-hover table-sm mb-0'>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>price</th>
|
||||||
|
<th>lowest product price in 30 days</th>
|
||||||
|
<th colspan='2'>standard price</th>
|
||||||
|
<th>Stock</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% set stock = product.stock().get() %}
|
||||||
|
{% for price in product.price %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ price.price | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
||||||
|
<td>{{ price.lowestProductPrice30Days | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
||||||
|
<td>{{ price.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
||||||
|
<td>{{ price.created_at }}</td>
|
||||||
|
<td>{{ (stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const ctx = document.getElementById('price').getContext('2d');
|
||||||
|
|
||||||
|
new Chart(ctx, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: ['{{ price_dates|raw }}'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Price ({{ product.country.currency }})',
|
||||||
|
data: {{ price_list|raw }},
|
||||||
|
yAxisID: 'yPrice',
|
||||||
|
tension: 0.1,
|
||||||
|
borderWidth: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Stock (units)',
|
||||||
|
data: {{ stock_list|raw }},
|
||||||
|
yAxisID: 'yStock',
|
||||||
|
tension: 0.1,
|
||||||
|
borderWidth: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
spanGaps: false,
|
||||||
|
responsive: true,
|
||||||
|
animation: false,
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Date'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
yPrice: {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'left',
|
||||||
|
beginAtZero: true,
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Price ({{ product.country.currency }})'
|
||||||
|
},
|
||||||
|
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>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if listType starts with 'category_' %}
|
||||||
|
{{ renderCategoryTree(categoryTree, category) | raw }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if listType starts with 'promos' %}
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
{% for locale, promoByLocale in promos %}
|
||||||
|
<li class="list-group-item">
|
||||||
|
<h5 class="d-inline-block"><span class="badge bg-info">{{ locale | upper }}</span></h5>
|
||||||
|
{% for promo in promoByLocale %}
|
||||||
|
<a href="{{ path('app_promos', {'promo': promo.slug}) }}"><span
|
||||||
|
class="badge bg-info">PROMO: {{ promo.tag }} [{{ promo.locale | upper }}]</span></a>
|
||||||
|
{% endfor %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% if (listType starts with 'category_' and category == null) or not (listType starts with 'category_') or (listType starts with 'category_' and category is not null) %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<td class="align-middle">
|
||||||
|
<a href='{{ path('app_product', {'productId': product.id}) }}'
|
||||||
|
class="text-decoration-none">{{ product.name }}</a>
|
||||||
|
<br>
|
||||||
|
{% if product.stock > 0 %}
|
||||||
|
<span class="badge text-bg-secondary">stock: {{ product.stock }}</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge text-bg-warning">out of stock</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if product.isDiscontinued() %}
|
||||||
|
<a href="{{ path('app_discontinued') }}"><span class="badge text-bg-secondary" data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
|
||||||
|
{% endif %}
|
||||||
|
{% if product.isNew() %}
|
||||||
|
<a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a>
|
||||||
|
{% endif %}
|
||||||
|
<a href="{{ path('app_search', {'search': product.subTitle}) }}"><span class="badge text-bg-secondary">{{ product.subTitle }}</span></a>
|
||||||
|
{% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %}
|
||||||
|
<span class="badge text-bg-secondary">{{ product.country.countryName }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
|
<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 %}
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle"><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
|
||||||
|
<td class="align-middle text-end">
|
||||||
|
{% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %}
|
||||||
|
{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}
|
||||||
|
{% else %}
|
||||||
|
{% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{% else %}
|
||||||
|
<span class="badge text-bg-info">now lowest</span>{% endif %}</td>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<td class="align-middle text-end">{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<div class="d-flex flex-row">
|
||||||
|
{% if product.priceCurrent != product.productStandardPrice %}<span
|
||||||
|
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span>
|
||||||
|
<span
|
||||||
|
class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" data-bs-theme="">
|
||||||
|
<head>
|
||||||
|
<script>
|
||||||
|
(() => {
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const getStoredTheme = () => localStorage.getItem('theme')
|
||||||
|
const setStoredTheme = theme => localStorage.setItem('theme', theme)
|
||||||
|
|
||||||
|
const getPreferredTheme = () => {
|
||||||
|
const storedTheme = getStoredTheme()
|
||||||
|
if (storedTheme) {
|
||||||
|
return storedTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||||
|
}
|
||||||
|
|
||||||
|
const setTheme = theme => {
|
||||||
|
if (theme === 'auto') {
|
||||||
|
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'))
|
||||||
|
} else {
|
||||||
|
document.documentElement.setAttribute('data-bs-theme', theme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTheme(getPreferredTheme())
|
||||||
|
|
||||||
|
const showActiveTheme = (theme, focus = false) => {
|
||||||
|
const themeSwitcher = document.querySelector('#bd-theme')
|
||||||
|
|
||||||
|
if (!themeSwitcher) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
|
||||||
|
|
||||||
|
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
|
||||||
|
element.classList.remove('active')
|
||||||
|
})
|
||||||
|
|
||||||
|
btnToActive.classList.add('active')
|
||||||
|
|
||||||
|
if (focus) {
|
||||||
|
themeSwitcher.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||||
|
const storedTheme = getStoredTheme()
|
||||||
|
if (storedTheme !== 'light' && storedTheme !== 'dark') {
|
||||||
|
setTheme(getPreferredTheme())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
showActiveTheme(getPreferredTheme())
|
||||||
|
|
||||||
|
document.querySelectorAll('[data-bs-theme-value]')
|
||||||
|
.forEach(toggle => {
|
||||||
|
toggle.addEventListener('click', () => {
|
||||||
|
const theme = toggle.getAttribute('data-bs-theme-value')
|
||||||
|
setStoredTheme(theme)
|
||||||
|
setTheme(theme)
|
||||||
|
showActiveTheme(theme, true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})()
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<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">
|
||||||
|
<title>Ryobi crawler</title>
|
||||||
|
<link href="/templates/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
|
<script src="/templates/js/script.js" defer></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="{{ path('app_home') }}">Crawler</a>
|
||||||
|
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||||
|
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</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_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_lowest_price') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_lowest_price') }}">Lowest price <span class="badge text-bg-secondary">{{ lowestPriceCount() }}</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>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<label for="floatingInputValue">Search term eg. 36v or RCS18X</label>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
{{ include('footer.html.twig') }}
|
||||||
|
<script src="/templates/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
Reference in new issue
Block a user