[bitrix] export photos

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
CModule::IncludeModule("iblock");
$arSelect = Array(
"ID", "IBLOCK_ID", "NAME", "DETAIL_PICTURE", "PROPERTY_CML2_ARTICLE" //"PROPERTY_MODEL", "PROPERTY_COLOR", "PROPERTY_SIZE", "PROPERTY_MORE_PHOTO"
);
$arFilter = Array("IBLOCK_ID" => 12, "!PROPERTY_CML2_ARTICLE" => false, "ACTIVE" => "Y");
$res = CIBlockElement::GetList(Array("ID" => "DESC"), $arFilter, false, array("nTopCount" => 1), $arSelect);
$fw = fopen($_SERVER["DOCUMENT_ROOT"] . "/upload/products_with_photo.xml", "w+");
fwrite($fw, "<?xml version=\"1.0\" encoding=\"UTF8\"?>\n");
fwrite($fw, "<items>");
while ($fields = $res->GetNext()) {
$pid = $fields["ID"];
$images = "";
fwrite($fw, "<product article=\"" . $fields["PROPERTY_CML2_ARTICLE_VALUE"] . "\" name=\"" . $fields["NAME"] . "\">\n");
if (!empty($fields["DETAIL_PICTURE"])) {
$arFile = CFile::GetFileArray($fields["DETAIL_PICTURE"]);
if($arFile["SRC"]
&& file_exists($_SERVER["DOCUMENT_ROOT"] . $arFile["SRC"])) {
$images .= "\t\t<photo>" . $arFile["SRC"] . "</photo>\n";
}
}
$db_props = CIBlockElement::GetProperty(12, $fields["ID"], array("sort" => "asc"), Array("CODE"=>"MORE_PHOTO"));
while($ar_props = $db_props->Fetch())
{
if (!empty($ar_props["VALUE"])){
$arFile2 = CFile::GetFileArray($ar_props["VALUE"]);
if($arFile2["SRC"]
&& file_exists($_SERVER["DOCUMENT_ROOT"] . $arFile2["SRC"])) {
$images .= "\t\t<photo>" . $arFile2["SRC"] . "</photo>\n";
}
}
}
if($images) {
fwrite($fw, "\t<images>\n");
fwrite($fw, $images);
fwrite($fw, "\t</images>\n");
}
fwrite($fw, "</product>\n");
}
fwrite($fw, "</items>");
fclose($fw);