2023-01-02 21:33:36 +05:00
< ? php
2023-02-08 16:59:59 +05:00
function getFromSamson ( $code ){
// echo $code;
$curl = curl_init ( 'https://api.samsonopt.ru/v1/sku/' . $code . '/?api_key=4e2ef85d3ec9e27cc2a148c74a47d804' );
// echo 'https://api.samsonopt.ru/v1/sku/' . $code . '/?api_key=4e2ef85d3ec9e27cc2a148c74a47d804';
$arHeaderList = array ();
$arHeaderList [] = 'Accept: application/json' ;
$arHeaderList [] = 'User-Agent: 4e2ef85d3ec9e27cc2a148c74a47d804' ;
$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 );
return \json :: from_j ( $result );
}
//Если нет картинок...
if ( $page [ 0 ][ 'partner' ] == 'samson' && ! $imagesTovar ){
$result = getFromSamson ( $page [ 0 ][ 'code' ]);
$listImg = $result [ 'data' ][ 0 ][ 'photo_list' ];
//print_r ($listImg);
for ( $i = 0 ; $i < count ( $listImg ); $i ++ ){
$filename = \core :: genpassword ( 30 );
exec ( " wget " . $listImg [ $i ] . " -O /home/cloud/core/img/tk-ligat.ru/tovar/ " . $filename . " .jpg " );
DB :: add ( " INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?) " , array ( $filename , $_GET [ 'id' ] ) );
}
}
if ( $page [ 0 ][ 'partner' ] == 'samson' && ! $har ){
$result = getFromSamson ( $page [ 0 ][ 'code' ]);
$listHar = $result [ 'data' ][ 0 ][ 'facet_list' ];
for ( $i = 0 ; $i < count ( $listHar ); $i ++ ){
$h = $listHar [ $i ];
//проверяем, есть ли значение характеристики в БД, если нет - добавляем, если есть, добавляем ИД и характеристику
$har_sp_id = \DB :: getValue ( " SELECT `id` FROM `tovar_har_sp` WHERE `txt`=? " , $h [ 'name' ]);
if ( ! $har_sp_id ) $har_sp_id = \DB :: add ( " INSERT INTO `tovar_har_sp` (`txt`) VALUES(?) " , $h [ 'name' ]);
\DB :: add ( " INSERT INTO `tovar_har` (`tovar_har_sp_id`, `tovar_id`, `txt`) VALUES(?, ?, ?) " , array ( $har_sp_id , $_GET [ 'id' ], $h [ 'value' ]));
}
}
//print_r(getFromSamson($page[0]['code']));
2023-01-02 21:33:36 +05:00
//Если нет картинок..... Ищем в хрен знает где....
/*
if ( ! $imagesTovar ){
$imgLinks = \DB :: getAll ( " SELECT * FROM `img_links` WHERE `link` LIKE ' " . $page [ 0 ][ 'artikul' ] . " ' " );
for ( $i = 0 ; $i < count ( $imgLinks ); $i ++ ){
$fileName = \core :: genpassword ( 30 );
exec ( " wget " . $imgLinks [ $i ][ 'link' ] . " -O /home/cloud/core/img/tk-ligat.ru/tovar/ " . $fileName . " .jpg " );
$insertId = \DB :: add ( " INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?) " , array ( $fileName , $_GET [ 'id' ] ) );
}
} */
//Проверяем наличие картинок в папке....
2023-02-08 16:59:59 +05:00
/*
2023-01-02 21:33:36 +05:00
$checkImg = \DB :: getAll ( " SELECT * FROM `tovar_img` WHERE `tovar_id`=? " , $_GET [ 'id' ]);
for ( $i = 0 ; $i < count ( $checkImg ); $i ++ )
if ( ! file_exists ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/tovar/' . $checkImg [ $i ][ 'filename' ] . '.jpg' ) ) \DB :: set ( " DELETE FROM `tovar_img` WHERE `filename`=? AND `tovar_id`=? " , array ( $checkImg [ $i ][ 'filename' ], $_GET [ 'id' ] ) );
2023-02-08 16:59:59 +05:00
if ( count ( $checkImg ) == 0 ) exec ( " php /home/cloud/core/parcer/getj.php " . $page [ 0 ][ 'code' ] . " & " ); */
2023-01-02 21:33:36 +05:00
?>