Skip to content

Commit

Permalink
Update ProductDB.php
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhancelebi authored Nov 25, 2022
1 parent caa266c commit 12517cb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ProductDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function reset_data(){
file_put_contents(__DIR__ . "/../products.json", json_encode([]));
}

static function update_product_data()
static function update_product_data()
{
echo "Product data getting updated" . PHP_EOL;

Expand All @@ -104,6 +104,8 @@ static function update_product_data()
$continue = true;
$since_id = 0;

$product_data = [];

while ($continue) {

echo "Page: " . $page . " downloaded" .PHP_EOL;
Expand All @@ -116,12 +118,11 @@ static function update_product_data()

if (isset($data["products"]) && count($data["products"])) {
foreach ($data["products"] as $row) {
\Lib\ProductDB::add_product($row["id"], $row["variants"][0]["id"], $row["variants"][0]["sku"],$row);
$product_data[] = ["id" => $row["id"], "sku" => $row["variants"][0]["sku"], "variation_id" => $row["variants"][0]["id"],'data'=>$row];
$since_id = $row["id"];
}
}


if (!isset($data["products"]) || count($data["products"]) == 0) {
$continue = false;
}
Expand All @@ -131,9 +132,12 @@ static function update_product_data()
sleep(1);
}

file_put_contents(__DIR__ . "/../products.json", json_encode($product_data));

echo "Product data updated" . PHP_EOL;
}


static function product_count(){
$products = json_decode(file_get_contents(__DIR__ . "/../products.json"), true);
return count($products);
Expand Down

0 comments on commit 12517cb

Please sign in to comment.