2022-12-11 13:55:49 +05:00
< ? php
2023-07-12 20:02:20 +05:00
ini_set ( 'display_errors' , 0 );
@ mkdir ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/cert' , 0700 );
@ mkdir ( 'img/' . $_SERVER [ 'SERVER_NAME' ] . '/tovar/square' , 0700 );
2023-08-14 09:15:58 +05:00
if ( ! $_SESSION [ 'user_id' ]) $smarty -> caching = true ;
2023-07-12 20:02:20 +05:00
$smarty -> cache_lifetime = 86400 ;
$me = \core :: checkMe ();
function setKeywords ()
{
$token = 'y0_AgAAAAABiU4jAAn8iwAAAADkWpkSbFJu1kVDTGCi5DQIA4h6RaMwKpA' ;
$url = (( ! empty ( $_SERVER [ 'HTTPS' ])) ? 'https' : 'http' ) . '://' . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ]; // . $_SERVER['REQUEST_URI']
$params = array (
'ids' => '88262601' ,
'metrics' => 'ym:s:visits' ,
'dimensions' => 'ym:s:searchPhrase' ,
'date1' => '365daysAgo' ,
'date2' => 'today' ,
'filters' => " ym:pv:URL==' " . $url . " ' "
);
2023-08-14 09:15:58 +05:00
2023-07-12 20:02:20 +05:00
$ch = curl_init ( 'https://api-metrika.yandex.net/stat/v1/data?' . urldecode ( http_build_query ( $params )));
curl_setopt ( $ch , CURLOPT_HTTPHEADER , array ( 'Authorization: OAuth ' . $token ));
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , false );
curl_setopt ( $ch , CURLOPT_HEADER , false );
$res = curl_exec ( $ch );
curl_close ( $ch );
$res = json_decode ( $res , true );
$words = array ();
foreach ( $res [ 'data' ] as $row ) {
$words [] = $row [ 'dimensions' ][ 0 ][ 'name' ];
}
for ( $i = 0 ; $i < count ( $words ); $i ++ ) {
$id = \DB :: getValue ( " SELECT `id` FROM `tovar_keywords` WHERE `tovar_id`=? AND `txt`=? LIMIT 1 " , array ( $_GET [ 'id' ], $words [ $i ]));
2023-08-14 09:15:58 +05:00
if ( ! $id ) \DB :: set ( " INSERT INTO `tovar_keywords` (`tovar_id`, `txt`) VALUES (?, ?) " , array ( $_GET [ 'id' ], $words [ $i ]));
2023-07-12 20:02:20 +05:00
}
}
2023-08-14 09:15:58 +05:00
if ( date ( " H:i " ) == '00:00' ) setKeywords ();
2023-07-12 20:02:20 +05:00
2023-02-28 21:22:24 +05:00
2023-03-05 20:22:21 +05:00
/* ----------------------------------------------------------------------
01.03 . 2023
Получаем историю просмотров
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$tovarHistory = \DB :: getAll ( " SELECT `id`, `title`, `cena` FROM `tovar` WHERE `id` IN ( SELECT `tovar_id` FROM `tovar_history` WHERE `session_id`=? ORDER BY RAND()) AND `status`=1 LIMIT 20 " , $me );
for ( $i = 0 ; $i < count ( $tovarHistory ); $i ++ ) {
2023-08-14 09:15:58 +05:00
$tovarHistory [ $i ][ 'img_id' ] = \DB :: getValue ( " SELECT `id` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1 " , $tovarHistory [ $i ][ 'id' ]);
2023-07-12 20:02:20 +05:00
}
//print_r($tovarHistory);
$smarty -> assign ( 'tovarHistory' , $tovarHistory );
2023-02-28 21:22:24 +05:00
/* ----------------------------------------------------------------------
28.02 . 2023
Получаем коментарии
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$comments = \DB :: getAll ( " SELECT * FROM `tovar_otzyv` WHERE `tovar_id`=? AND `status`=1 ORDER BY `t` DESC " , $_GET [ 'id' ]);
2023-08-14 09:15:58 +05:00
for ( $i = 0 ; $i < count ( $comments ); $i ++ ) $comments [ $i ][ 'fio' ] = \DB :: getValue ( " SELECT `fio` FROM `users` WHERE `id`=? " , $comments [ $i ][ 'user_id' ]);
2023-07-12 20:02:20 +05:00
$smarty -> assign ( 'comments' , $comments );
$smarty -> assign ( 'inc_comments' , 'api/modules/tovar_show/comments.html' );
2023-02-28 21:22:24 +05:00
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12 . 2022
Получаем данные о товаре
---------------------------------------------------------------------- */
2023-01-07 18:55:55 +05:00
2023-07-12 20:02:20 +05:00
$page = \DB :: getAll ( " SELECT * FROM `tovar` WHERE `id`=? LIMIT 1 " , $_GET [ 'id' ]);
$page [ 0 ][ 'date' ] = date ( 'd.m.Y' , @ $page [ 0 ][ 't' ]);
2023-03-05 20:22:21 +05:00
2023-07-12 20:02:20 +05:00
$triDnya = time () - $page [ 0 ][ 'cena_d' ];
if ( $_SERVER [ 'SERVER_NAME' ] == 'tk-ligat.ru' ) {
if ( $page [ 0 ][ 'partner' ] == 'samson' ) {
require_once 'api/modules/tovar_show/get_price_samson.php' ;
$page [ 0 ][ 'cena' ] = ( $triDnya > 259200 ) ? getCenaApiSamson ( $page [ 0 ][ 'id' ], $page [ 0 ][ 'code' ]) : $page [ 0 ][ 'cena' ];
2023-08-14 09:15:58 +05:00
//sortTovar($page[0]['id'], $page[0]['code']);
2023-07-12 20:02:20 +05:00
}
if ( $page [ 0 ][ 'partner' ] == 'leopak' ) {
require_once 'api/modules/tovar_show/get_price_leopak.php' ;
$page [ 0 ][ 'cena' ] = ( $triDnya > 259200 ) ? getCenaLeopak ( $page [ 0 ][ 'donor' ], $page [ 0 ][ 'id' ]) : $page [ 0 ][ 'cena' ];
2023-03-05 20:22:21 +05:00
2023-07-12 20:02:20 +05:00
}
if ( $page [ 0 ][ 'partner' ] == 'deznet' ) {
require_once 'api/modules/tovar_show/get_price_deznet.php' ;
$page [ 0 ][ 'cena' ] = ( $triDnya > 259200 ) ? getCenaLeopak ( $page [ 0 ][ 'donor' ], $page [ 0 ][ 'id' ]) : $page [ 0 ][ 'cena' ];
}
}
2023-03-05 20:22:21 +05:00
2023-07-12 20:02:20 +05:00
/* ----------------------------------------------------------------------
08.07 . 2023
Штрихкод
---------------------------------------------------------------------- */
$page [ 0 ][ 'barcode' ] = \DB :: getValue ( " SELECT `barcode` FROM `tovar_barcode` WHERE `tovar_id`=? " , $_GET [ 'id' ]);
2023-03-05 20:22:21 +05:00
2023-01-07 18:55:55 +05:00
/* ----------------------------------------------------------------------
03.01 . 2023
Хлебные крошки
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$smarty -> assign ( 'Breadcrumb' , \core :: getBreadcrumb ( 'tovar_category' , $page [ 0 ][ 'category' ]));
2023-01-07 18:55:55 +05:00
/* ----------------------------------------------------------------------
03.01 . 2023
Получаем картинку категории
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$smarty -> assign ( 'catImg' , \DB :: getValue ( " SELECT `filename` FROM `tovar_category_img` WHERE `tovar_category_id`=? " , $page [ 0 ][ 'category' ]));
2023-01-07 18:55:55 +05:00
2022-12-24 21:12:23 +05:00
/* ----------------------------------------------------------------------
17.12 . 2022
Получаем данные о последней цене на товар
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
if ( ! $page [ 0 ][ 'cena' ])
$page [ 0 ][ 'cena' ] = \DB :: getAll ( " SELECT `cena`, `t` FROM `tovar_price_history` WHERE `status`=1 AND `tovar_id`=? ORDER BY `t` DESC LIMIT 1 " , $_GET [ 'id' ])[ 0 ][ 'cena' ];
\DB :: set ( " UPDATE `tovar` SET `cena`=? WHERE `id`=? LIMIT 1 " , array ( $page [ 0 ][ 'cena' ], $_GET [ 'id' ]));
2022-12-24 21:12:23 +05:00
2023-07-12 20:02:20 +05:00
$smarty -> assign ( 'page' , $page );
2022-12-11 13:55:49 +05:00
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12 . 2022
Получаем картинки
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$imagesTovar = \DB :: getAll ( " SELECT * FROM `tovar_img` WHERE `tovar_id`=? " , $_GET [ 'id' ]);
if ( ! $imagesTovar && $page [ 0 ][ 'partner' ] == " deznet " ) {
$filename = \core :: genpassword ( 30 );
exec ( " wget " . $page [ 0 ][ 'linkimg' ] . " -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' ]));
$imagesTovar = \DB :: getAll ( " SELECT * FROM `tovar_img` WHERE `tovar_id`=? " , $_GET [ 'id' ]);
}
2023-02-26 21:57:01 +05:00
2023-07-12 20:02:20 +05:00
$smarty -> assign ( 'imagesTovar' , $imagesTovar );
$countImg = count ( $imagesTovar );
\DB :: set ( " UPDATE `tovar` SET `countImg`=? WHERE `id`=? " , array ( $countImg , $_GET [ 'id' ]));
2023-01-02 21:33:36 +05:00
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12 . 2022
Получаем характеристики из БД
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$har = \DB :: getAll ( " SELECT * FROM `tovar_har` WHERE `tovar_id`=? " , $_GET [ 'id' ]);
for ( $i = 0 ; $i < count ( $har ); $i ++ )
$har [ $i ][ 'opt' ] = \DB :: getValue ( " SELECT `txt` FROM `tovar_har_sp` WHERE `id`=? " , $har [ $i ][ 'tovar_har_sp_id' ]);
$smarty -> assign ( 'har' , $har );
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12 . 2022
Пишем историю
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$session_id = ( $_SESSION [ 'user_id' ]) ? $_SESSION [ 'user_id' ] : session_id ();
2022-12-17 18:15:09 +05:00
unset ( $id );
2023-07-12 20:02:20 +05:00
$id = \DB :: getValue ( " SELECT `id` FROM `tovar_history` WHERE `tovar_id`=? AND `session_id`=? " , array ( $_GET [ 'id' ], $session_id ));
2023-08-14 09:15:58 +05:00
if ( ! $id ) \DB :: add ( " INSERT INTO `tovar_history` (`tovar_id`, `session_id`, `t`) VALUES (?, ?, ?) " , array ( $_GET [ 'id' ], $session_id , time ()));
2022-12-11 13:55:49 +05:00
/* ----------------------------------------------------------------------
2023-02-08 16:59:59 +05:00
05.02 . 2023
ищем похожие товары - этой же категории , но рандомно
2022-12-11 13:55:49 +05:00
---------------------------------------------------------------------- */
2023-07-12 20:02:20 +05:00
$rndTovar = \DB :: getAll ( " SELECT * FROM `tovar` WHERE `category`=? ORDER BY RAND() LIMIT 10 " , $page [ 0 ][ 'category' ]);
2023-08-14 09:15:58 +05:00
for ( $i = 0 ; $i < count ( $rndTovar ); $i ++ ) $rndTovar [ $i ][ 'img_id' ] = \DB :: getValue ( 'SELECT `id` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1' , $rndTovar [ $i ][ 'id' ]);
2022-12-11 13:55:49 +05:00
2023-08-14 09:15:58 +05:00
//$rndTovar[$i]['cena'] = \DB::getValue('SELECT `cena` FROM `tovar_price_history` WHERE `status`=1 AND `tovar_id`=? ORDER BY `id` DESC LIMIT 1', $rndTovar[$i]['id']);
$smarty -> assign ( 'rndTovar' , $rndTovar );
2022-12-11 13:55:49 +05:00
?>