225 lines
7.1 KiB
PHP
Executable File
225 lines
7.1 KiB
PHP
Executable File
<?php
|
|
|
|
ini_set('display_errors', 0);
|
|
|
|
if (!@$_SESSION['user_id']) {
|
|
$smarty->caching = true;
|
|
$smarty->cache_lifetime = 86400;
|
|
}
|
|
|
|
class modClass
|
|
{
|
|
static $content = '';
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
16.05.2025
|
|
Получаем дочерние категории
|
|
---------------------------------------------------------------------- */
|
|
static function getRootCategory()
|
|
{
|
|
|
|
return \DBmysql::getAll("SELECT `id`, `title`, `json` FROM `ctovar` WHERE `status`=? AND `cat`=? ORDER BY `sort`, `title`", [1, 0]);
|
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------------------
|
|
13.04.2025
|
|
Получаем хлебные крошки
|
|
---------------------------------------------------------------------- */
|
|
static function getBreadcrumb()
|
|
{
|
|
|
|
$id=self::$content['cat'];
|
|
//echo $id;
|
|
$i=0;
|
|
while ($id!=0) {
|
|
|
|
$row=\DBmysql::getRow("SELECT `id`, `cat`, `title` FROM `ctovar` WHERE `id`=?", $id);
|
|
$array[$i]['id']=$row['id'];
|
|
$array[$i]['cat']=$row['cat'];
|
|
$array[$i]['title']=$row['title'];
|
|
|
|
$id=$array[$i]['cat'];
|
|
|
|
|
|
$i++;
|
|
}
|
|
|
|
|
|
|
|
if (is_array($array))
|
|
return array_reverse($array);
|
|
}
|
|
|
|
|
|
static function getListCategory()
|
|
{
|
|
|
|
$list = \DBmysql::getAll("SELECT `id`, `title` FROM `ctovar` WHERE `status`=? ORDER BY `sort`, `title`", 1);
|
|
|
|
}
|
|
static function getContent()
|
|
{
|
|
self::$content = DBmysql::getRow("SELECT * FROM `ctovar` WHERE `id`=? LIMIT 1", $_GET['id']);
|
|
self::$content['arr'] = \core::j(self::$content['json']);
|
|
/*$cache ='/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/content_' . $_GET['id'] . '.json';// 'api/modules/content/cache/' . $_SERVER['SERVER_NAME'] . '/' . $_GET['id'] . '.json';
|
|
if (file_exists($cache)) {
|
|
$text = file_get_contents($cache);
|
|
self::$content = \core::j(\core::unzip($text));
|
|
//Чистим кеш через пять дней
|
|
$r = time() - filemtime($cache);
|
|
if ($r > 432000)
|
|
unlink($cache);
|
|
} else {
|
|
$row = \DBmysql::getRow("SELECT * FROM `ctovar` WHERE `id`=? LIMIT 1", $_GET['id']);
|
|
self::$content = $row;
|
|
self::$content['massiv'] = \core::j($row['json']);
|
|
$j = \core::j(self::$content);
|
|
$a = \core::zip($j);
|
|
if (strlen($a)>16) file_put_contents($cache, $a);
|
|
}
|
|
*/
|
|
|
|
}
|
|
static function findChildren()
|
|
{
|
|
\DBmysql::set("UPDATE `content` SET `category`=? WHERE `json` LIKE '%\"parent_category\":" . modClass::$content['massiv']['original_id'] . ",%' AND `category`<>? AND `fix`=?", [$_GET['id'], $_GET['id'], 0]);
|
|
}
|
|
|
|
|
|
static function getTovar($limit, $mini = false, $sort = 'title')
|
|
{
|
|
|
|
|
|
if ($_SESSION['sort']==1){
|
|
|
|
/* $cache = '/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/' . $_GET['id'] . '_' . $_POST['page'] . '_tovar_list1.json';
|
|
if (file_exists($cache)) {
|
|
$text = file_get_contents($cache);
|
|
$array = \core::j(\core::unzip($text));
|
|
//Чистим кеш через пять дней
|
|
$r = time() - filemtime($cache);
|
|
if ($r > 432000)
|
|
unlink($cache);
|
|
} else {
|
|
|
|
$array = \DBmysql::getAll("SELECT `id`, `title`, `json`, `cena` FROM `tovar` WHERE `status`=? AND `ctovar`=? ORDER BY `cena` LIMIT 1000", [1, $_GET['id']]);
|
|
$c = count($array);
|
|
for ($i = 0; $i < $c; $i++) {
|
|
$m = \core::j($array[$i]['json']);
|
|
$array[$i]['img'] = $m['images'][0];
|
|
$array[$i]['artikul'] = ($m['artikul']) ? $m['artikul'] : $m['code'];
|
|
}
|
|
$j = \core::j($array);
|
|
$a = \core::zip($j);
|
|
if (strlen($a)>16) file_put_contents($cache, $a);
|
|
}*/
|
|
|
|
}else{
|
|
|
|
|
|
$array = DBmysql::getAll("SELECT tovar.id, tovar.title, tovar.json, cenaarendy.ch4 as cena FROM tovar JOIN cenaarendy ON tovar.id=cenaarendy.tovar_id WHERE `status`=? AND `ctovar`=? LIMIT 1000", [1, $_GET['id']]);
|
|
for ($i = 0; $i < count($array); $i++) $array[$i]['images'] = core::j($array[$i]['json'])['images'][0];
|
|
|
|
/*$cache = '/tmp/cache/' . $_SERVER['SERVER_NAME'] . '/' . $_GET['id'] . '_' . $_POST['page'] . '_tovar_list.json';
|
|
if (file_exists($cache)) {
|
|
$text = file_get_contents($cache);
|
|
$array = \core::j(\core::unzip($text));
|
|
//Чистим кеш через пять дней
|
|
$r = time() - filemtime($cache);
|
|
if ($r > 432000)
|
|
unlink($cache);
|
|
} else {
|
|
|
|
$array = \DBmysql::getAll("SELECT `id`, `title`, `json`, `cena` FROM `tovar` WHERE `status`=? AND `ctovar`=? LIMIT 1000", [1, $_GET['id']]);
|
|
$c = count($array);
|
|
for ($i = 0; $i < $c; $i++) {
|
|
$m = \core::j($array[$i]['json']);
|
|
$array[$i]['img'] = $m['images'][0];
|
|
$array[$i]['artikul'] = ($m['artikul']) ? $m['artikul'] : $m['code'];
|
|
}
|
|
$j = \core::j($array);
|
|
$a = \core::zip($j);
|
|
if (strlen($a)>16) file_put_contents($cache, $a);
|
|
}*/
|
|
}
|
|
|
|
|
|
|
|
return $array;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
modClass::getContent();
|
|
|
|
$limit = 12;
|
|
|
|
//Получаем дочерние категории
|
|
require_once('api/modules/ctovar/tovar_category_get_children_category.php');
|
|
|
|
|
|
//Получаем количество всех товаров этой категории
|
|
$total = \DBmysql::getAll("SELECT COUNT(*) FROM `tovar` WHERE `status`=1 AND `ctovar`=?", modClass::$content['id'])[0]['COUNT(*)'];
|
|
//print_r($total);
|
|
$amt = ceil($total / $limit);
|
|
$smarty->assign('amt', $amt);
|
|
$tovar = modClass::getTovar($limit);
|
|
$smarty->assign('tovar', $tovar);
|
|
|
|
|
|
|
|
|
|
|
|
$smarty->assign('content', modClass::$content);
|
|
$smarty->assign('total', $total);
|
|
|
|
$smarty->assign('rootCategory', modClass::getRootCategory());
|
|
|
|
|
|
|
|
|
|
if ($_SESSION['dostup']=='a'){
|
|
$smarty->assign('all_cats', \DBmysql::getAll("SELECT `id`, `title` FROM `ctovar` WHERE `status`=1 ORDER BY `title`"));
|
|
|
|
|
|
|
|
//Ищем фильтры
|
|
$f=\DBmysql::getAll("SELECT `id`, `title` FROM `sort2` WHERE `category`=? ORDER BY `title`",modClass::$content['id']);
|
|
$smarty->assign('flist', $f);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Перемещалка
|
|
|
|
$list=\DBmysql::getAll("SELECT `title` FROM `sort2` WHERE `category`=?", modClass::$content['id']);
|
|
$c=count($list);
|
|
for ($i=0; $i<$c; $i++)
|
|
\DBmysql::set("UPDATE `tovar` SET `ctovar`=? WHERE `title` LIKE '" . $list[$i]['title'] . "' AND `ctovar` <> ?", [modClass::$content['id'],modClass::$content['id']]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$url='https://' . $_SERVER['SERVER_NAME'] . '/tovar/' . $_GET['id'];
|
|
|
|
if (modClass::$content['title']&&modClass::$content['status']==1){
|
|
//Пишем в сайтмап
|
|
$id=\DBmysql::getValue("SELECT `id` FROM `sitemap` WHERE `link`=? LIMIT 1", $url);
|
|
if (!$id)\DBmysql::add("INSERT INTO `sitemap` (`link`, `t`, `site`, `status`) VALUES (?,?,?,?)", [$url, time(), $_SERVER['SERVER_NAME'], 1]);
|
|
}
|
|
|
|
|
|
$smarty->assign('getBreadcrumb', modClass::getBreadcrumb());
|
|
?>
|