From 5a3918c22865d66e922980f57a78899436554795 Mon Sep 17 00:00:00 2001 From: Krzysiej Date: Sat, 31 Jan 2026 09:01:31 +0100 Subject: [PATCH] Add promotions to database and scrape command --- src/Command/Migrate.php | 5 +++++ src/Command/ScrapeWebsite.php | 1 + src/Models/Product.php | 1 + 3 files changed, 7 insertions(+) diff --git a/src/Command/Migrate.php b/src/Command/Migrate.php index ed1a099..322c164 100644 --- a/src/Command/Migrate.php +++ b/src/Command/Migrate.php @@ -181,6 +181,11 @@ class Migrate extends Command $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 diff --git a/src/Command/ScrapeWebsite.php b/src/Command/ScrapeWebsite.php index 9272190..3ee86fe 100644 --- a/src/Command/ScrapeWebsite.php +++ b/src/Command/ScrapeWebsite.php @@ -120,6 +120,7 @@ class ScrapeWebsite extends Command $productModel->lastSeen = date("Y-m-d"); $productModel->touch('updated_at'); $productModel->country()->associate($country); + $productModel->promotions = json_encode($product->promotions); $productModel->save(); $priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists(); diff --git a/src/Models/Product.php b/src/Models/Product.php index 8997015..f285a99 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -28,6 +28,7 @@ use function Symfony\Component\Clock\now; * @property float $lowestProductPrice30Days * @property Date $lastSeen * @property integer $stock + * @property Object $promotions */ class Product extends Model {