<?
//<title>Simple Yandex Market Export</title>
//IncludeModuleLangFile( $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/catalog/export_setup_templ.php' );
Cmodule::IncludeModule('catalog');
global $APPLICATION, $USER;
//require( 'simplemarket_functions.php' );
header("Content-Type: text/xml; charset=windows-1251");
//$condition = new ConditionWork( 'conditionsExport.json' );
$path = '/bitrix/catalog_export/';
$temporaryFile = 'tempExport.php';
$IBLOCK_ID = 3;
//$BASE_CURRENCY = CCurrency::GetBaseCurrency();
$foldersIDList = array( '1326','1321','1320','1323','1324','1316','1315','1314','1313','1311','1313','1319','1327','1328','1332','1323','1331','1330','1319','1303','1269','1267','1262','1258','1257','1249','1248','1188','1187','1186','1185','1181','1178','1177','1176','1170','1169','1164','1163','1162','1143','1142','1141','1137','1134','1124','1109','1106','1097','1093','1087','1086','1085','1084','1078','1077','1074','1072','1071','1068','1067','1066','1065','1064','1060','1057','1056','1055','1003','1002','1000','999','998','997','996','995','943','942','941','940','929','924','916','915','914','913','912','911','905','903','900','899','898','896','895','894','893','892','891','890','887','884','883','882','880','879','878','877','876','875','874','873','764','762','761','758','757','756','754','753','752','751','750','749','748','747','746','745','742','734','733','732','731','730','729','728','727','726','725','724','723','722','721','719','718','705','704','703','702','701','697','696','695','693','692','689','688','687','686','685','684','683','682','681','680','679','678','677','676','675','674','673','672','671','670','669','668','667','666','665','664','663','662','661','660'
,'1268','1245','1244','1243','1242','1241','1240','1239','1238','1237','1236','1235','1234','1233','1232','1231','1230','1229','1227','1226','1225','1224','1223','1222','1221','1220','1219','1218','1217','1216','1215','1214','1213','1212','1211','1210','1209','1208','1207','1206','1205','1204','1203','1202','1201','1200','1199','1198','1197','1196','1195','1194','1193','1192','1191','1190','1184','1183','1182','1180','1179','1175','1174','1149','1148','1147','1146','1145','1088','1081','1080','1079','991','989','988','987','985','984','983','775','774','773','772','771','770','769','768','767','766','736','735',
'1168','1167','1166','1165','1098','1095','1094','1082','1049','1005','1004','1048','1123');
/*
отключено
'1009','1026','1044','1035','1034','1028','1032','1031','1029','1027','1008','1030','1033','1025','1023','1042','1045','1043','1041','1040','1037','1007','1139','1022','1019','1016','1015','1013','1069','1012','1020','1038','1014','1017','1089','1092','1090','1011','1010','1018','1021','1024','1039'
*/
$arr_ne_dveri = array('1268','1245','1244','1243','1242','1241','1240','1239','1238','1237','1236','1235','1234','1233','1232','1231','1230','1229','1227','1226','1225','1224','1223','1222','1221','1220','1219','1218','1217','1216','1215','1214','1213','1212','1211','1210','1209','1208','1207','1206','1205','1204','1203','1202','1201','1200','1199','1198','1197','1196','1195','1194','1193','1192','1191','1190','1184','1183','1182','1180','1179','1175','1174','1149','1148','1147','1146','1145','1088','1081','1080','1079','991','989','988','987','985','984','983','775','774','773','772','771','770','769','768','767','766','736','735','1168','1167','1166','1165','1139','1098','1095','1094','1092','1090','1089','1082','1069','1049','1048','1045','1044','1043','1042','1041','1040','1039','1038','1037','1035','1034','1033','1032','1031','1030','1029','1028','1027','1026','1025','1024','1023','1022','1021','1020','1019','1018','1017','1016','1015','1014','1013','1012','1011','1010','1009','1008','1007','1005','1004','1123');
$arr_id_mejk_dverej = array('1326','1321','1320','1323','1324','1316','1315','1314','1313','1311','1313','1319','1327','1328','1332','1323','1331','1330','1262','1249','1248','1188','1187','1186','1185','1181','1178','1177','1176','1170','1169','1163','1143','1142','1141','1137','1134','1109','1106','1097','1093','1087','1086','1085','1084','1078','1077','1074','1072','1071','1068','1067','1066','1065','1064','1057','1056','1055','1003','1002','1000','999','998','997','996','995','943','942','941','940','929','924','916','905','903','900','899','898','896','895','894','893','892','891','890','887','884','883','882','880','879','878','877','876','875','874','873','728','727','726','725','724','723','722','721','719','718','705','704','703','702','701','697','696','695','693','692','689','688','687','686','685','684','683','682','681','680','679','678','677','676','675','674','673','672','671','670','669','668','667','666','665','664','663','662','661','660');
CCatalogDiscountSave::Disable();
$data = "<? header(\"Content-Type: text/xml; charset=windows-1251\");?>" . '<? echo "<"."?xml version=\"1.0\" encoding=\"windows-1251\"?".">"?>' . "<!DO CTYPE yml_catalog SYSTEM \"shops.dtd\">\r\n
<yml_catalog date=\"" . date( "Y-m-d H:i" ) . "\">\r\n
<shop>\r\n
<name>Интернет-магазин</name>\r\n
<company>Интернет-магазин</company>\r\n
<url>{$siteURL}</url>\r\n
<currencies>\r\n
<currency id=\"RUR\" rate=\"1\" />\r\n
</currencies>\r\n";
$arFilter = Array( 'IBLOCK_ID' => $IBLOCK_ID, "ACTIVE" => "Y", "IBLOCK_ACTIVE" => "Y", "GLOBAL_ACTIVE" => "Y" );
$db_list = CIBlockSection::GetList( array(), $arFilter, true );
$data .= "<categories>\r\n";
while( $ar_result = $db_list->GetNext() )
{
$catName = yandex_text2xml( $ar_result['NAME'] );
if( in_array( $ar_result['ID'], $foldersIDList ) )
{
if( empty( $ar_result['IBLOCK_SECTION_ID'] ) )
{
$data .= "<category id=\"{$ar_result['ID']}\">{$catName}</category>\r\n";
} else {
$data .= "<category id=\"{$ar_result['ID']}\" parentId=\"{$ar_result['IBLOCK_SECTION_ID']}\">{$catName}</category>\r\n";
}
}
}
$data .= "</categories>\r\n";
$arSelect = array( "ID", "NAME", "DETAIL_PAGE_URL", "DETAIL_PICTURE", "PREVIEW_PICTURE", "PREVIEW_TEXT" );
$arFilter = array( "IBLOCK_ID" => $IBLOCK_ID, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y" );
// Remove after checking
$arFilter['ID']='22807';
// Remove after checking
$res = CIBlockElement::GetList( Array(), $arFilter, false, false, $arSelect );
$data .= "<offers>\r\n";
while($ob = $res->GetNextElement())
{
$arFields = $ob->GetFields();
$arProps = $ob->GetProperties();
$ID = $arFields['ID'];
$categoryID = $arFields['IBLOCK_SECTION_ID'];
$productURL = $siteURL . $arFields['DETAIL_PAGE_URL'];
$productName = yandex_text2xml( $arFields['NAME'] );
$productText = yandex_text2xml( $arFields['PREVIEW_TEXT'] );
if( intval( $arFields["DETAIL_PICTURE"] ) > 0 || intval( $arFields["PREVIEW_PICTURE"] ) > 0 )
{
$pictNo = intval( $arFields["DETAIL_PICTURE"] );
if( $pictNo <= 0 )
{
$pictNo = intval( $arFields["PREVIEW_PICTURE"] );
}
if( $ar_file = CFile::GetFileArray( $pictNo ) )
{
if( substr( $ar_file["SRC"], 0, 1 ) == "/" )
{
$strFile = $siteURL . implode( "/", array_map( "rawurlencode", explode( "/", $ar_file["SRC"] ) ) );
}
elseif( preg_match( "/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $ar_file["SRC"], $match ) )
{
$strFile = "http://".$match[2].'/'.implode( "/", array_map( "rawurlencode", explode( "/", $match[3] ) ) );
} else {
$strFile = $ar_file["SRC"];
}
}
}
if( !empty( $strFile ) )
{
$image = "<picture>" . $strFile . "</picture>\r\n";
} else {
$image = '';
}
if( !in_array( $categoryID, $foldersIDList ) )
{
continue;
}
$available = 'true';
$rsProducts = CCatalogProduct::GetList( array(), array( 'ID' => $ID ), false, false, array( 'ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO' ) );
if( $arProduct = $rsProducts->Fetch() )
{
$arProduct['QUANTITY'] = doubleval( $arProduct['QUANTITY'] );
if( 0 >= $arProduct['QUANTITY'] && 'Y' == $arProduct['QUANTITY_TRACE'] )
{
$available = 'false';
}
}
/////////////////////////////////////////////////////////////
// print_r(CCatalogDiscount::GetByID(1));
$dbPrice = CPrice::GetList(
array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"),
array("PRODUCT_ID" => $ID),
false,
false,
array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")
);
while ($arPrice = $dbPrice->Fetch()) {
$arDiscounts = CCatalogDiscount::GetDiscountByPrice(
$arPrice["ID"],
//$USER->GetUserGroupArray(),
array(2),
"N"
);
print_r($arPrice["ID"]);
$discountPrice = CCatalogProduct::CountPriceWithDiscount(
$arPrice["PRICE"],
$arPrice["CURRENCY"],
$arDiscounts
);
$arPrice["DISCOUNT_PRICE"] = $discountPrice;
print_r($arPrice);
}
die();
if( $arPrice = CCatalogProduct::GetOptimalPrice( $ID, 1, array( 2 ), 'N', array() ) ){
print_r($arPrice);
die();
$minPrice = $arPrice['DISCOUNT_PRICE'];
} else {
continue;
}
// Производитель
// Приоритет Связь с инфоблоком 29, иначе бере поле MANUFACTURER
//print_r($arProps);
$manufName = '';
if(isset($arProps['REF_MANUF']['VALUE']) && !empty($arProps['REF_MANUF']['VALUE'])){
// Выборка производителя
$rManuf = CIBlockElement::GetByID($arProps['REF_MANUF']['VALUE']);
if($aManuf = $rManuf->GetNext()){
$manufName = $aManuf['NAME'];
}
}
if(empty($manufName) && isset($arProps['MANUFACTURER']['VALUE'][0]) && !empty($arProps['MANUFACTURER']['VALUE'][0])){
$manufName = $arProps['MANUFACTURER']['VALUE'][0];
}
if(!empty($manufName)) $manufName = "<vendor>".yandex_text2xml($manufName)."</vendor>\r\n";
// Параметры.
// - цвет
$colorName = '';
if(isset($arProps['COLOR_RELAT']['VALUE']) && !empty($arProps['COLOR_RELAT']['VALUE'])){
// Выборка цвета
$rColor = CIBlockElement::GetByID($arProps['COLOR_RELAT']['VALUE']);
if($aColor = $rColor->GetNext()){
$colorName = "<param name=\"Цвет\">".yandex_text2xml($aColor['NAME'])."</param>\r\n";
}
}
// - высота
$heightVal = '';
if(isset($arProps['HEIGHT']['VALUE']) && !empty($arProps['HEIGHT']['VALUE'])){
$heightVal = "<param name=\"Высота\" unit=\"мм\">".yandex_text2xml($arProps['HEIGHT']['VALUE'])."</param>\r\n";
}
// - ширина
$widthVal = '';
if(isset($arProps['WIDTH']['VALUE']) && !empty($arProps['WIDTH']['VALUE'])){
$widthVal = "<param name=\"Ширина\" unit=\"мм\">".yandex_text2xml($arProps['WIDTH']['VALUE'])."</param>\r\n";
}
// - Стекло
$glassVal = '';
if(isset($arProps['WITH_GLASS']['VALUE']) && !empty($arProps['WITH_GLASS']['VALUE'])){
if($arProps['WITH_GLASS']['VALUE_ENUM_ID'] == 319){
$isGlass = "да";
}else{
$isGlass = "нет";
}
$glassVal = "<param name=\"Стекло\">".$isGlass."</param>\r\n";
}
// - Стиль
$styleName = '';
if(isset($arProps['REF_STYLE']['VALUE']) && !empty($arProps['REF_STYLE']['VALUE'])){
// Выборка производителя
$rStyle = CIBlockElement::GetByID($arProps['REF_STYLE']['VALUE']);
if($aStyle = $rStyle->GetNext()){
$styleVal = "<param name=\"Стиль\">".yandex_text2xml($aStyle['NAME'])."</param>\r\n";
}
}
// print_r($arProps['COLOR_RELAT']['VALUE']);
// die();
//REF_STYLE
// <vendor>Nokia</vendor>
// <param name="Размер экрана" unit="дюйм">27</param>
$data .= "<offer id=\"{$ID}\" available=\"{$available}\">\r\n";
$data .= $manufName;
$data .= "<url>{$productURL}</url>\r\n";
$data .= "<price>{$minPrice}</price>\r\n";
$data .= "<currencyId>RUB</currencyId>\r\n";
$data .= "<categoryId>{$categoryID}</categoryId>\r\n";
$data .= $image;
$data .= "<name>{$productName}</name>\r\n";
$data .= "<description>{$productText}</description>\r\n";
// params
$data .= $colorName.$heightVal.$widthVal.$glassVal.$styleVal;
$data .= "<sales_notes>Предоплата 50%";
if(!in_array($categoryID,$arr_ne_dveri)){
$data .= ", наличные, б/н расчет, карты";
}
$data .= "</sales_notes>\r\n";
if(in_array($categoryID,$arr_id_mejk_dverej)){
$data .= "<country_of_origin>Россия</country_of_origin>\r\n";
$data .= "<manufacturer_warranty>true</manufacturer_warranty>\r\n";
}
$data .= "</offer>";
}
$data .= "</offers>\r\n
</shop>\r\n
</yml_catalog>";
$fileName = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/catalog_export/yandex_dvertorg.php';
saveData( $data, $fileName );
CCatalogDiscountSave::Enable();
|