150 lines
4.9 KiB
PHP
Executable File
150 lines
4.9 KiB
PHP
Executable File
<?php
|
||
ini_set('display_errors', 0);
|
||
ini_set('max_execution_time', 111300);
|
||
header('Content-type: text/xml; charset=utf-8');
|
||
$smarty->caching = false;
|
||
$smarty->cache_lifetime = 172800;//Два дня
|
||
|
||
|
||
|
||
|
||
function ekr($text)
|
||
{ // ФУНКЦИЯ очистки кода
|
||
|
||
$old1 = ["&", ":", '"'];#Ищем вредное ">",, "<"
|
||
|
||
$new1 = ["&", ":", '"'];#Меняем на полезное">", , "<"
|
||
|
||
$text = str_replace($old1, $new1, $text);#Собсно сама замена =)
|
||
|
||
return $text;
|
||
}#Возвращение результата наших извращений =)
|
||
|
||
|
||
|
||
|
||
$xml = '<?xml version="1.0" encoding="UTF-8"?>
|
||
<yml_catalog date="' . date("Y-m-d") . 'T14:37:38+03:00">
|
||
<shop>
|
||
<name>ТК ЛигаТ</name>
|
||
<company>ТК ЛигаТ</company>
|
||
<url>https://' . $_SERVER['SERVER_NAME'] . '</url>
|
||
<platform>YurecCore</platform>
|
||
<categories>';
|
||
|
||
|
||
|
||
|
||
|
||
$tovar_cat = (class_exists('DBmysql')) ? \DBmysql::getAll("SELECT `id`, `category`, `title` FROM `tovar_category` WHERE `status`=1 AND `site`=?", $_SERVER['SERVER_NAME']) : \DB::getAll("SELECT `id`, `category`, `title` FROM `tovar_category` WHERE `status`=1 AND `site`=?", $_SERVER['SERVER_NAME']);
|
||
|
||
|
||
for ($i = 0; $i < count($tovar_cat); $i++) {
|
||
if ($tovar_cat[$i]['category'] == 0)
|
||
$xml .= '<category id="' . $tovar_cat[$i]['id'] . '">' . $tovar_cat[$i]['title'] . '</category>';
|
||
else
|
||
$xml .= '<category id="' . $tovar_cat[$i]['id'] . '" parentId="' . $tovar_cat[$i]['category'] . '">' . $tovar_cat[$i]['title'] . '</category>';
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
$tovar_list = (class_exists('DBmysql')) ? \DBmysql::getAll("SELECT `id`, `json`, `code`, `category`, `cena`, `old_cena`, `title`, `txt`, `images` FROM `tovar` WHERE `status`=1 AND `site`=? AND `images` IS NOT NULL AND `cena` IS NOT NULL", $_SERVER['SERVER_NAME']) : \DB::getAll("SELECT `id`, `category`, `title` FROM `tovar_category` WHERE `status`=1 AND `site`=?", $_SERVER['SERVER_NAME']);
|
||
|
||
|
||
|
||
|
||
$xml .= '</categories><delivery-options><option cost="200" days="14"/></delivery-options><pickup-options><option cost="200" days="14"/></pickup-options><offers>';
|
||
|
||
|
||
$c = count($tovar_list);
|
||
for ($i = 0; $i < $c; $i++) {
|
||
|
||
$tovar_list[$i]['yaid'] = \DBmysql::getValue("SELECT `yandexcategoryid` FROM `tovar_category` WHERE `id`=?", $tovar_list[$i]['category']);
|
||
$tovar_list[$i]['title'] = ekr($tovar_list[$i]['title']);
|
||
$tovar_list[$i]['txt'] = ekr($tovar_list[$i]['txt']);
|
||
$tovar_list[$i]['massiv'] = \core::j($tovar_list[$i]['json']);
|
||
$tovar_list[$i]['img'] = \core::j($tovar_list[$i]['images']);
|
||
//Получаем характеристики...
|
||
unset($m);
|
||
unset($harlist);
|
||
unset($piclist);
|
||
$m = \DBmysql::getAll("SELECT tovar_har.txt, tovar_har.tovar_har_sp_id, tovar_har_sp.txt as sp FROM `tovar_har` INNER JOIN tovar_har_sp ON tovar_har.tovar_har_sp_id = tovar_har_sp.id WHERE `tovar_id`=?", $tovar_list[$i]['id']);
|
||
$tovar_list[$i]['hars'] = $m;
|
||
|
||
$pics = $tovar_list[$i]['img'];
|
||
$c2 = count(@$pics);
|
||
for ($j = 0; $j < $c2; $j++) {
|
||
@$piclist .= '<picture>https://' . $_SERVER['SERVER_NAME'] . '/img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . $tovar_list[$i]['id'] . '/' . $pics[$j]['filename'] . '.' . $pics[$j]['tip'] . '</picture>';
|
||
}
|
||
|
||
$c3 = count($m);
|
||
for ($j = 0; $j < $c3; $j++) {
|
||
@$harlist .= '<param name="' . ekr($m[$j]['sp']) . '">' . $m[$j]['txt'] . '</param>';
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
$xml .= '<offer id="' . $tovar_list[$i]['id'] . '" type="vendor.model">
|
||
<typePrefix>' . $tovar_list[$i]['title'] . '</typePrefix>
|
||
<vendor>' . $tovar_list[$i]['massiv']['brand'] . '</vendor>
|
||
<model>' . @$tovar_list[$i]['massiv']['code'] . '</model>
|
||
<url>https://' . $_SERVER['SERVER_NAME'] . '/tovar_show/' . $tovar_list[$i]['id'] . '</url>
|
||
<price>' . $tovar_list[$i]['cena'] . '</price>
|
||
|
||
<currencyId>RUR</currencyId>
|
||
<categoryId>' . $tovar_list[$i]['yaid'] . '</categoryId>' . $piclist . '
|
||
<delivery>true</delivery>
|
||
<delivery-options>
|
||
<option cost="300" days="1" order-before="18"/>
|
||
</delivery-options>
|
||
<description>
|
||
<![CDATA[
|
||
' . $tovar_list[$i]['txt'] . '
|
||
]]>
|
||
</description>
|
||
' . $harlist . '
|
||
|
||
<barcode>' . $tovar_list[$i]['massiv']['barcode'] . '</barcode>
|
||
</offer>';
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
$smarty->assign('tovar_cat', $tovar_cat);
|
||
$smarty->assign('tovar_list', $tovar_list);
|
||
$xml .= '</offers>
|
||
</shop>
|
||
</yml_catalog>';
|
||
|
||
|
||
//print_r($tovar_cat);
|
||
//echo $xml;
|
||
$t = time();
|
||
$filename = 'cache/' . $t . '.xml';
|
||
|
||
|
||
|
||
$fh = fopen($filename, 'w');
|
||
|
||
fwrite($fh, $xml);
|
||
|
||
fclose($fh);
|
||
|
||
|
||
exec("zip /www/static/yml/$t.zip cache/$t.xml");
|
||
//echo '<a href="https://static.yurecnt.ru/yml/' . $t . '.zip">Скачать</a>';
|
||
|
||
|
||
?>
|