Start working on handling multiple countries at once
This commit is contained in:
@@ -41,6 +41,7 @@ class Migrate extends Command
|
||||
$this->createStocksTable();
|
||||
$this->addColumns();
|
||||
$this->createCountriesTable();
|
||||
$this->index();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
@@ -170,4 +171,12 @@ class Migrate extends Command
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
Capsule::schema()->table('products', function (Blueprint $table) {
|
||||
$table->integer('skuID')->unique(false)->change();
|
||||
$table->unique(['skuID', 'country_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,16 +56,16 @@ class ScrapeWebsite extends Command
|
||||
$products = Product::all();
|
||||
$progress->setMaxSteps(count($products));
|
||||
$progress->start();
|
||||
// foreach($products as $product) {
|
||||
// $newestPrice = $product->newestPrice;
|
||||
// $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->save(['timestamps' => false]);
|
||||
// $progress->advance();
|
||||
// }
|
||||
foreach($products as $product) {
|
||||
$newestPrice = $product->newestPrice;
|
||||
$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->save(['timestamps' => false]);
|
||||
$progress->advance();
|
||||
}
|
||||
$progress->finish();
|
||||
$output->writeln('');
|
||||
$output->writeln('Update prices - DONE');
|
||||
|
||||
Reference in New Issue
Block a user