// Define script folder
define('FOLDER', './../');
// Require classes and includes
require_once('./privat/privat.php');
require_once('./includes/common.php');
require_once('./class/show/class.XML.php');
// Start sessions
shop_session();
// Personal param
$gUser['currency'] = 'UAH'; // EUR | RUR | UAH | USD
$gUser['vendor'] = '80'; // ID характеристики "Производитель" Введите сюда ID своей характеристики (посмотреть в менеджере характеристик)
// Go!
main();
/**
* Function main
**/
function main()
{
global $gData, $gOptions, $gUser, $gTpl, $gStartPoint;
// Get start point for time
$gStartPoint = run_time(0);
// Connect to Data
$gData = data_connect();
$prec = $gOptions['main_prec'];
$url = rtrim($gOptions['attr_base_url'],'/');
$curr = $gOptions['main_base_curr'];
// Start XML file
$xml_file = './tmp/'.md5(session_id()).'.xml';
$xml = new XML(SHOP_CHARSET, $xml_file, 'Windows-1251', false);
$xml->PutXML('<!DOCTYPE yml_catalog SYSTEM "shops.dtd">');
$xml->StartTag('yml_catalog', array('date' => date("Y-m-d H:i", strtotime($gOptions['main_update_time']))));
$xml->StartTag('shop');
$xml->PutTag('name', array(), $gOptions['attr_shop_name']);
$xml->PutTag('company', array(), $gOptions['attr_shop_org']);
$xml->PutTag('url', array(), $gOptions['attr_shop_url']);
$xml->StartTag('currencies');
$xml->PutTag('currency', array('id' => $gUser['currency'], 'rate' => '1'));
$xml->PutTag('currency', array('id' => 'USD', 'rate' => 'CBRF'));
$xml->PutTag('currency', array('id' => 'EUR', 'rate' => 'CBRF'));
$xml->CloseTag('currencies');
// Topics
$topic = $gData->GetCatForXML();
$rows = $gData->GetNumRows($topic);
if ( $rows == 0 ) exit;
$xml->StartTag('categories');
for ( $n = 1; $n <= $rows; $n++ )
{
$hash = $gData->FetchRow($topic);
$xml->PutTag('category', array('id' => $hash[0], 'parentId' => $hash[7]), $hash[1]);
}
$xml->CloseTag('categories');
// Request topic & goods
$xml->StartTag('offers');
$gData->DataSeek($topic, 0);
for ( $n = 1; $n <= $rows; $n++ )
{
$hash = $gData->FetchRow($topic);
$topic_id = $hash[0];
// Create Goods
$goods = $gData->GetGoodsForXML($hash[0]);
$goods_rows = $gData->GetNumRows($goods);
for ( $i = 1; $i <= $goods_rows; $i++ )
{
$g_hash = $gData->FetchRow($goods);
$price = ( $g_hash[11] > 0 ) ? $g_hash[11] : $g_hash[6];
$status = ( $g_hash[4] == 0 || $g_hash[4] == 4) ? 'true' : 'false';
$link = ( strlen($g_hash[15]) > 0 ) ? 'goods_'.urlencode($g_hash[15]).'.htm' : 'goods.php?id='.$g_hash[0];
$xml->StartTag('offer', array('id' => $g_hash[0], 'available' => $status));
$xml->PutTag('url', array(), $url.'/'.$link);
$xml->PutTag('price', array(), number_format($price, $prec, "." ,""));
$xml->PutTag('currencyId', array(), $gUser['currency']);
$xml->PutTag('categoryId', array(), $topic_id);
$img_file = ( is_file('./../files/store'.$g_hash[0].'.jpg') ) ? 'files/store'.$g_hash[0].'.jpg' : 'files/store_default.jpg';
$xml->PutTag('picture', array(), $url.'/'.$img_file);
$xml->PutTag('name', array(), $g_hash[3]);
$xml->PutTag('vendor', array(), $gData->GetInfoValueGoods($g_hash[0], $gUser['vendor']));
$xml->PutTag('vendorCode', array(), $g_hash[1]);
$xml->PutTag('description', array(), html2text($g_hash[5]));
$xml->CloseTag('offer');
}
}
$xml->CloseTag('offers');
$xml->CloseTag('shop');
$xml->CloseTag('yml_catalog');
$xml->Free();
header('Content-type: text/xml; charset=Windows-1251');
echo implode('',file($xml_file));
@unlink($xml_file);
}