Keep track of discontinued items. That means items that were tracked, but then they were never updated.Added is discontinued badge.
This commit is contained in:
@@ -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('created_by')
|
->orderByDesc('created_by')
|
||||||
->with(['currentPrice'])
|
->with(['currentPrice'])
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -25,7 +25,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">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>
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
<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 active" 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">
|
||||||
|
<a class="nav-link active" aria-current="page" href="{{ path('app_discontinued') }}">Discontinued <span class="badge text-bg-secondary">{{ discontinuedCount() }}</span></a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<form class="d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
<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">
|
<input class="form-control me-2" type="search" name="search" placeholder="Search term eg. 36v or RCS18X" value="{{ search|default('') }}" aria-label="Search">
|
||||||
|
|||||||
Reference in New Issue
Block a user