Compare commits
1 Commits
f01398603d
...
feature/ta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c093003fe7 |
@@ -1,17 +0,0 @@
|
|||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
workflow_dispatch:
|
|
||||||
jobs:
|
|
||||||
deploy-job:
|
|
||||||
runs-on: server
|
|
||||||
steps:
|
|
||||||
- name: initial test
|
|
||||||
run: echo "test"
|
|
||||||
- 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
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@
|
|||||||
.idea
|
.idea
|
||||||
*.sqlite
|
*.sqlite
|
||||||
var/cache/
|
var/cache/
|
||||||
.env.local
|
.env.local
|
||||||
|
/node_modules/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM php:8.4-cli
|
FROM php:8.3-cli
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
ENV PHP_MEMORY_LIMIT=1500M
|
ENV PHP_MEMORY_LIMIT=1500M
|
||||||
@@ -7,7 +7,9 @@ RUN apt-get update && apt-get install -y \
|
|||||||
git \
|
git \
|
||||||
unzip \
|
unzip \
|
||||||
libicu-dev \
|
libicu-dev \
|
||||||
libzip-dev
|
libzip-dev \
|
||||||
|
nodejs \
|
||||||
|
npm
|
||||||
|
|
||||||
RUN docker-php-ext-install zip intl
|
RUN docker-php-ext-install zip intl
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
echo "Cleaning cache"
|
bin/cli rm -rf var/cache
|
||||||
bin/cli rm -rf var/cache
|
|
||||||
echo "cache cleaned2"
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
bin/cli php console.php app:cache:warm-twig
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
[ -z "$1" ] && bin/cli composer list && exit
|
[ -z "$1" ] && echo "Please specify a Composer command (ex. install)" && exit
|
||||||
bin/cli composer "$@"
|
bin/cli composer "$@"
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
echo "Updating project"
|
echo "Updating project"
|
||||||
git pull origin master
|
git pull origin master
|
||||||
bin/cacheclean
|
bin/cli rm -rf var/cache
|
||||||
bin/composer install --no-dev
|
|
||||||
echo "Project updated"
|
echo "Project updated"
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^7",
|
"guzzlehttp/guzzle": "^7.0",
|
||||||
"illuminate/database": "11.26.0.0",
|
"illuminate/database": "11.26.0.0",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"symfony/console": "^8.0",
|
"symfony/console": "^7.0",
|
||||||
"symfony/routing": "^8.0",
|
"symfony/routing": "^7.1",
|
||||||
"laravel/serializable-closure": "^1.3",
|
"laravel/serializable-closure": "^1.3",
|
||||||
"symfony/http-kernel": "^8.0",
|
"symfony/http-kernel": "^7.1",
|
||||||
"symfony/framework-bundle": "^8.0",
|
"symfony/framework-bundle": "^7.1",
|
||||||
"symfony/twig-bundle": "^8.0",
|
"symfony/twig-bundle": "^7.1",
|
||||||
"symfony/dotenv": "^8.0",
|
"symfony/dotenv": "^7.1",
|
||||||
"twig/intl-extra": "^3.13",
|
"twig/intl-extra": "^3.13",
|
||||||
"twig/extra-bundle": "^3.13",
|
"twig/extra-bundle": "^3.13",
|
||||||
"symfony/cache": "^8.0",
|
"symfony/cache": "^7.2",
|
||||||
"twig/cache-extra": "^3.21"
|
"twig/cache-extra": "^3.21"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@@ -21,7 +21,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "^8.0"
|
"symfony/var-dumper": "^7.1"
|
||||||
},
|
}
|
||||||
"minimum-stability": "stable"
|
|
||||||
}
|
}
|
||||||
|
|||||||
1269
composer.lock
generated
1269
composer.lock
generated
File diff suppressed because it is too large
Load Diff
1079
package-lock.json
generated
Normal file
1079
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
Normal file
20
package.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "ryobi-crawler",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "## Project start",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"dev": "npx @tailwindcss/cli -i ./templates/input/style.css -o ./templates/output/style.css --watch"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.techtube.pl/krzysiej/ryobi-crawler.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@tailwindcss/cli": "^4.1.7",
|
||||||
|
"tailwindcss": "^4.1.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
screenshot1.png
BIN
screenshot1.png
Binary file not shown.
|
Before Width: | Height: | Size: 282 KiB After Width: | Height: | Size: 199 KiB |
84
src/Command/CacheWarmCommand.php
Normal file
84
src/Command/CacheWarmCommand.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
#[AsCommand(name: 'app:cache:warm-twig', description: '')]
|
||||||
|
class CacheWarmCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Environment $twig,
|
||||||
|
private RequestStack $requestStack,
|
||||||
|
private FilesystemAdapter $cache,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$this->cache->clear();
|
||||||
|
|
||||||
|
$capsule = new Capsule;
|
||||||
|
$capsule->addConnection([
|
||||||
|
'driver' => 'sqlite',
|
||||||
|
'database' => __DIR__ . '/../../database.sqlite',
|
||||||
|
]);
|
||||||
|
$capsule->setAsGlobal();
|
||||||
|
$capsule->bootEloquent();
|
||||||
|
|
||||||
|
$progress = new ProgressBar($output);
|
||||||
|
$progress->start();
|
||||||
|
$products = Product::with([
|
||||||
|
'price' => fn($query) => $query->orderByDesc('created_at'),
|
||||||
|
'stock' => fn($query) => $query->orderByDesc('created_at'),
|
||||||
|
])->get();
|
||||||
|
$progress->setMaxSteps(count($products));
|
||||||
|
|
||||||
|
$request = Request::create('/cache-warm');
|
||||||
|
$this->requestStack->push($request);
|
||||||
|
|
||||||
|
foreach ($products as $product) {
|
||||||
|
$priceList = $product->price()->pluck('price');
|
||||||
|
$stockList = $product->stock()->pluck('stock');
|
||||||
|
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
|
||||||
|
$stockDates = $product->stock()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
|
||||||
|
$this->twig->render('product.html.twig', [
|
||||||
|
'product' => $product,
|
||||||
|
'price_list' => $this->prepareChartData($priceDates, $priceList),
|
||||||
|
'stock_list' => $this->prepareChartData($stockDates, $stockList),
|
||||||
|
'price_dates' => implode("','", $priceDates),
|
||||||
|
]);
|
||||||
|
$progress->advance();
|
||||||
|
}
|
||||||
|
|
||||||
|
$progress->finish();
|
||||||
|
$output->writeln('');
|
||||||
|
$output->writeln('DONE');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepareChartData($set1, $set2): string
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
foreach ($set1 as $key => $value) {
|
||||||
|
$data[] = ['x' => $value, 'y' => $set2[$key]];
|
||||||
|
}
|
||||||
|
$stringData = json_encode($data);
|
||||||
|
|
||||||
|
return str_replace(['"x"', '"y"'], ['x', 'y'], $stringData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,13 +6,11 @@ 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\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
|
||||||
@@ -26,10 +24,11 @@ class Migrate extends Command
|
|||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
if ($input->getOption(self::RECREATE_OPTION)) {
|
if (true === $input->hasOption(self::RECREATE_OPTION)) {
|
||||||
unlink(__DIR__ . '/../../database.sqlite');
|
unlink(__DIR__ . '/../../database.sqlite');
|
||||||
touch(__DIR__ . '/../../database.sqlite');
|
//sleep(5);
|
||||||
}
|
}
|
||||||
|
touch(__DIR__ . '/../../database.sqlite');
|
||||||
$capsule = new Capsule;
|
$capsule = new Capsule;
|
||||||
$capsule->addConnection([
|
$capsule->addConnection([
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
@@ -40,9 +39,6 @@ class Migrate extends Command
|
|||||||
$this->createProductsTable();
|
$this->createProductsTable();
|
||||||
$this->createPricesTable();
|
$this->createPricesTable();
|
||||||
$this->createStocksTable();
|
$this->createStocksTable();
|
||||||
$this->addColumns();
|
|
||||||
$this->createCountriesTable();
|
|
||||||
$this->index();
|
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -81,111 +77,6 @@ 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')) {
|
||||||
@@ -203,110 +94,4 @@ 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,7 +7,6 @@ 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;
|
||||||
@@ -15,90 +14,61 @@ 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->start();
|
|
||||||
$progress->setMaxSteps(count($products));
|
|
||||||
foreach ($products as $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 = new ProgressBar($output);
|
||||||
$progress->setMaxSteps(count($products));
|
|
||||||
$progress->start();
|
$progress->start();
|
||||||
foreach($products as $product) {
|
$products = $this->getProducts();
|
||||||
$newestPrice = $product->newestPrice;
|
$progress->setMaxSteps(count($products));
|
||||||
$currentStock = $product->currentStock;
|
foreach ($products as $product) {
|
||||||
$product->priceCurrent = $newestPrice->price;
|
$this->saveProduct($product);
|
||||||
$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('Update prices - DONE');
|
$output->writeln('DONE');
|
||||||
$output->writeln('COMMAND - DONE');
|
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProducts(Country $country): array
|
private function getProducts(): array
|
||||||
{
|
{
|
||||||
$products = [];
|
$products = [];
|
||||||
$page = 0;
|
$page = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
$res = $this->client->request('POST', $country->productsUrl, [
|
$res = $this->client->request('POST', 'https://pl.ryobitools.eu/api/product-listing/get-products', [
|
||||||
'form_params' => [
|
'form_params' => [
|
||||||
"includePreviousPages" => false,
|
"includePreviousPages" => false,
|
||||||
"pageIndex" => $page,
|
"pageIndex" => $page,
|
||||||
"pageSize" => 100,
|
"pageSize" => 100,
|
||||||
"cultureCode" => $country->cultureCode,
|
"cultureCode" => "pl-PL",
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
$responseObject = json_decode($res->getBody()->getContents());
|
$responseObject = json_decode($res->getBody()->getContents());
|
||||||
$products = array_merge($products, $responseObject->products);
|
$products = array_merge($products, $responseObject->products);
|
||||||
$page++;
|
$page++;
|
||||||
$canLoadMore = $responseObject->canLoadMore;
|
$canLoadMore = $responseObject->canLoadMore;
|
||||||
} catch (GuzzleException $e) {
|
} catch (GuzzleException) {
|
||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
} while ($canLoadMore);
|
} while ($canLoadMore);
|
||||||
@@ -106,24 +76,21 @@ class ScrapeWebsite extends Command
|
|||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function saveProduct(\stdClass $product, Country $country): void
|
private function saveProduct(\stdClass $product): void
|
||||||
{
|
{
|
||||||
/** @var Product $productModel */
|
/** @var Product $productModel */
|
||||||
$productModel = Product::firstOrNew(['skuID' => $product->skuID, 'country_id' => $country->id]);
|
$productModel = Product::firstOrNew(['skuID' => $product->skuID]);
|
||||||
|
|
||||||
$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->categories = str_replace(['/', ' '], '', $product->categories);
|
$productModel->categories = $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->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();
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ class BaseController extends AbstractController
|
|||||||
{
|
{
|
||||||
protected Environment $twig;
|
protected Environment $twig;
|
||||||
|
|
||||||
public function __construct( protected Capsule $database)
|
public function __construct(protected FilesystemAdapter $cache)
|
||||||
{
|
{
|
||||||
|
$capsule = new Capsule;
|
||||||
|
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../../database.sqlite']);
|
||||||
|
$capsule->setAsGlobal();
|
||||||
|
$capsule->bootEloquent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,40 +8,22 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||||||
|
|
||||||
final class CategoryController extends BaseController
|
final class CategoryController extends BaseController
|
||||||
{
|
{
|
||||||
#[Route('/category/{category?}', name: 'app_category')]
|
#[Route('/category/{category}', name: 'app_category')]
|
||||||
public function __invoke(?string $category): Response
|
public function __invoke(string $category): Response
|
||||||
{
|
{
|
||||||
|
if($this->cache->getItem('list_category_'.$category)->isHit()) {
|
||||||
|
return $this->render('productList.html.twig', ['listType' => 'category_'.$category]);
|
||||||
|
}
|
||||||
|
|
||||||
/** @var Product[] $products */
|
|
||||||
$products = Product::with(['price', 'lowestPrice'])
|
$products = Product::with(['price', 'lowestPrice'])
|
||||||
->selectRaw('products.*')
|
->selectRaw('products.*')
|
||||||
->distinct('products.id')
|
->distinct('products.id')
|
||||||
->when(!is_null($category) , fn ($q) => $q->whereRaw('json_each.value = ?', [$category]))
|
|
||||||
->fromRaw('products, json_each(products.categories)')
|
->fromRaw('products, json_each(products.categories)')
|
||||||
|
->whereRaw('json_each.value = ?', [$category])
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$categoriesTree = [];
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_'.$category]);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,14 @@ final class DiscontinuedController extends BaseController
|
|||||||
#[Route('/discontinued', name: 'app_discontinued')]
|
#[Route('/discontinued', name: 'app_discontinued')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
|
if($this->cache->getItem('list_discontinued')->isHit()) {
|
||||||
|
return $this->render('productList.html.twig', ['listType' => 'discontinued']);
|
||||||
|
}
|
||||||
|
|
||||||
$products = Product::where('lastSeen', '<', now()->format('Y-m-d'))
|
$products = Product::where('updated_at', '<', now()->format('Y-m-d'))
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
|
->with(['currentPrice', 'lowestPrice'])
|
||||||
->get();
|
->get();
|
||||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'discontinued']);
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'discontinued']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ final class IndexController extends BaseController
|
|||||||
#[Route('/', name: 'app_home')]
|
#[Route('/', name: 'app_home')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
$products = Product::orderByDesc('starred')
|
if ($this->cache->getItem('list_all')->isHit()) {
|
||||||
|
return $this->render('productList.html.twig', ['listType' => 'all']);
|
||||||
|
}
|
||||||
|
$products = Product::with(['currentStock', 'price', 'lowestPrice'])
|
||||||
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|
||||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'all']);
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'all']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
<?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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
@@ -13,11 +14,14 @@ final class NewController extends BaseController
|
|||||||
#[Route('/new', name: 'app_new')]
|
#[Route('/new', name: 'app_new')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
$date = now()->modify('-30 days')->format('Y-m-d');
|
if($this->cache->getItem('list_new')->isHit()) {
|
||||||
$products = Product::where('created_at', '>', $date)
|
return $this->render('productList.html.twig', ['listType' => 'new']);
|
||||||
->with(['country', 'stock'])
|
}
|
||||||
|
|
||||||
|
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
|
->with(['currentPrice', 'lowestPrice'])
|
||||||
->get();
|
->get();
|
||||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'new']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
@@ -19,6 +20,10 @@ final class ProductController extends BaseController
|
|||||||
#[Route('/product/{productId<\d+>}', name: 'app_product')]
|
#[Route('/product/{productId<\d+>}', name: 'app_product')]
|
||||||
public function __invoke(int $productId): Response
|
public function __invoke(int $productId): Response
|
||||||
{
|
{
|
||||||
|
if($this->cache->getItem('product'.$productId)->isHit()) {
|
||||||
|
return $this->render('product.html.twig', ['product' => ['id' => $productId]]);
|
||||||
|
}
|
||||||
|
|
||||||
$product = Product::with([
|
$product = Product::with([
|
||||||
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||||
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
|
||||||
@@ -26,38 +31,26 @@ final class ProductController extends BaseController
|
|||||||
if (null === $product) {
|
if (null === $product) {
|
||||||
throw $this->createNotFoundException('Product not found');
|
throw $this->createNotFoundException('Product not found');
|
||||||
}
|
}
|
||||||
$priceList = $product->price()->pluck('price', 'created_at')->mapWithKeys(fn($price, $createdAt) => [explode(' ', $createdAt)[0] => $price])->toArray();
|
$priceList = $product->price()->pluck('price');
|
||||||
$stockList = $product->stock()->pluck('stock', 'created_at')->mapWithKeys(fn($stock, $createdAt) => [explode(' ', $createdAt)[0] => $stock])->toArray();
|
$stockList = $product->stock()->pluck('stock');
|
||||||
|
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
|
||||||
ksort($stockList);
|
$stockDates = $product->stock()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
|
||||||
ksort($priceList);
|
|
||||||
|
|
||||||
return $this->render('product.html.twig', [
|
return $this->render('product.html.twig', [
|
||||||
'product' => $product,
|
'product' => $product,
|
||||||
'price_list' => $this->prepareChartData($priceList),
|
'price_list' => $this->prepareChartData($priceDates, $priceList),
|
||||||
'stock_list' => $this->prepareChartData($stockList),
|
'stock_list' => $this->prepareChartData($stockDates, $stockList),
|
||||||
'price_dates' => implode("','", $this->dateRange(array_key_first($priceList), array_key_last($priceList))),
|
'price_dates' => implode("','", $priceDates),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareChartData($set1): string
|
private function prepareChartData($set1, $set2): string
|
||||||
{
|
{
|
||||||
$dates = $this->dateRange(array_key_first($set1), array_key_last($set1));
|
$data = [];
|
||||||
$data = array_map(fn($date) => ['x' => $date, 'y' => $set1[$date] ?? null], $dates);
|
foreach ($set1 as $key => $value) {
|
||||||
|
$data[] = ['x' => $value, 'y' => $set2[$key]];
|
||||||
|
}
|
||||||
$stringData = json_encode($data);
|
$stringData = json_encode($data);
|
||||||
|
|
||||||
return str_replace(['"x"', '"y"'], ['x', 'y'], $stringData);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,30 +2,25 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
final class PromosController extends BaseController
|
final class PromosController extends BaseController
|
||||||
{
|
{
|
||||||
#[Route('/promos/{promo?}', name: 'app_promos')]
|
#[Route('/promos', name: 'app_promos')]
|
||||||
public function __invoke(?string $promo): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
$products = Product::when(is_null($promo), fn($q) => $q->whereRaw('priceCurrent < productStandardPrice'))
|
if($this->cache->getItem('list_promos')->isHit()) {
|
||||||
|
return $this->render('productList.html.twig', ['listType' => 'promos']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$products = Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->with(['currentPrice', 'lowestPrice'])
|
->with(['currentPrice', 'lowestPrice'])
|
||||||
->when(!is_null($promo), fn($q) => $q->whereRaw("json_extract(promotions, '$.slug') LIKE ?", $promo))
|
|
||||||
->get();
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos']);
|
||||||
|
|
||||||
$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()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ final class SearchController extends BaseController
|
|||||||
->orWhere([['name', 'like', "%$search%"]])
|
->orWhere([['name', 'like', "%$search%"]])
|
||||||
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
->orWhere([['subTitle', 'like', "%$search%"]])->get();
|
||||||
|
|
||||||
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search, 'listType' => 'search_'.$search]);
|
return $this->render('productList.html.twig', ['products' => $products ?? [], 'search' => $search]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,7 @@ final class StarController extends BaseController
|
|||||||
#[Route('/star/{productId<\d+>}', name: 'app_star')]
|
#[Route('/star/{productId<\d+>}', name: 'app_star')]
|
||||||
public function __invoke(int $productId, Request $request): Response
|
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();
|
Product::find($productId)->toggleStarred()->save();
|
||||||
return $this->redirect($referer);
|
return $this->redirect($request->headers->get('referer'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler;
|
namespace Krzysiej\RyobiCrawler;
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager;
|
|
||||||
use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
use Krzysiej\RyobiCrawler\Twig\AppExtension;
|
||||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||||
use Symfony\Bundle\TwigBundle\TwigBundle;
|
use Symfony\Bundle\TwigBundle\TwigBundle;
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||||
|
use Twig\Extra\Cache\CacheExtension;
|
||||||
|
use Twig\Extra\Cache\CacheRuntime;
|
||||||
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;
|
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;
|
||||||
|
|
||||||
class Kernel extends BaseKernel
|
class Kernel extends BaseKernel
|
||||||
@@ -31,10 +34,14 @@ class Kernel extends BaseKernel
|
|||||||
'secret' => 'S0ME_SECRET'
|
'secret' => 'S0ME_SECRET'
|
||||||
]);
|
]);
|
||||||
$services = $container->services()->defaults()->autowire()->autoconfigure();
|
$services = $container->services()->defaults()->autowire()->autoconfigure();
|
||||||
$services->set(Manager::class)->configurator([DatabaseFactory::class, 'create']);
|
|
||||||
$services->load('Krzysiej\\RyobiCrawler\\', __DIR__ )
|
$services->load('Krzysiej\\RyobiCrawler\\', __DIR__ )
|
||||||
->exclude('../src/{Models,Twig,DatabaseFactory.php,Kernel.php}');
|
->exclude('../src/{Models,Twig,Kernel.php}');
|
||||||
$services->set('twig.extension', AppExtension::class)->tag('twig.extension');
|
$services->set('twig.extension.cache', AppExtension::class)->tag('twig.extension');
|
||||||
|
$services->set(CacheExtension::class)->tag('twig.extension');
|
||||||
|
$services->set(FilesystemAdapter::class)->args([
|
||||||
|
'$directory' => __DIR__ . '/../var/cache/twig_blocks'
|
||||||
|
]);
|
||||||
|
$services->set('twig.runtime.cache', CacheRuntime::class)->args([new Reference(FilesystemAdapter::class)])->tag('twig.runtime');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configureRoutes(RoutingConfigurator $routes): void
|
protected function configureRoutes(RoutingConfigurator $routes): void
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
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\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use function Symfony\Component\Clock\now;
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,23 +20,11 @@ use function Symfony\Component\Clock\now;
|
|||||||
* @property string $modelCode
|
* @property string $modelCode
|
||||||
* @property string $url
|
* @property string $url
|
||||||
* @property int $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', 'country_id'];
|
public $fillable = ['skuID'];
|
||||||
|
|
||||||
public function country(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Country::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function price(): HasMany
|
public function price(): HasMany
|
||||||
{
|
{
|
||||||
@@ -61,11 +46,6 @@ class Product extends Model
|
|||||||
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
|
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);
|
||||||
@@ -73,7 +53,9 @@ class Product extends Model
|
|||||||
|
|
||||||
public function currentStock(): HasOne
|
public function currentStock(): HasOne
|
||||||
{
|
{
|
||||||
return $this->stock()->one()->ofMany()->withDefault(fn(Stock $stock) => $stock->stock = 0)->take(1);
|
return $this->stock()->one()->ofMany()->withDefault(function (Stock $stock) {
|
||||||
|
$stock->stock = 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleStarred(): self
|
public function toggleStarred(): self
|
||||||
@@ -91,23 +73,10 @@ class Product extends Model
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
public function isDiscontinued(): bool
|
||||||
{
|
{
|
||||||
return $this->lastSeen < now()->format('Y-m-d');
|
return $this->updated_at->format('Y-m-d') < now()->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isNew(): bool
|
public function isNew(): bool
|
||||||
{
|
{
|
||||||
return $this->created_at->format('Y-m-d') > now()->modify('-30 days')->format('Y-m-d');
|
return $this->created_at->format('Y-m-d') > now()->modify('-30 days')->format('Y-m-d');
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler\Twig;
|
namespace Krzysiej\RyobiCrawler\Twig;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
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;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFilter;
|
use Twig\TwigFilter;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
@@ -15,10 +15,6 @@ use function Symfony\Component\Clock\now;
|
|||||||
|
|
||||||
class AppExtension extends AbstractExtension
|
class AppExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
public function __construct(public RouterInterface $route)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFunctions(): array
|
public function getFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@@ -26,8 +22,6 @@ class AppExtension extends AbstractExtension
|
|||||||
new TwigFunction('allCount', [$this, 'allCount']),
|
new TwigFunction('allCount', [$this, 'allCount']),
|
||||||
new TwigFunction('newCount', [$this, 'newCount']),
|
new TwigFunction('newCount', [$this, 'newCount']),
|
||||||
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||||
new TwigFunction('lowestPriceCount', [$this, 'lowestPriceCount']),
|
|
||||||
new TwigFunction('renderCategoryTree', [$this, 'renderCategoryTree']),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +31,6 @@ class AppExtension extends AbstractExtension
|
|||||||
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
|
new TwigFilter('findByCreatedAtDate', [$this, 'findByCreatedAtDate']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function allCount(): int
|
public function allCount(): int
|
||||||
{
|
{
|
||||||
return Product::count();
|
return Product::count();
|
||||||
@@ -45,7 +38,7 @@ class AppExtension extends AbstractExtension
|
|||||||
|
|
||||||
public function promosCount(): int
|
public function promosCount(): int
|
||||||
{
|
{
|
||||||
return Product::whereRaw('priceCurrent < productStandardPrice')->count();
|
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newCount(): int
|
public function newCount(): int
|
||||||
@@ -55,43 +48,11 @@ class AppExtension extends AbstractExtension
|
|||||||
|
|
||||||
public function discontinuedCount(): int
|
public function discontinuedCount(): int
|
||||||
{
|
{
|
||||||
return Product::where('lastSeen', '<>', now()->format('Y-m-d'))->count();
|
return Product::where('updated_at', '<', 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
|
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
||||||
{
|
{
|
||||||
return $items->first(fn($item) => str_starts_with($item->created_at, $date));
|
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
templates/css/bootstrap.min.css
vendored
6
templates/css/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,9 +0,0 @@
|
|||||||
<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-3 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>
|
|
||||||
</footer>
|
|
||||||
</div>
|
|
||||||
1
templates/input/style.css
Normal file
1
templates/input/style.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
7
templates/js/bootstrap.bundle.min.js
vendored
7
templates/js/bootstrap.bundle.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
340
templates/output/style.css
Normal file
340
templates/output/style.css
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
/*! tailwindcss v4.1.7 | MIT License | https://tailwindcss.com */
|
||||||
|
@layer properties;
|
||||||
|
@layer theme, base, components, utilities;
|
||||||
|
@layer theme {
|
||||||
|
:root, :host {
|
||||||
|
--font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
|
||||||
|
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||||
|
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
|
||||||
|
"Courier New", monospace;
|
||||||
|
--spacing: 0.25rem;
|
||||||
|
--text-3xl: 1.875rem;
|
||||||
|
--text-3xl--line-height: calc(2.25 / 1.875);
|
||||||
|
--font-weight-bold: 700;
|
||||||
|
--default-font-family: var(--font-sans);
|
||||||
|
--default-mono-font-family: var(--font-mono);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@layer base {
|
||||||
|
*, ::after, ::before, ::backdrop, ::file-selector-button {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 0 solid;
|
||||||
|
}
|
||||||
|
html, :host {
|
||||||
|
line-height: 1.5;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
tab-size: 4;
|
||||||
|
font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
|
||||||
|
font-feature-settings: var(--default-font-feature-settings, normal);
|
||||||
|
font-variation-settings: var(--default-font-variation-settings, normal);
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
hr {
|
||||||
|
height: 0;
|
||||||
|
color: inherit;
|
||||||
|
border-top-width: 1px;
|
||||||
|
}
|
||||||
|
abbr:where([title]) {
|
||||||
|
-webkit-text-decoration: underline dotted;
|
||||||
|
text-decoration: underline dotted;
|
||||||
|
}
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
font-size: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: inherit;
|
||||||
|
-webkit-text-decoration: inherit;
|
||||||
|
text-decoration: inherit;
|
||||||
|
}
|
||||||
|
b, strong {
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
code, kbd, samp, pre {
|
||||||
|
font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
|
||||||
|
font-feature-settings: var(--default-mono-font-feature-settings, normal);
|
||||||
|
font-variation-settings: var(--default-mono-font-variation-settings, normal);
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
small {
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
|
sub, sup {
|
||||||
|
font-size: 75%;
|
||||||
|
line-height: 0;
|
||||||
|
position: relative;
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
sub {
|
||||||
|
bottom: -0.25em;
|
||||||
|
}
|
||||||
|
sup {
|
||||||
|
top: -0.5em;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
text-indent: 0;
|
||||||
|
border-color: inherit;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
:-moz-focusring {
|
||||||
|
outline: auto;
|
||||||
|
}
|
||||||
|
progress {
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
summary {
|
||||||
|
display: list-item;
|
||||||
|
}
|
||||||
|
ol, ul, menu {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
img, svg, video, canvas, audio, iframe, embed, object {
|
||||||
|
display: block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
img, video {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
button, input, select, optgroup, textarea, ::file-selector-button {
|
||||||
|
font: inherit;
|
||||||
|
font-feature-settings: inherit;
|
||||||
|
font-variation-settings: inherit;
|
||||||
|
letter-spacing: inherit;
|
||||||
|
color: inherit;
|
||||||
|
border-radius: 0;
|
||||||
|
background-color: transparent;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
:where(select:is([multiple], [size])) optgroup {
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
:where(select:is([multiple], [size])) optgroup option {
|
||||||
|
padding-inline-start: 20px;
|
||||||
|
}
|
||||||
|
::file-selector-button {
|
||||||
|
margin-inline-end: 4px;
|
||||||
|
}
|
||||||
|
::placeholder {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
@supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
|
||||||
|
::placeholder {
|
||||||
|
color: currentcolor;
|
||||||
|
@supports (color: color-mix(in lab, red, red)) {
|
||||||
|
color: color-mix(in oklab, currentcolor 50%, transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
::-webkit-search-decoration {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
}
|
||||||
|
::-webkit-date-and-time-value {
|
||||||
|
min-height: 1lh;
|
||||||
|
text-align: inherit;
|
||||||
|
}
|
||||||
|
::-webkit-datetime-edit {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
::-webkit-datetime-edit-fields-wrapper {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
|
||||||
|
padding-block: 0;
|
||||||
|
}
|
||||||
|
:-moz-ui-invalid {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
button, input:where([type="button"], [type="reset"], [type="submit"]), ::file-selector-button {
|
||||||
|
appearance: button;
|
||||||
|
}
|
||||||
|
::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
[hidden]:where(:not([hidden="until-found"])) {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@layer utilities {
|
||||||
|
.collapse {
|
||||||
|
visibility: collapse;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
@media (width >= 40rem) {
|
||||||
|
max-width: 40rem;
|
||||||
|
}
|
||||||
|
@media (width >= 48rem) {
|
||||||
|
max-width: 48rem;
|
||||||
|
}
|
||||||
|
@media (width >= 64rem) {
|
||||||
|
max-width: 64rem;
|
||||||
|
}
|
||||||
|
@media (width >= 80rem) {
|
||||||
|
max-width: 80rem;
|
||||||
|
}
|
||||||
|
@media (width >= 96rem) {
|
||||||
|
max-width: 96rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.me-2 {
|
||||||
|
margin-inline-end: calc(var(--spacing) * 2);
|
||||||
|
}
|
||||||
|
.me-auto {
|
||||||
|
margin-inline-end: auto;
|
||||||
|
}
|
||||||
|
.mb-0 {
|
||||||
|
margin-bottom: calc(var(--spacing) * 0);
|
||||||
|
}
|
||||||
|
.mb-2 {
|
||||||
|
margin-bottom: calc(var(--spacing) * 2);
|
||||||
|
}
|
||||||
|
.block {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
}
|
||||||
|
.table {
|
||||||
|
display: table;
|
||||||
|
}
|
||||||
|
.flex-row {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
.rounded {
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
|
.border {
|
||||||
|
border-style: var(--tw-border-style);
|
||||||
|
border-width: 1px;
|
||||||
|
}
|
||||||
|
.border-1 {
|
||||||
|
border-style: var(--tw-border-style);
|
||||||
|
border-width: 1px;
|
||||||
|
}
|
||||||
|
.p-1 {
|
||||||
|
padding: calc(var(--spacing) * 1);
|
||||||
|
}
|
||||||
|
.text-end {
|
||||||
|
text-align: end;
|
||||||
|
}
|
||||||
|
.align-middle {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.text-3xl {
|
||||||
|
font-size: var(--text-3xl);
|
||||||
|
line-height: var(--tw-leading, var(--text-3xl--line-height));
|
||||||
|
}
|
||||||
|
.font-bold {
|
||||||
|
--tw-font-weight: var(--font-weight-bold);
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
}
|
||||||
|
.underline {
|
||||||
|
text-decoration-line: underline;
|
||||||
|
}
|
||||||
|
.shadow-sm {
|
||||||
|
--tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 1px 2px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
||||||
|
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@property --tw-border-style {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: solid;
|
||||||
|
}
|
||||||
|
@property --tw-font-weight {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
}
|
||||||
|
@property --tw-shadow {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 0 0 #0000;
|
||||||
|
}
|
||||||
|
@property --tw-shadow-color {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
}
|
||||||
|
@property --tw-shadow-alpha {
|
||||||
|
syntax: "<percentage>";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 100%;
|
||||||
|
}
|
||||||
|
@property --tw-inset-shadow {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 0 0 #0000;
|
||||||
|
}
|
||||||
|
@property --tw-inset-shadow-color {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
}
|
||||||
|
@property --tw-inset-shadow-alpha {
|
||||||
|
syntax: "<percentage>";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 100%;
|
||||||
|
}
|
||||||
|
@property --tw-ring-color {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
}
|
||||||
|
@property --tw-ring-shadow {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 0 0 #0000;
|
||||||
|
}
|
||||||
|
@property --tw-inset-ring-color {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
}
|
||||||
|
@property --tw-inset-ring-shadow {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 0 0 #0000;
|
||||||
|
}
|
||||||
|
@property --tw-ring-inset {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
}
|
||||||
|
@property --tw-ring-offset-width {
|
||||||
|
syntax: "<length>";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 0px;
|
||||||
|
}
|
||||||
|
@property --tw-ring-offset-color {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: #fff;
|
||||||
|
}
|
||||||
|
@property --tw-ring-offset-shadow {
|
||||||
|
syntax: "*";
|
||||||
|
inherits: false;
|
||||||
|
initial-value: 0 0 #0000;
|
||||||
|
}
|
||||||
|
@layer properties {
|
||||||
|
@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
|
||||||
|
*, ::before, ::after, ::backdrop {
|
||||||
|
--tw-border-style: solid;
|
||||||
|
--tw-font-weight: initial;
|
||||||
|
--tw-shadow: 0 0 #0000;
|
||||||
|
--tw-shadow-color: initial;
|
||||||
|
--tw-shadow-alpha: 100%;
|
||||||
|
--tw-inset-shadow: 0 0 #0000;
|
||||||
|
--tw-inset-shadow-color: initial;
|
||||||
|
--tw-inset-shadow-alpha: 100%;
|
||||||
|
--tw-ring-color: initial;
|
||||||
|
--tw-ring-shadow: 0 0 #0000;
|
||||||
|
--tw-inset-ring-color: initial;
|
||||||
|
--tw-inset-ring-shadow: 0 0 #0000;
|
||||||
|
--tw-ring-inset: initial;
|
||||||
|
--tw-ring-offset-width: 0px;
|
||||||
|
--tw-ring-offset-color: #fff;
|
||||||
|
--tw-ring-offset-shadow: 0 0 #0000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,35 +1,28 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% cache 'product' ~ product.id %}
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class='table table-hover'>
|
<table class='table table-hover'>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
||||||
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a>
|
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||||
</td>
|
|
||||||
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
||||||
<td>
|
<td>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}'
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
class="text-decoration-none">{{ product.name }}</a>
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}"
|
|
||||||
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
|
||||||
{% 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>
|
||||||
<td>
|
<td>
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
{% for category in product.categories %}
|
{% for category in product.categories %}
|
||||||
<li class="breadcrumb-item" aria-current="page"><a
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none"
|
||||||
class="breadcrumb-item text-decoration-none"
|
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
</td>
|
</td>
|
||||||
<td><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
|
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="5">
|
<td colspan="5">
|
||||||
@@ -49,14 +42,13 @@
|
|||||||
<th>Stock</th>
|
<th>Stock</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% set stock = product.stock().get() %}
|
|
||||||
{% for price in product.price %}
|
{% for price in product.price %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ price.price | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
<td>{{ price.price | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
<td>{{ price.lowestProductPrice30Days | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
<td>{{ price.lowestProductPrice30Days | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
<td>{{ price.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
<td>{{ price.created_at }}</td>
|
<td>{{ price.created_at }}</td>
|
||||||
<td>{{ (stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
@@ -75,7 +67,7 @@
|
|||||||
labels: ['{{ price_dates|raw }}'],
|
labels: ['{{ price_dates|raw }}'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Price ({{ product.country.currency }})',
|
label: 'Price (PLN)',
|
||||||
data: {{ price_list|raw }},
|
data: {{ price_list|raw }},
|
||||||
yAxisID: 'yPrice',
|
yAxisID: 'yPrice',
|
||||||
tension: 0.1,
|
tension: 0.1,
|
||||||
@@ -91,7 +83,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
spanGaps: false,
|
|
||||||
responsive: true,
|
responsive: true,
|
||||||
animation: false,
|
animation: false,
|
||||||
scales: {
|
scales: {
|
||||||
@@ -107,7 +98,7 @@
|
|||||||
beginAtZero: true,
|
beginAtZero: true,
|
||||||
title: {
|
title: {
|
||||||
display: true,
|
display: true,
|
||||||
text: 'Price ({{ product.country.currency }})'
|
text: 'Price (PLN)'
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
drawOnChartArea: false
|
drawOnChartArea: false
|
||||||
@@ -139,5 +130,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
{% endcache %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -1,104 +1,64 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if listType starts with 'category_' %}
|
{% cache 'list_' ~ listType %}
|
||||||
{{ renderCategoryTree(categoryTree, category) | raw }}
|
<div class="table-responsive">
|
||||||
{% endif %}
|
<table class='table table-hover'>
|
||||||
|
<thead>
|
||||||
{% if listType starts with 'promos' %}
|
<tr>
|
||||||
<ul class="list-group list-group-flush">
|
<th></th>
|
||||||
{% for locale, promoByLocale in promos %}
|
<th></th>
|
||||||
<li class="list-group-item">
|
<th>Name</th>
|
||||||
<h5 class="d-inline-block"><span class="badge bg-info">{{ locale | upper }}</span></h5>
|
<th>Categories</th>
|
||||||
{% for promo in promoByLocale %}
|
<th></th>
|
||||||
<a href="{{ path('app_promos', {'promo': promo.slug}) }}"><span
|
<th class="text-end">Lowest Price</th>
|
||||||
class="badge bg-info">PROMO: {{ promo.tag }} [{{ promo.locale | upper }}]</span></a>
|
<th class="text-end">Current Price</th>
|
||||||
{% endfor %}
|
<th></th>
|
||||||
</li>
|
</tr>
|
||||||
{% endfor %}
|
</thead>
|
||||||
</ul>
|
{% for product in products %}
|
||||||
{% endif %}
|
<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>
|
||||||
{% if (listType starts with 'category_' and category == null) or not (listType starts with 'category_') or (listType starts with 'category_' and category is not null) %}
|
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70' class='img-thumbnail' alt='{{ product.name }}'/></td>
|
||||||
<div class="table-responsive">
|
<td class="align-middle">
|
||||||
<table class='table table-hover'>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
<thead>
|
{% if product.currentStock.stock > 0 %}
|
||||||
<tr>
|
<span class="badge text-bg-light">stock: {{ product.currentStock.stock }}</span>
|
||||||
<th></th>
|
{% else %}
|
||||||
<th></th>
|
<span class="badge text-bg-warning">out of stock</span>
|
||||||
<th>Name</th>
|
{% endif %}
|
||||||
<th>Categories</th>
|
{% if product.isDiscontinued() %}
|
||||||
<th></th>
|
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" data-bs-title="Last update: {{ product.updated_at }}">is discontinued</span>
|
||||||
<th class="text-end">Lowest Price</th>
|
{% endif %}
|
||||||
<th class="text-end">Current Price</th>
|
{% if product.isNew() %}
|
||||||
<th></th>
|
<span class="badge text-bg-success">is new</span>
|
||||||
</tr>
|
{% endif %}
|
||||||
</thead>
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
{% for product in products %}
|
</td>
|
||||||
<tr>
|
<td class="align-middle">
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
||||||
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred == true %}★{% else %} ☆ {% endif %}</a>
|
<ol class="breadcrumb">
|
||||||
</td>
|
{% for category in product.categories %}
|
||||||
<td class="align-middle" style="width: 120px;"><img src='{{ product.image }}&width=70'
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
class='img-thumbnail'
|
{% endfor %}
|
||||||
alt='{{ product.name }}'/></td>
|
</ol>
|
||||||
<td class="align-middle">
|
</nav>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}'
|
</td>
|
||||||
class="text-decoration-none">{{ product.name }}</a>
|
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||||
<br>
|
<td class="align-middle text-end">{% if product.lowestPrice.price != product.price.last.price %}{{ product.lowestPrice.price | format_currency('PLN', {}, 'pl') }}{% endif %}</td>
|
||||||
{% if product.stock > 0 %}
|
<td class="align-middle text-end">{{ product.price.last.price | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
<span class="badge text-bg-light">stock: {{ product.stock }}</span>
|
<td class="align-middle">
|
||||||
{% else %}
|
<div class="d-flex flex-row">
|
||||||
<span class="badge text-bg-warning">out of stock</span>
|
{% if product.price.last.price != product.price.last.productStandardPrice %}<span
|
||||||
{% endif %}
|
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.price.last.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span> <span
|
||||||
{% if product.isDiscontinued() %}
|
class="badge text-bg-success flex-fill">{{ ((1 - product.price.last.price / product.price.last.productStandardPrice)*100)|number_format(0) }}%</span>
|
||||||
<a href="{{ path('app_discontinued') }}"><span class="badge text-bg-secondary" data-bs-toggle="tooltip"
|
{% endif %}
|
||||||
data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span></a>
|
</div>
|
||||||
{% endif %}
|
</td>
|
||||||
{% if product.isNew() %}
|
</tr>
|
||||||
<a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a>
|
{% endfor %}
|
||||||
{% endif %}
|
</table>
|
||||||
<span class="badge text-bg-light"><a
|
</div>
|
||||||
href="{{ path('app_search', {'search': product.subTitle}) }}"
|
{% endcache %}
|
||||||
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
|
||||||
{% 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-light">{{ 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 %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,108 +1,38 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en" data-bs-theme="">
|
<html lang="en">
|
||||||
<head>
|
<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 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 name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<title>Ryobi crawler</title>
|
<title>Ryobi crawler</title>
|
||||||
<link href="/templates/css/bootstrap.min.css" rel="stylesheet" />
|
<link href="/templates/output/style.css" rel="stylesheet" />
|
||||||
<script src="/templates/js/script.js" defer></script>
|
<script src="/templates/js/script.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h1 class="text-3xl font-bold underline">test header</h1>
|
||||||
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="{{ path('app_home') }}">Crawler</a>
|
<a class="navbar-brand" href="{{ path('app_home') }}">Crawler</a>
|
||||||
|
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
|
{% cache "menu_count" %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link {% 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>
|
<a class="nav-link {% if app.request.pathinfo == path('app_home') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_home') }}">All products <span class="badge text-bg-secondary">{{ allCount() }}</span></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<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>
|
<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>
|
||||||
<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">
|
<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>
|
<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>
|
||||||
<li class="nav-item">
|
<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>
|
<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>
|
</li>
|
||||||
|
{% endcache %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
<form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
||||||
@@ -115,8 +45,8 @@
|
|||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
{{ include('footer.html.twig') }}
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||||
<script src="/templates/js/bootstrap.bundle.min.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user