$childrenCategory=\DB::getAll("SELECT `id`, `title`, `img`, `kolvo` FROM `tovar_category` WHERE `status` = 1 AND `category` = ? ORDER BY `title`",$pieces[0]);
if(!$childrenCategory)$childrenCategory=\DB::getAll("SELECT `id`, `title`, `img`, `kolvo` FROM `tovar_category` WHERE `status` = 1 AND `category` = ? ORDER BY `title`",$categoryInfo[0]['category']);
for($i=0;$i<count($childrenCategory);$i++)$childrenCategory[$i]['children']=\DB::getAll("SELECT `id`, `title`, `img`, `kolvo` FROM `tovar_category` WHERE `category`=? AND `status`=1 ORDER BY `title`",$childrenCategory[$i]['id']);
$total=\DB::getValue("SELECT COUNT(*) FROM `tovar` WHERE (`category` = ? OR `multicat` LIKE '%-".$categoryInfo[0]['code']."-%') AND `status`=1",$pieces[0]);
\DB::set("UPDATE `tovar_category` SET `kolvo`=? WHERE `id`=?",array($total,$pieces[0]));//обновляем количество товара в категории
$childrenTovar=\DB::getAll("SELECT `id`, `title`, `linkimg`, `cena` FROM `tovar` WHERE (`category` = ? OR `multicat` LIKE '%-".$categoryInfo[0]['code']."-%') AND `status`=1 ORDER BY `title` LIMIT $art, $kol",$pieces[0]);
\DB::set("UPDATE `tovar` SET `category`=? WHERE `multicat` LIKE '%-".$categoryInfo[0]['code']."-%'",$pieces[0]);
}else{
$total=\DB::getValue("SELECT COUNT(*) FROM `tovar` WHERE `category` = ? AND `status`=1",$pieces[0]);
\DB::set("UPDATE `tovar_category` SET `kolvo`=? WHERE `id`=?",array($total,$pieces[0]));//обновляем количество товара в категории
$childrenTovar=\DB::getAll("SELECT `id`, `title`, `linkimg`, `cena` FROM `tovar` WHERE `category` = ? AND `status`=1 ORDER BY `title` LIMIT $art, $kol",$pieces[0]);
for($i=0;$i<count($childrenTovar);$i++)$childrenTovar[$i]['img_id']=\DB::getValue("SELECT `id` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1",$childrenTovar[$i]['id']);