core/parcer/samson/cat.php

75 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-08-14 09:15:58 +05:00
<?php
ini_set('display_errors', 1);
$_SERVER['SERVER_NAME'] = 'tk-ligat.ru';
require_once('/home/cloud/core/set/tk-ligat.ru.php');
require_once('/home/cloud/core/api/php/db.php');
$curl = curl_init('https://api.samsonopt.ru/v1/category/?api_key=3f8f720d5a2923a1ff02be994090b002');
$arHeaderList = array();
$arHeaderList[] = 'Accept: application/json';
$arHeaderList[] = 'User-Agent: string';
$arHeaderList[] = 'Accept-Encoding: gzip';
curl_setopt($curl, CURLOPT_HTTPHEADER, $arHeaderList);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
$result = curl_exec($curl);
curl_close($curl);
require_once('/home/cloud/core/api/php/json.php');
$massiv = json::from_j($result)['data'];
function subcats($massiv, $code, $id){
for ($i = 0; $i < count($massiv); $i++) {
if ($massiv[$i]['parent_id'] == $code) {
$id1 = DB::getValue("SELECT `id` FROM `tovar_category` WHERE `title`=? AND `category`=?", array($massiv[$i]['name'], $id));
if ($id1) {
DB::set("UPDATE `tovar_category` SET `status`=1, `code`=?, `partner`=?, `img`=? WHERE `id`=?", array(
$massiv[$i]['id'],
'samson',
$massiv[$i]['photo_list'][0],
$id1
));
} else {
DB::add("INSERT INTO `tovar_category` (`title`, `status`, `category`, `code`, `partner`, `img`) VALUES (?, ?, ?, ?, ?, ?)", array(
$massiv[$i]['name'],
1,
$id,
$massiv[$i]['id'],
'samson',
$massiv[$i]['photo_list'][0]
)
);
}
}
}
}
$subkanc=DB::getAll("SELECT * FROM `tovar_category` WHERE `partner` ='samson'");
for ($i=0; $i<count($subkanc); $i++){
subcats($massiv, $subkanc[$i]['code'], $subkanc[$i]['id']);
}
print_r($massiv);
//24921 - канцтовары
?>