Fetch data from ryobi api and save it into database.

This commit is contained in:
Krzysztof Płaczek
2024-03-18 07:33:46 +01:00
parent 12f5554068
commit cb9eae65c7
5 changed files with 2178 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/vendor/
.idea

7
composer.json Normal file
View File

@@ -0,0 +1,7 @@
{
"require": {
"guzzlehttp/guzzle": "^7.0",
"symfony/var-dumper": "^7.0",
"illuminate/database": "^11.0"
}
}

2121
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

BIN
database.sample.sqlite Normal file

Binary file not shown.

48
index.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
include_once 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => __DIR__ . '/database.sample.sqlite',
'prefix' => '',
]);
$capsule->setAsGlobal();
$client = new GuzzleHttp\Client();
$page = 0;
do {
$res = $client->request('POST', 'https://pl.ryobitools.eu/api/product-listing/get-products', [
'form_params' => [
"includePreviousPages" => false,
"pageIndex" => $page,
"pageSize" => 100,
"cultureCode" => "pl-PL",
]
]);
$page++;
$responseObject = json_decode($res->getBody()->getContents());
$products = $responseObject->products;
foreach ($products as $product) {
Capsule::table('product')->updateOrInsert([
'skuID' => $product->skuID,
], [
'name' => $product->name,
'price' => $product->productPrice,
'availableQuantity' => $product->availableQuantity,
'stock' => $product->stock,
'categories' => json_encode($product->categories),
'image' => $product->image,
'subTitle' => $product->subTitle,
'variantCode' => $product->variantCode,
'modelCode' => $product->modelCode,
'url' => $product->url,
'productStandardPrice' => $product->productStandardPrice,
'lowestProductPrice30Days' => $product->lowestProductPrice30Days,
]);
echo ".";
}
echo "\n";
} while ((bool)$responseObject->canLoadMore);