Add stock to product.

This commit was merged in pull request #49.
This commit is contained in:
2026-01-19 15:08:53 +01:00
parent 295a968581
commit 46065dae1a
3 changed files with 17 additions and 6 deletions

View File

@@ -170,13 +170,25 @@ 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();
});
}
} }
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"'))) {
Capsule::schema()->table('products', function (Blueprint $table) { Capsule::schema()->table('products', function (Blueprint $table) {
$table->integer('skuID')->unique(false)->change(); $table->integer('skuID')->unique(false)->change();
$table->unique(['skuID', 'country_id']); $table->unique(['skuID', 'country_id']);
}); });
} }
Capsule::schema()->table('products', function (Blueprint $table) {
$table->foreign('id')->references('product_id')->on('stocks');
});
}
} }

View File

@@ -58,11 +58,13 @@ class ScrapeWebsite extends Command
$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();
} }
@@ -103,10 +105,6 @@ 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]);

View File

@@ -27,6 +27,7 @@ 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
*/ */
class Product extends Model class Product extends Model
{ {