Save prices to the database to the history table. Added simple browse script.

This commit is contained in:
Krzysztof Płaczek
2024-03-24 09:01:36 +01:00
parent cb9eae65c7
commit 16614316ec
3 changed files with 54 additions and 2 deletions

View File

@@ -4,6 +4,10 @@ include_once 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
if (php_sapi_name() !== 'cli') {
echo 'Execute this script in cli only';
exit;
}
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
@@ -30,7 +34,6 @@ do {
'skuID' => $product->skuID,
], [
'name' => $product->name,
'price' => $product->productPrice,
'availableQuantity' => $product->availableQuantity,
'stock' => $product->stock,
'categories' => json_encode($product->categories),
@@ -39,6 +42,14 @@ do {
'variantCode' => $product->variantCode,
'modelCode' => $product->modelCode,
'url' => $product->url,
'updated_at' => date('Y-m-d'),
]);
$databaseProduct = Capsule::table('product')->where('skuID', '=', $product->skuID)->first();
Capsule::table('price')->updateOrInsert([
'product_id' => $databaseProduct->id,
'created_at' => date('Y-m-d'),
], [
'price' => $product->productPrice,
'productStandardPrice' => $product->productStandardPrice,
'lowestProductPrice30Days' => $product->lowestProductPrice30Days,
]);