Fetch data from ryobi api and save it into database.
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/vendor/
|
||||||
|
.idea
|
||||||
7
composer.json
Normal file
7
composer.json
Normal 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
2121
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
database.sample.sqlite
Normal file
BIN
database.sample.sqlite
Normal file
Binary file not shown.
48
index.php
Normal file
48
index.php
Normal 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);
|
||||||
Reference in New Issue
Block a user