Add stock to product.
This commit was merged in pull request #49.
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user