<?//
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("catalog");
CModule::IncludeModule("sale");
CModule::IncludeModule("iblock");
set_time_limit(0);
$SETUP_FILE_NAME="/yandex_tmp.xml";
$MAIN_FILE_NAME="/yandex.market.xml";
function MakeWordsFromString($s)
{
if (strlen($s)<=19) return $s;
else return substr($s, 0, 19)." ".MakeWordsFromString(substr($s, 19, strlen($s)));
}
global $USER;
$bTmpUserCreated = False;
if (!isset($USER))
{
$bTmpUserCreated = True;
$USER = new CUser;
}
function yandex_text2xml($text, $bHSC = false)
{
if ($bHSC)
$text = htmlspecialchars(htmlspecialcharsback(htmlspecialcharsback($text)));
$text = ereg_replace("[\x1-\x8\xB-\xC\xE-\x1F]", "", $text);
$text = ereg_replace("'", "'", $text);
return $text;
}
$strExportErrorMessage = "";
if (!$fp = @fopen($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, "wb"))
$strExportErrorMessage .= "Can not open \"".$_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME."\" file for writing.";
if (strlen($strExportErrorMessage)<=0)
{
@fwrite($fp, '<?xml version="1.0" encoding="windows-1251"?>'.chr(10));
@fwrite($fp, '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">'.chr(10));
@fwrite($fp, '<yml_catalog date="'.Date("Y-m-d H:i").'">'.chr(10));
@fwrite($fp, '<shop>'.chr(10));
@fwrite($fp, '<name>DTT</name>'.chr(10));
@fwrite($fp, '<company>Discovery Telecom</company>'.chr(10));
@fwrite($fp, '<url>http://'.SITE_SERVER_NAME.'/</url>'.chr(10));
$strTmp = "<currencies>".chr(10);
$strTmp.= '<currency id="RUR" rate="1"/>'.chr(10);
$strTmp.= "</currencies>".chr(10);
@fwrite($fp, $strTmp);
// категории
$strTmpCat.= "<categories>".chr(10);
$rsSec = CIBlockSection::GetList(array("ID"=>"ASC"), array("IBLOCK_ID"=>15));
while ($arSec = $rsSec->GetNext()):
if ($arSec['DEPTH_LEVEL']==1)
$strTmpCat.= '<category id="'.$arSec['ID'].'">'.$arSec['NAME'].'</category>'.chr(10);
if ($arSec['IBLOCK_SECTION_ID'])
$allSec[$arSec['ID']]['PARENT'] = $arSec['IBLOCK_SECTION_ID'];
else
$allSec[$arSec['ID']] = $arSec['ID'];
endwhile;
$strTmpCat.= "</categories>".chr(10);
@fwrite($fp, $strTmpCat);
// номенклатура
@fwrite($fp, "<offers>".chr(10));
$rsOffers = CIBlockElement::GetList(Array("ID"=>"ASC"), Array("IBLOCK_ID"=>15, "ACTIVE"=>"Y"), false, false, Array("ID", "SECTION", "DETAIL_PAGE_URL", "DETAIL_PICTURE", "CATALOG_GROUP_2", "PROPERTY_NAME_RU", "PROPERTY_ANONS_RU", "PROPERTY_VENDOR"));
while ($arOffer = $rsOffers->GetNext()):
/*?><pre><?print_r($arOffer);?></pre><?*/
if ($arOffer['CATALOG_PRICE_2'] <= 0) continue;
if (empty($arOffer['IBLOCK_SECTION_ID'])) continue;
// если подраздел - для товара выставить раздел верхнего уровня
if ($allSec[$arOffer['IBLOCK_SECTION_ID']]['PARENT'])
$arOffer['IBLOCK_SECTION_ID'] = $allSec[$arOffer['IBLOCK_SECTION_ID']]['PARENT'];
if (IntVal($arOffer["CATALOG_QUANTITY"])>0)
$avial='available="true"';
else
$avial='available="false"';
$strTmpOff.= '<offer id="'.$arOffer["ID"].'" type="vendor.model" '.$avial.'>'.chr(10);
$strTmpOff.= '<url>http://'.SITE_SERVER_NAME.htmlspecialchars($arOffer["DETAIL_PAGE_URL"]).'</url>'.chr(10);
// конвертировать цену в рубли и округлить до целого
$price = round(CCurrencyRates::ConvertCurrency($arOffer['CATALOG_PRICE_2'], "USD", "RUR"));
$strTmpOff.= "<price>".$price."</price>".chr(10);
$strTmpOff.= "<currencyId>RUR</currencyId>".chr(10);
$strTmpOff.= "<categoryId>".$arOffer['IBLOCK_SECTION_ID']."</categoryId>".chr(10);
if ($arOffer['DETAIL_PICTURE']):
$arrImg = CFile::_GetImgParams($arOffer['DETAIL_PICTURE'], $iSizeWHTTP=0, $iSizeHHTTP=0);
$strTmpOff.="<picture>http://".SITE_SERVER_NAME.$arrImg['SRC']."</picture>".chr(10);
endif;
$rsBrand = CIBlockElement::GetList(Array(), Array("IBLOCK_ID"=>13, "ID"=>$arOffer["PROPERTY_VENDOR_VALUE"]), false, false, Array("NAME"));
$arBrand=$rsBrand->GetNext();
$strTmpOff.= "<vendor>".$arBrand["NAME"]."</vendor>".chr(10);
$strTmpOff.= "<model>".htmlspecialchars(trim(str_replace($arBrand["NAME"],"",$arOffer["PROPERTY_NAME_RU_VALUE"])))."</model>".chr(10);
&nb |