Fetch data from ryobi api and save it into database.
This commit is contained in:
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