Merge branch 'master' into feature/order-columns
# Conflicts: # Dockerfile # templates/productList.html.twig
This commit is contained in:
@@ -2,7 +2,7 @@ FROM php:8.3-cli
|
|||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
ENV PHP_MEMORY_LIMIT=512M
|
ENV PHP_MEMORY_LIMIT=512M
|
||||||
|
RUN echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit.ini
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
unzip \
|
unzip \
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ class ScrapeWebsite extends Command
|
|||||||
$products = $this->getProducts();
|
$products = $this->getProducts();
|
||||||
$progress->setMaxSteps(count($products));
|
$progress->setMaxSteps(count($products));
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
//dd($product);
|
|
||||||
$this->saveProduct($product);
|
$this->saveProduct($product);
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
}
|
}
|
||||||
@@ -91,6 +90,7 @@ class ScrapeWebsite extends Command
|
|||||||
$productModel->variantCode = $product->variantCode;
|
$productModel->variantCode = $product->variantCode;
|
||||||
$productModel->modelCode = $product->modelCode;
|
$productModel->modelCode = $product->modelCode;
|
||||||
$productModel->url = $product->url;
|
$productModel->url = $product->url;
|
||||||
|
$productModel->touch('updated_at');
|
||||||
$productModel->save();
|
$productModel->save();
|
||||||
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
||||||
|
|
||||||
|
|||||||
24
src/Controller/DiscontinuedController.php
Normal file
24
src/Controller/DiscontinuedController.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
|
final class DiscontinuedController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/discontinued', name: 'app_discontinued')]
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
|
||||||
|
$products = Product::where('updated_at', '<', now()->format('Y-m-d'))
|
||||||
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->with(['currentPrice'])
|
||||||
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,13 +7,14 @@ 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;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
final class NewController extends BaseController
|
final class NewController extends BaseController
|
||||||
{
|
{
|
||||||
#[Route('/new', name: 'app_new')]
|
#[Route('/new', name: 'app_new')]
|
||||||
public function __invoke(): Response
|
public function __invoke(): Response
|
||||||
{
|
{
|
||||||
$date = (new \DateTime())->modify('-30 days')->format('Y-m-d');
|
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
|
||||||
$products = Product::where('created_at', '>', $date)
|
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
->orderByDesc('name')
|
->orderByDesc('name')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property integer $skuID
|
* @property integer $skuID
|
||||||
* @property string $name
|
* @property string $name
|
||||||
@@ -66,9 +68,12 @@ class Product extends Model
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isnew(): bool
|
public function isDiscontinued(): bool
|
||||||
{
|
{
|
||||||
$newDate = (new \DateTime())->modify('-30 days')->format('Y-m-d');
|
return $this->updated_at->format('Y-m-d') < now()->format('Y-m-d');
|
||||||
return $this->created_at->format('Y-m-d') > $newDate;
|
}
|
||||||
|
public function isNew(): bool
|
||||||
|
{
|
||||||
|
return $this->created_at->format('Y-m-d') > now()->modify('-30 days')->format('Y-m-d');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use Twig\Extension\AbstractExtension;
|
|||||||
use Twig\TwigFilter;
|
use Twig\TwigFilter;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
use function Symfony\Component\Clock\now;
|
||||||
|
|
||||||
class AppExtension extends AbstractExtension
|
class AppExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
public function getFunctions(): array
|
public function getFunctions(): array
|
||||||
@@ -18,6 +20,7 @@ class AppExtension extends AbstractExtension
|
|||||||
return [
|
return [
|
||||||
new TwigFunction('promosCount', [$this, 'promosCount']),
|
new TwigFunction('promosCount', [$this, 'promosCount']),
|
||||||
new TwigFunction('newCount', [$this, 'newCount']),
|
new TwigFunction('newCount', [$this, 'newCount']),
|
||||||
|
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +38,12 @@ class AppExtension extends AbstractExtension
|
|||||||
|
|
||||||
public function newCount(): int
|
public function newCount(): int
|
||||||
{
|
{
|
||||||
$date = (new \DateTime())->modify('-30 days')->format('Y-m-d');
|
return Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))->count();
|
||||||
return Product::where('created_at', '>', $date)->count();
|
}
|
||||||
|
|
||||||
|
public function discontinuedCount(): int
|
||||||
|
{
|
||||||
|
return Product::where('updated_at', '<', now()->format('Y-m-d'))->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
||||||
|
|||||||
6
templates/css/bootstrap.min.css
vendored
Normal file
6
templates/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
4
templates/js/script.js
Normal file
4
templates/js/script.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
(function() {
|
||||||
|
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||||
|
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
|
||||||
|
})();
|
||||||
@@ -1,57 +1,60 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<table class='table table-hover'>
|
<div class="table-responsive">
|
||||||
<tr>
|
<table class='table table-hover'>
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
<tr>
|
||||||
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
||||||
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
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>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<td>
|
||||||
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
</td>
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
<td>
|
</td>
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
<td>
|
||||||
<ol class="breadcrumb">
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
{% for category in product.categories %}
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
{% for category in product.categories %}
|
||||||
{% endfor %}
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none"
|
||||||
</ol>
|
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
</nav>
|
{% endfor %}
|
||||||
</td>
|
</ol>
|
||||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
</nav>
|
||||||
</tr>
|
</td>
|
||||||
<tr>
|
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||||
<td colspan="5">
|
</tr>
|
||||||
<div style="width: 800px;">
|
<tr>
|
||||||
<canvas id="price"></canvas>
|
<td colspan="5">
|
||||||
</div>
|
<div style="width: 800px;">
|
||||||
</td>
|
<canvas id="price"></canvas>
|
||||||
</tr>
|
</div>
|
||||||
<tr>
|
</td>
|
||||||
<td colspan="5">
|
</tr>
|
||||||
<table class='table table-hover table-sm mb-0'>
|
<tr>
|
||||||
<thead>
|
<td colspan="5">
|
||||||
<tr>
|
<table class='table table-hover table-sm mb-0'>
|
||||||
<th>price</th>
|
<thead>
|
||||||
<th>lowest product price in 30 days</th>
|
|
||||||
<th colspan='2'>standard price</th>
|
|
||||||
<th>Stock</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
{% for price in product.price %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ price.price | format_currency('PLN', {}, 'pl') }}</td>
|
<th>price</th>
|
||||||
<td>{{ price.lowestProductPrice30Days | format_currency('PLN', {}, 'pl') }}</td>
|
<th>lowest product price in 30 days</th>
|
||||||
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
|
<th colspan='2'>standard price</th>
|
||||||
<td>{{ price.created_at }}</td>
|
<th>Stock</th>
|
||||||
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
</thead>
|
||||||
</table>
|
{% for price in product.price %}
|
||||||
</td>
|
<tr>
|
||||||
</tr>
|
<td>{{ price.price | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
</table>
|
<td>{{ price.lowestProductPrice30Days | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
|
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
|
<td>{{ price.created_at }}</td>
|
||||||
|
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="table-responsive">
|
||||||
{{ app.request.get('order') }}
|
{{ app.request.get('order') }}
|
||||||
<table class='table table-hover'>
|
<table class='table table-hover'>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -26,7 +27,10 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<span class="badge text-bg-warning">out of stock</span>
|
<span class="badge text-bg-warning">out of stock</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if product.isnew() %}
|
{% if product.isDiscontinued() %}
|
||||||
|
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" data-bs-title="Last update: {{ product.updated_at }}">is discontinued</span>
|
||||||
|
{% endif %}
|
||||||
|
{% if product.isNew() %}
|
||||||
<span class="badge text-bg-success">is new</span>
|
<span class="badge text-bg-success">is new</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
@@ -53,4 +57,5 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<title>Ryobi crawler</title>
|
<title>Ryobi crawler</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
|
<link href="/templates/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
crossorigin="anonymous"/>
|
<script src="/templates/js/script.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary border-bottom border-secondary border-1">
|
||||||
@@ -19,15 +19,20 @@
|
|||||||
<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">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
|
<a class="nav-link {% if app.request.pathinfo == path('app_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">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" 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 class="nav-item">
|
||||||
|
<a class="nav-link {% if app.request.pathinfo == path('app_discontinued') %}active shadow-sm bg-body rounded{% endif %}" aria-current="page" href="{{ path('app_discontinued') }}">Discontinued <span class="badge text-bg-secondary">{{ discontinuedCount() }}</span></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<form class="d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
|
||||||
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}" aria-label="Search">
|
<form class="form-floating d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
||||||
|
<input class="form-control me-2 form-control-sm" type="search" id="floatingInputValue" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}">
|
||||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||||
|
<label for="floatingInputValue">Search term eg. 36v or RCS18X</label>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user