Compare commits
30 Commits
3bbf82f897
...
7373657d78
| Author | SHA1 | Date | |
|---|---|---|---|
| 7373657d78 | |||
| 3431c0c131 | |||
| a2109a601b | |||
| fc63580305 | |||
| 695da689ac | |||
| 69dd3ce823 | |||
| 88daeef9ec | |||
| b553c15578 | |||
| 7bb3320e51 | |||
| befcef9e8d | |||
| cba20f6a61 | |||
| 074de13175 | |||
| 7e2658b174 | |||
| 1303b4ad8a | |||
| 67019e3933 | |||
| a545bfe2ab | |||
| 6556ba0f88 | |||
| 6da4f4257e | |||
| 5696f23f3d | |||
| 9f368a266a | |||
| 62c6538b89 | |||
| 2d1861caba | |||
| 5b424a2345 | |||
| 710c31551e | |||
| 0042fda5cc | |||
| 646383fb6a | |||
| f9c58edccd | |||
| 9ec3291a6a | |||
| 373fd1641b | |||
| 46065dae1a |
15
.gitea/workflows/deploy.yaml
Normal file
15
.gitea/workflows/deploy.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM php:8.3-cli
|
FROM php:8.4-cli
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
ENV PHP_MEMORY_LIMIT=1500M
|
ENV PHP_MEMORY_LIMIT=1500M
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
#!/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"
|
||||||
@@ -2,4 +2,5 @@
|
|||||||
echo "Updating project"
|
echo "Updating project"
|
||||||
git pull origin master
|
git pull origin master
|
||||||
bin/cacheclean
|
bin/cacheclean
|
||||||
|
bin/composer install --no-dev
|
||||||
echo "Project updated"
|
echo "Project updated"
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^7.0",
|
"guzzlehttp/guzzle": "^7",
|
||||||
"illuminate/database": "11.26.0.0",
|
"illuminate/database": "11.26.0.0",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"symfony/console": "^7.0",
|
"symfony/console": "^8.0",
|
||||||
"symfony/routing": "^7.1",
|
"symfony/routing": "^8.0",
|
||||||
"laravel/serializable-closure": "^1.3",
|
"laravel/serializable-closure": "^1.3",
|
||||||
"symfony/http-kernel": "^7.1",
|
"symfony/http-kernel": "^8.0",
|
||||||
"symfony/framework-bundle": "^7.1",
|
"symfony/framework-bundle": "^8.0",
|
||||||
"symfony/twig-bundle": "^7.1",
|
"symfony/twig-bundle": "^8.0",
|
||||||
"symfony/dotenv": "^7.1",
|
"symfony/dotenv": "^8.0",
|
||||||
"twig/intl-extra": "^3.13",
|
"twig/intl-extra": "^3.13",
|
||||||
"twig/extra-bundle": "^3.13",
|
"twig/extra-bundle": "^3.13",
|
||||||
"symfony/cache": "^7.2",
|
"symfony/cache": "^8.0",
|
||||||
"twig/cache-extra": "^3.21"
|
"twig/cache-extra": "^3.21"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/var-dumper": "^7.1"
|
"symfony/var-dumper": "^8.0"
|
||||||
}
|
},
|
||||||
|
"minimum-stability": "stable"
|
||||||
}
|
}
|
||||||
|
|||||||
966
composer.lock
generated
966
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler\Command;
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
|
||||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
use Twig\Environment;
|
|
||||||
|
|
||||||
#[AsCommand(name: 'app:cache:warm-twig', description: 'Warmup twig cache')]
|
|
||||||
class CacheWarmCommand extends Command
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private Environment $twig,
|
|
||||||
private RequestStack $requestStack,
|
|
||||||
private FilesystemAdapter $cache,
|
|
||||||
) {
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
|
||||||
{
|
|
||||||
$this->cache->clear();
|
|
||||||
|
|
||||||
$capsule = new Capsule;
|
|
||||||
$capsule->addConnection([
|
|
||||||
'driver' => 'sqlite',
|
|
||||||
'database' => __DIR__ . '/../../database.sqlite',
|
|
||||||
]);
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
|
|
||||||
$progress = new ProgressBar($output);
|
|
||||||
$progress->start();
|
|
||||||
$products = Product::with([
|
|
||||||
'price' => fn($query) => $query->orderByDesc('created_at'),
|
|
||||||
'stock' => fn($query) => $query->orderByDesc('created_at'),
|
|
||||||
])->get();
|
|
||||||
$progress->setMaxSteps(count($products));
|
|
||||||
|
|
||||||
$request = Request::create('/cache-warm');
|
|
||||||
$this->requestStack->push($request);
|
|
||||||
|
|
||||||
foreach ($products as $product) {
|
|
||||||
$priceList = $product->price()->pluck('price');
|
|
||||||
$stockList = $product->stock()->pluck('stock');
|
|
||||||
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
|
|
||||||
$stockDates = $product->stock()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->toArray();
|
|
||||||
$this->twig->render('product.html.twig', [
|
|
||||||
'product' => $product,
|
|
||||||
'price_list' => $this->prepareChartData($priceDates, $priceList),
|
|
||||||
'stock_list' => $this->prepareChartData($stockDates, $stockList),
|
|
||||||
'price_dates' => implode("','", $priceDates),
|
|
||||||
]);
|
|
||||||
$progress->advance();
|
|
||||||
}
|
|
||||||
|
|
||||||
$progress->finish();
|
|
||||||
$output->writeln('');
|
|
||||||
$output->writeln('DONE');
|
|
||||||
|
|
||||||
return Command::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function prepareChartData($set1, $set2): string
|
|
||||||
{
|
|
||||||
$data = [];
|
|
||||||
foreach ($set1 as $key => $value) {
|
|
||||||
$data[] = ['x' => $value, 'y' => $set2[$key]];
|
|
||||||
}
|
|
||||||
$stringData = json_encode($data);
|
|
||||||
|
|
||||||
return str_replace(['"x"', '"y"'], ['x', 'y'], $stringData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -112,7 +112,7 @@ class Migrate extends Command
|
|||||||
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
|
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
|
||||||
'cultureCode' => 'en-GB',
|
'cultureCode' => 'en-GB',
|
||||||
'currency' => 'GBP',
|
'currency' => 'GBP',
|
||||||
'locale' => 'en',
|
'locale' => 'uk',
|
||||||
'created_at' => now(),
|
'created_at' => now(),
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
]
|
]
|
||||||
@@ -154,6 +154,30 @@ class Migrate extends Command
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
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')) {
|
if (!Capsule::schema()->hasColumn('products', 'country_id')) {
|
||||||
Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
|
Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
|
||||||
@@ -211,15 +235,78 @@ class Migrate extends Command
|
|||||||
$table->date('lastSeen')->nullable();
|
$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
|
public function index(): void
|
||||||
{
|
{
|
||||||
if (!count(Capsule::select('SELECT name FROM sqlite_master WHERE type = "index" and name = "products_skuid_country_id_unique"'))) {
|
if (!$this->hasIndex('products_skuid_country_id_unique')) {
|
||||||
Capsule::schema()->table('products', function (Blueprint $table) {
|
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||||
$table->integer('skuID')->unique(false)->change();
|
if ($this->hasIndex('products_skuid_unique')) {
|
||||||
|
$table->integer('skuID')->unique(false)->change();
|
||||||
|
}
|
||||||
$table->unique(['skuID', 'country_id']);
|
$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]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ 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)
|
public function __construct(protected Capsule $database)
|
||||||
@@ -30,39 +32,42 @@ class ScrapeWebsite extends Command
|
|||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$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');
|
$output->writeln('Scrape products');
|
||||||
$progress = new ProgressBar($output);
|
$countries = Country::all()->when($countryId, fn ($query) => $query->where('id', $countryId));
|
||||||
$countries = Country::all();
|
|
||||||
foreach($countries as $country) {
|
foreach($countries as $country) {
|
||||||
$output->writeln('Country name: ' . $country->countryName."\n");
|
$output->writeln('Country name: ' . $country->countryName);
|
||||||
$progress->start();
|
|
||||||
$products = $this->getProducts($country);
|
$products = $this->getProducts($country);
|
||||||
|
$progress = new ProgressBar($output);
|
||||||
|
$progress->start();
|
||||||
$progress->setMaxSteps(count($products));
|
$progress->setMaxSteps(count($products));
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
$this->saveProduct($product, $country);
|
$this->saveProduct($product, $country);
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
}
|
}
|
||||||
$progress->finish();
|
$progress->finish();
|
||||||
$output->writeln('');
|
$output->writeln("\nScrape products - DONE\n");
|
||||||
$output->writeln('Scrape products - DONE');
|
|
||||||
$output->writeln('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln('Update prices');
|
$output->writeln('Update prices');
|
||||||
$products = Product::all();
|
$products = Product::all();
|
||||||
|
$progress = new ProgressBar($output);
|
||||||
$progress->setMaxSteps(count($products));
|
$progress->setMaxSteps(count($products));
|
||||||
$progress->start();
|
$progress->start();
|
||||||
foreach($products as $product) {
|
foreach($products as $product) {
|
||||||
$newestPrice = $product->newestPrice;
|
$newestPrice = $product->newestPrice;
|
||||||
|
$currentStock = $product->currentStock;
|
||||||
$product->priceCurrent = $newestPrice->price;
|
$product->priceCurrent = $newestPrice->price;
|
||||||
$product->productStandardPrice = $newestPrice->productStandardPrice;
|
$product->productStandardPrice = $newestPrice->productStandardPrice;
|
||||||
$product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
|
$product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
|
||||||
$product->priceLowest = $product->lowestPrice->price;
|
$product->priceLowest = $product->lowestPrice->price;
|
||||||
$product->lastSeen = $newestPrice->created_at->format('Y-m-d');
|
$product->lastSeen = $newestPrice->created_at->format('Y-m-d');
|
||||||
|
$product->stock = $currentStock->stock;
|
||||||
$product->save(['timestamps' => false]);
|
$product->save(['timestamps' => false]);
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
}
|
}
|
||||||
@@ -93,7 +98,7 @@ class ScrapeWebsite extends Command
|
|||||||
$products = array_merge($products, $responseObject->products);
|
$products = array_merge($products, $responseObject->products);
|
||||||
$page++;
|
$page++;
|
||||||
$canLoadMore = $responseObject->canLoadMore;
|
$canLoadMore = $responseObject->canLoadMore;
|
||||||
} catch (GuzzleException) {
|
} catch (GuzzleException $e) {
|
||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
} while ($canLoadMore);
|
} while ($canLoadMore);
|
||||||
@@ -103,17 +108,13 @@ class ScrapeWebsite extends Command
|
|||||||
|
|
||||||
private function saveProduct(\stdClass $product, Country $country): void
|
private function saveProduct(\stdClass $product, Country $country): void
|
||||||
{
|
{
|
||||||
// if ($product->skuID == 0) {
|
|
||||||
// dump([$product->skuID, $product->name]);
|
|
||||||
// }
|
|
||||||
// return;
|
|
||||||
/** @var Product $productModel */
|
/** @var Product $productModel */
|
||||||
$productModel = Product::firstOrNew(['skuID' => $product->skuID, 'country_id' => $country->id]);
|
$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->categories = $product->categories;
|
$productModel->categories = str_replace(['/', ' '], '', $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;
|
||||||
@@ -122,6 +123,7 @@ class ScrapeWebsite extends Command
|
|||||||
$productModel->lastSeen = date("Y-m-d");
|
$productModel->lastSeen = date("Y-m-d");
|
||||||
$productModel->touch('updated_at');
|
$productModel->touch('updated_at');
|
||||||
$productModel->country()->associate($country);
|
$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,7 @@ class BaseController extends AbstractController
|
|||||||
{
|
{
|
||||||
protected Environment $twig;
|
protected Environment $twig;
|
||||||
|
|
||||||
public function __construct(protected FilesystemAdapter $cache, protected Capsule $database)
|
public function __construct( protected Capsule $database)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,22 +8,40 @@ 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();
|
||||||
|
|
||||||
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_'.$category]);
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ 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('lastSeen', '<', now()->format('Y-m-d'))
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
|
|||||||
@@ -11,14 +11,11 @@ final class IndexController extends BaseController
|
|||||||
#[Route('/', name: 'app_home')]
|
#[Route('/', name: 'app_home')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
if ($this->cache->getItem('list_all')->isHit()) {
|
$products = Product::orderByDesc('starred')
|
||||||
return $this->render('productList.html.twig', ['listType' => 'all']);
|
|
||||||
}
|
|
||||||
$products = Product::with(['currentStock'])
|
|
||||||
->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']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ final class LowestPriceController extends BaseController
|
|||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
$listType = 'lowest_price';
|
$listType = 'lowest_price';
|
||||||
if($this->cache->getItem('lowest_price')->isHit()) {
|
|
||||||
return $this->render('productList.html.twig', ['listType' => $listType]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$products = Product::whereRaw('priceCurrent = priceLowest')
|
$products = Product::whereRaw('priceCurrent = priceLowest')
|
||||||
->whereRaw('lastSeen = "'.now()->format('Y-m-d').'"')
|
->whereRaw('lastSeen = "'.now()->format('Y-m-d').'"')
|
||||||
|
|||||||
@@ -13,14 +13,11 @@ final class NewController extends BaseController
|
|||||||
#[Route('/new', name: 'app_new')]
|
#[Route('/new', name: 'app_new')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
if($this->cache->getItem('list_new')->isHit()) {
|
$date = now()->modify('-30 days')->format('Y-m-d');
|
||||||
return $this->render('productList.html.twig', ['listType' => 'new']);
|
$products = Product::where('created_at', '>', $date)
|
||||||
}
|
->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']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,6 @@ 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'),
|
||||||
@@ -32,6 +28,10 @@ final class ProductController extends BaseController
|
|||||||
}
|
}
|
||||||
$priceList = $product->price()->pluck('price', 'created_at')->mapWithKeys(fn($price, $createdAt) => [explode(' ', $createdAt)[0] => $price])->toArray();
|
$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();
|
$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', [
|
return $this->render('product.html.twig', [
|
||||||
'product' => $product,
|
'product' => $product,
|
||||||
'price_list' => $this->prepareChartData($priceList),
|
'price_list' => $this->prepareChartData($priceList),
|
||||||
|
|||||||
@@ -8,18 +8,21 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||||||
|
|
||||||
final class PromosController extends BaseController
|
final class PromosController extends BaseController
|
||||||
{
|
{
|
||||||
#[Route('/promos', name: 'app_promos')]
|
#[Route('/promos/{promo?}', name: 'app_promos')]
|
||||||
public function __invoke(): Response
|
public function __invoke(?string $promo): Response
|
||||||
{
|
{
|
||||||
if($this->cache->getItem('list_promos')->isHit()) {
|
$products = Product::when(is_null($promo), fn($q) => $q->whereRaw('priceCurrent < productStandardPrice'))
|
||||||
return $this->render('productList.html.twig', ['listType' => 'promos']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$products = Product::whereRaw('priceCurrent < 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"))
|
||||||
|
->whereRaw("json_extract(promotions, '$.tag') is not null")
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'promos' . $promo, 'promos' => $promos->toArray()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,12 @@ 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
|
||||||
{
|
{
|
||||||
$this->cache->deleteItems(['list_all', 'list_promos', 'list_new', 'list_discontinued']);
|
|
||||||
$referer = $request->headers->get('referer');
|
$referer = $request->headers->get('referer');
|
||||||
if (str_contains($referer, '/category/')) {
|
if (str_contains($referer, '/category/')) {
|
||||||
preg_match('#/category/(.*)#i', $referer, $matches);
|
preg_match('#/category/(.*)#i', $referer, $matches);
|
||||||
$this->cache->deleteItem('list_category_'.urldecode($matches[1]));
|
|
||||||
}
|
}
|
||||||
if (str_contains($referer, '/search?search=')) {
|
if (str_contains($referer, '/search?search=')) {
|
||||||
preg_match('#/search\?search=(.*)#i', $referer, $matches);
|
preg_match('#/search\?search=(.*)#i', $referer, $matches);
|
||||||
$this->cache->deleteItem('list_search_'.urldecode($matches[1]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Product::find($productId)->toggleStarred()->save();
|
Product::find($productId)->toggleStarred()->save();
|
||||||
|
|||||||
18
src/Controller/UpdateController.php
Normal file
18
src/Controller/UpdateController.php
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,12 +38,7 @@ class Kernel extends BaseKernel
|
|||||||
$services->set(Manager::class)->configurator([DatabaseFactory::class, 'create']);
|
$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,DatabaseFactory.php,Kernel.php}');
|
||||||
$services->set('twig.extension.cache', AppExtension::class)->tag('twig.extension');
|
$services->set('twig.extension', 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
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,11 +28,13 @@ use function Symfony\Component\Clock\now;
|
|||||||
* @property float $productStandardPrice
|
* @property float $productStandardPrice
|
||||||
* @property float $lowestProductPrice30Days
|
* @property float $lowestProductPrice30Days
|
||||||
* @property Date $lastSeen
|
* @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
|
public function country(): BelongsTo
|
||||||
{
|
{
|
||||||
@@ -57,9 +60,10 @@ class Product extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
|
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newestPrice(): HasOne
|
public function newestPrice(): HasOne
|
||||||
{
|
{
|
||||||
return $this->hasOne(Price::class)->latest();
|
return $this->hasOne(Price::class)->latest()->take(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stock(): HasMany
|
public function stock(): HasMany
|
||||||
@@ -69,7 +73,7 @@ class Product extends Model
|
|||||||
|
|
||||||
public function currentStock(): HasOne
|
public function currentStock(): HasOne
|
||||||
{
|
{
|
||||||
return $this->stock()->one()->ofMany()->withDefault(fn (Stock $stock) => $stock->stock = 0);
|
return $this->stock()->one()->ofMany()->withDefault(fn(Stock $stock) => $stock->stock = 0)->take(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleStarred(): self
|
public function toggleStarred(): self
|
||||||
@@ -87,10 +91,23 @@ 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->lastSeen < 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,6 +15,10 @@ 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 [
|
||||||
@@ -23,6 +27,7 @@ class AppExtension extends AbstractExtension
|
|||||||
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('lowestPriceCount', [$this, 'lowestPriceCount']),
|
||||||
|
new TwigFunction('renderCategoryTree', [$this, 'renderCategoryTree']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +61,7 @@ class AppExtension extends AbstractExtension
|
|||||||
public function lowestPriceCount(): int
|
public function lowestPriceCount(): int
|
||||||
{
|
{
|
||||||
return Product::whereRaw('priceCurrent = priceLowest')
|
return Product::whereRaw('priceCurrent = priceLowest')
|
||||||
->whereRaw('lastSeen = "'.now()->format('Y-m-d').'"')
|
->whereRaw('lastSeen = "' . now()->format('Y-m-d') . '"')
|
||||||
->whereRaw('priceCurrent < productStandardPrice')
|
->whereRaw('priceCurrent < productStandardPrice')
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
@@ -65,4 +70,28 @@ class AppExtension extends AbstractExtension
|
|||||||
{
|
{
|
||||||
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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,35 @@
|
|||||||
{% 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></td>
|
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a>
|
||||||
|
</td>
|
||||||
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
||||||
<td>
|
<td>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<a href='{{ path('app_product', {'productId': product.id}) }}'
|
||||||
<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>
|
class="text-decoration-none">{{ product.name }}</a>
|
||||||
|
<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 class="breadcrumb-item text-decoration-none"
|
<li class="breadcrumb-item" aria-current="page"><a
|
||||||
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
class="breadcrumb-item text-decoration-none"
|
||||||
|
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
</td>
|
</td>
|
||||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
<td><a href='https://{{ product.country.locale }}.ryobitools.eu{{ product.url }}'>link</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="5">
|
<td colspan="5">
|
||||||
@@ -42,13 +49,14 @@
|
|||||||
<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(product.country.currency, {}, product.country.locale) }}</td>
|
||||||
<td>{{ price.lowestProductPrice30Days | 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.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</td>
|
||||||
<td>{{ price.created_at }}</td>
|
<td>{{ price.created_at }}</td>
|
||||||
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
<td>{{ (stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
@@ -131,6 +139,5 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endcache %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +1,94 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% cache 'list_' ~ listType %}
|
{% if listType starts with 'category_' %}
|
||||||
<div class="table-responsive">
|
{{ renderCategoryTree(categoryTree, category) | raw }}
|
||||||
<table class='table table-hover'>
|
{% endif %}
|
||||||
<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>
|
|
||||||
{% if product.currentStock.stock > 0 %}
|
|
||||||
<span class="badge text-bg-light">stock: {{ product.currentStock.stock }}</span>
|
|
||||||
{% else %}
|
|
||||||
<span class="badge text-bg-warning">out of stock</span>
|
|
||||||
{% endif %}
|
|
||||||
{% if product.isDiscontinued() %}
|
|
||||||
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span>
|
|
||||||
{% endif %}
|
|
||||||
{% if product.isNew() %}
|
|
||||||
<span class="badge text-bg-success">is new</span>
|
|
||||||
{% endif %}
|
|
||||||
<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>
|
|
||||||
</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://pl.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>
|
{% if listType starts with 'promos' %}
|
||||||
<td class="align-middle">
|
{% for promo in promos %}
|
||||||
<div class="d-flex flex-row">
|
<a href="{{ path('app_promos', {'promo': promo.slug}) }}"><span class="badge bg-info">PROMO: {{ promo.tag }}</span></a>
|
||||||
{% if product.priceCurrent != product.productStandardPrice %}<span
|
{% endfor %}
|
||||||
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span> <span
|
{% endif %}
|
||||||
class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
{% 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>
|
<div class="table-responsive">
|
||||||
</tr>
|
<table class='table table-hover'>
|
||||||
{% endfor %}
|
<thead>
|
||||||
</table>
|
<tr>
|
||||||
</div>
|
<th></th>
|
||||||
{% endcache %}
|
<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>
|
||||||
|
{% if product.stock > 0 %}
|
||||||
|
<span class="badge text-bg-light">stock: {{ product.stock }}</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge text-bg-warning">out of stock</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if product.isDiscontinued() %}
|
||||||
|
<span class="badge text-bg-secondary" data-bs-toggle="tooltip"
|
||||||
|
data-bs-title="Last update: {{ product.lastSeen }}">is discontinued</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if product.isNew() %}
|
||||||
|
<span class="badge text-bg-success">is new</span>
|
||||||
|
{% endif %}
|
||||||
|
<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 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,5 +1,5 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en" data-bs-theme="light">
|
||||||
<head>
|
<head>
|
||||||
<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">
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
</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" ~ listType|default('') %}
|
|
||||||
<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>
|
||||||
@@ -34,7 +33,6 @@
|
|||||||
<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') }}">
|
||||||
|
|||||||
Reference in New Issue
Block a user