Merge branch 'master' into feature/order-columns
# Conflicts: # Dockerfile # templates/productList.html.twig
This commit is contained in:
@@ -40,7 +40,6 @@ class ScrapeWebsite extends Command
|
||||
$products = $this->getProducts();
|
||||
$progress->setMaxSteps(count($products));
|
||||
foreach ($products as $product) {
|
||||
//dd($product);
|
||||
$this->saveProduct($product);
|
||||
$progress->advance();
|
||||
}
|
||||
@@ -91,6 +90,7 @@ class ScrapeWebsite extends Command
|
||||
$productModel->variantCode = $product->variantCode;
|
||||
$productModel->modelCode = $product->modelCode;
|
||||
$productModel->url = $product->url;
|
||||
$productModel->touch('updated_at');
|
||||
$productModel->save();
|
||||
$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\Routing\Attribute\Route;
|
||||
|
||||
use function Symfony\Component\Clock\now;
|
||||
|
||||
final class NewController extends BaseController
|
||||
{
|
||||
#[Route('/new', name: 'app_new')]
|
||||
public function __invoke(): Response
|
||||
{
|
||||
$date = (new \DateTime())->modify('-30 days')->format('Y-m-d');
|
||||
$products = Product::where('created_at', '>', $date)
|
||||
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
|
||||
->orderByDesc('starred')
|
||||
->orderByDesc('name')
|
||||
->orderByDesc('created_by')
|
||||
|
||||
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
use function Symfony\Component\Clock\now;
|
||||
|
||||
/**
|
||||
* @property integer $skuID
|
||||
* @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->created_at->format('Y-m-d') > $newDate;
|
||||
return $this->updated_at->format('Y-m-d') < now()->format('Y-m-d');
|
||||
}
|
||||
public function isNew(): bool
|
||||
{
|
||||
return $this->created_at->format('Y-m-d') > now()->modify('-30 days')->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
use function Symfony\Component\Clock\now;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
public function getFunctions(): array
|
||||
@@ -18,6 +20,7 @@ class AppExtension extends AbstractExtension
|
||||
return [
|
||||
new TwigFunction('promosCount', [$this, 'promosCount']),
|
||||
new TwigFunction('newCount', [$this, 'newCount']),
|
||||
new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -35,8 +38,12 @@ class AppExtension extends AbstractExtension
|
||||
|
||||
public function newCount(): int
|
||||
{
|
||||
$date = (new \DateTime())->modify('-30 days')->format('Y-m-d');
|
||||
return Product::where('created_at', '>', $date)->count();
|
||||
return Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))->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
|
||||
|
||||
Reference in New Issue
Block a user