Fetch data from ryobi api and save it into database.
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
/vendor/
|
||||||
|
.idea
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"guzzlehttp/guzzle": "^7.0",
|
||||||
|
"symfony/var-dumper": "^7.0",
|
||||||
|
"illuminate/database": "^11.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+2121
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -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