<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
ini_set("max_execution_time", "120");
set_time_limit(0);
CModule::IncludeModule('iblock');
use Bitrix\Main\Loader;
Loader::includeModule("highloadblock");
use Bitrix\Highloadblock as HL;
use Bitrix\Main\Entity;
$destDir = $_SERVER['DOCUMENT_ROOT'].'/scripts/export/';
$arPartDir = array();
$hlbl = 5; // Указываем ID нашего highloadblock блока к которому будет делать запросы.
$BID = 5; // Указываем ID нашего инфоблока к которому будет делать запросы.
$hlblock = HL\HighloadBlockTable::getById($hlbl)->fetch();
$entity = HL\HighloadBlockTable::compileEntity($hlblock);
$entity_data_class = $entity->getDataClass();
function MakeBrandFolder($arBrand, $path, $BID)
{
static $io = false;
if ($io === false)
{
$io = CBXVirtualIo::GetInstance();
}
$path .= $arBrand['NAME'].'/';
$arSelect = Array("ID", "IBLOCK_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE","NAME", "PROPERTY_BREND", "PROPERTY_ARTNUMBER","PROPERTY_MORE_PHOTO");
//обрабатываю только доступные к покупке товары
$rsElement = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $BID, 'PROPERTY_BREND' => $arBrand['UF_XML_ID'],'CATALOG_AVAILABLE'=>'Y'), false, false, $arSelect);
while ($arElement = $rsElement->Fetch())
{
$artNumber = $arElement["PROPERTY_ARTNUMBER_VALUE"];
if($artNumber !="")
{
$t=1;
if ($arElement['PREVIEW_PICTURE'] > 0) {
$arPicture = CFile::GetFileArray($arElement['PREVIEW_PICTURE']);
$inIOP = $io->GetFile($io->RelativeToAbsolutePath($arPicture['SRC']));
if (preg_match('/.png/', $arPicture['ORIGINAL_NAME']))
$newName = $artNumber.'_'.$t.'.png';
else
$newName = $artNumber.'_'.$t.'.jpg';
$outIO = $io->GetFile($path.$newName);
if (!$outIO->IsExists()) {
$content = $inIO->GetContents();
if ($content !== null) {
$outIO->PutContents($content);
}
}
}
$t=2;
if ($arElement['DETAIL_PICTURE'] > 0) {
$arPicture = CFile::GetFileArray($arElement['DETAIL_PICTURE']);
$inIOD = $io->GetFile($io->RelativeToAbsolutePath($arPicture['SRC']));
if (preg_match('/.png/', $arPicture['ORIGINAL_NAME']))
$newName = $artNumber.'_'.$t.'.png';
else
$newName = $artNumber.'_'.$t.'.jpg';
$outIO = $io->GetFile($path.$newName);
if (!$outIO->IsExists()) {
$content = $inIO->GetContents();
if ($content !== null) {
$outIO->PutContents($content);
}
}
}
if(!empty($arElement['PROPERTY_MORE_PHOTO_VALUE']))
{
foreach ($arElement['PROPERTY_MORE_PHOTO_VALUE'] as $key => $photo)
{
$t++;
$arPicture = CFile::GetFileArray($photo);
$inIOM = $io->GetFile($io->RelativeToAbsolutePath($arPicture['SRC']));
if (preg_match('/.png/', $arPicture['ORIGINAL_NAME']))
$newName = $artNumber.'_'.$t.'.png';
else
$newName = $artNumber.'_'.$t.'.jpg';
$outIO = $io->GetFile($path.$newName);
if (!$outIO->IsExists()) {
$content = $inIO->GetContents();
if ($content !== null) {
$outIO->PutContents($content);
}
}
}
}
}
}
$io->CreateDirectory($path);
}
if (CheckDirPath($destDir)) {
$arBrands = array();
$rsData = $entity_data_class::getList(array(
"select" => array("*"),
"order" => array("UF_NAME" => "ASC"),
"filter" => array("UF_SITE"=>"11") // Задаем параметры фильтра выборки
));
while($arData = $rsData->Fetch())
{
$arBrands[$arData['ID']] = array(
'ID' => $arData['ID'],
'UF_XML_ID' => $arData['UF_XML_ID'],
'NAME' => $arData['UF_NAME']
);
}
foreach ($arBrands as $arBrand) {
MakeBrandFolder($arBrand, $destDir, $BID);
}
}