CModule::IncludeModule("iblock");
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/upload/full_export_iblock_12/products.xml", "w+");
fwrite($fp, "<" . "?xml version=\"1.0\" encoding=\"UTF8\"?" . ">\n");
fwrite($fp, "<products>\n");
$new_path = "/upload/full_export_iblock_12/products_files";
$res = CIBlockElement::GetList(
array("show_counter" => "desc"),
array("IBLOCK_ID" => 12, "ACTIVE"=>"Y", "!PROPERTY_CML2_ARTICLE" => false),
false,
false,
array("ID", "IBLOCK_ID", "NAME", "CODE", "PREVIEW_PICTURE", "DETAIL_PICTURE"
/*,"PROPERTY_IS_NEW", "PROPERTY_IS_BESTSELLER", "PROPERTY_IS_SALE", "PROPERTY_IS_ARCHIVE"*/)
);
while ($ar_res = $res->Fetch()) {
fwrite($fp, "<item>\n");
fwrite($fp, "<name>".str_replace("&", "&", $ar_res["NAME"])."</name>\n");
fwrite($fp, "<code>".$ar_res["CODE"]."</code>\n");
if($ar_res["PREVIEW_PICTURE"]) {
fwrite($fp, "<preview_picture_int>" . $ar_res["PREVIEW_PICTURE"] . "</preview_picture_int>\n");
$pPicture = CFile::GetPath($ar_res["PREVIEW_PICTURE"]);
$bdirName = str_replace("/upload/iblock","",$pPicture);
$new_dir_name = $_SERVER["DOCUMENT_ROOT"] . $new_path . dirname($bdirName);
if(!is_dir($new_dir_name)) mkdir($new_dir_name);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $pPicture, $_SERVER["DOCUMENT_ROOT"] . $new_path . $bdirName);
if($bSaved)
fwrite($fp, "<preview_picture>" . $new_path . $bdirName . "</preview_picture>\n");
}
if($ar_res["DETAIL_PICTURE"]) {
$dPicture = CFile::GetPath($ar_res["DETAIL_PICTURE"]);
fwrite($fp, "<detail_picture_int>" . $ar_res["DETAIL_PICTURE"] . "</detail_picture_int>\n");
$bdirName = str_replace("/upload/iblock","",$dPicture);
$new_dir_name = $_SERVER["DOCUMENT_ROOT"] . $new_path . dirname($bdirName);
if(!is_dir($new_dir_name)) mkdir($new_dir_name);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $dPicture, $_SERVER["DOCUMENT_ROOT"] . $new_path . $bdirName);
if($bSaved)
fwrite($fp, "<detail_picture>" . $new_path . $bdirName . "</detail_picture>\n");
}
$db_props = CIBlockElement::GetProperty(12, $ar_res["ID"], array("sort" => "asc"), Array("CODE"=>"MORE_PHOTO"));
$images = "";
while($ar_props = $db_props->Fetch()) {
if($ar_props["VALUE"]) {
$images .= "<file_int>" . $ar_props["VALUE"] . "</file_int>\n";
$file = CFile::GetPath($ar_props["VALUE"]);
$bdirName = str_replace("/upload/iblock","",$file);
$new_dir_name = $_SERVER["DOCUMENT_ROOT"] . $new_path . dirname($bdirName);
if(!is_dir($new_dir_name)) mkdir($new_dir_name);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $file, $_SERVER["DOCUMENT_ROOT"] . $new_path . $bdirName);
if($bSaved)
$images .= "<file>" . $new_path . $bdirName . "</file>\n";
}
}
if(!empty($images)) {
fwrite($fp, "<more_pictures>\n");
fwrite($fp, $images);
fwrite($fp, "</more_pictures>\n");
}
/*
if($ar_res["PROPERTY_IS_NEW_VALUE"])
fwrite($fp, "<new>".$ar_res["PROPERTY_IS_NEW_VALUE"]."</new>\n");
if($ar_res["PROPERTY_IS_BESTSELLER_VALUE"])
fwrite($fp, "<bestseller>".$ar_res["PROPERTY_IS_BESTSELLER_VALUE"]."</bestseller>\n");
if($ar_res["PROPERTY_IS_SALE_VALUE"])
fwrite($fp, "<sale>".$ar_res["PROPERTY_IS_SALE_VALUE"]."</sale>\n");
if($ar_res["PROPERTY_IS_ARCHIVE_VALUE"])
fwrite($fp, "<archive>".$ar_res["PROPERTY_IS_ARCHIVE_VALUE"]."</archive>\n");
*/
// if($ar_res["PROPERTY_MEGAVISOR_VALUE"])
// fwrite($fp, "<megavisor>".$ar_res["PROPERTY_MEGAVISOR_VALUE"]."</megavisor>\n");
// if($ar_res["PROPERTY_VIDEO_URL_VALUE"])
// fwrite($fp, "<video>".$ar_res["PROPERTY_VIDEO_URL_VALUE"]."</video>\n");
fwrite($fp, "</item>\n");
}
fwrite($fp, "</products>\n");
fclose($fp);