Add stock to product. #49

Merged
krzysiej merged 1 commits from feature/add-stock-to-product into master 2026-01-19 15:09:13 +01:00
3 changed files with 17 additions and 6 deletions
Showing only changes of commit 46065dae1a - Show all commits

View File

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

View File

@@ -58,11 +58,13 @@ class ScrapeWebsite extends Command
$progress->start();
foreach($products as $product) {
$newestPrice = $product->newestPrice;
$currentStock = $product->currentStock;
$product->priceCurrent = $newestPrice->price;
$product->productStandardPrice = $newestPrice->productStandardPrice;
$product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
$product->priceLowest = $product->lowestPrice->price;
$product->lastSeen = $newestPrice->created_at->format('Y-m-d');
$product->stock = $currentStock->stock;
$product->save(['timestamps' => false]);
$progress->advance();
}
@@ -103,10 +105,6 @@ class ScrapeWebsite extends Command
private function saveProduct(\stdClass $product, Country $country): void
{
// if ($product->skuID == 0) {
// dump([$product->skuID, $product->name]);
// }
// return;
/** @var Product $productModel */
$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 $lowestProductPrice30Days
* @property Date $lastSeen
* @property integer $stock
*/
class Product extends Model
{