Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //title: Присваивание картинок
- \Bitrix\Main\Loader::includeModule('iblock');
- function rbsCheckDir($dirPath, $dirName)
- {
- $collectionDir = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
- return is_dir($collectionDir.$dirPath) && $dirName != '.' && $dirName != '..';
- }
- $collectionDirSourse = $_SERVER["DOCUMENT_ROOT"]."/upload/collection_images/";
- $ib = 17;
- $dir = opendir($collectionDirSourse);
- $arLog = [];
- while($brand = readdir($dir))
- {
- if(rbsCheckDir($brand, $brand))
- {
- $brandDb = CIblockSection::GetList(['ID' => 'asc'], ['IBLOCK_ID' => $ib, '=NAME' => $brand], false, ['ID', 'NAME']);
- $brandDir = opendir($collectionDirSourse.$brand);
- while($obBrand = $brandDb->GetNext())
- {
- $collectionImg = false;
- while($collection = readdir($brandDir))
- {
- if(rbsCheckDir($brand.'/'.$collection, $collection))
- {
- $collDb = CIblockSection::GetList(['ID' => 'asc'], ['IBLOCK_ID' => $ib, '=NAME' => $collection, 'IBLOCK_SECTION_ID' => $obBrand['ID']], false, ['ID', 'NAME']);
- $collectionDir = opendir($collectionDirSourse.$brand.'/'.$collection.'/web/');
- while($obCol = $collDb->GetNext())
- {
- while($image = readdir($collectionDir))
- {
- if(strpos($image, '.jpg') !== false)
- {
- $dbElem = CIblockElement::GetList([],
- ['IBLOCK_ID' => $ib, '=CODE' => str_replace('.jpg', '', $image), 'IBLOCK_SECTION_ID' => $obCol['ID']], false, false,
- ['ID', 'NAME', 'CODE']);
- if($obElem = $dbElem->GetNext())
- {
- $el = new CIBlockElement;
- $picPath = $collectionDirSourse.$brand.'/'.$collection.'/web/'.$image;
- $fileArray = CFile::MakeFileArray($picPath);
- $arLoadProductArray = array(
- "PREVIEW_PICTURE" => $fileArray,
- "DETAIL_PICTURE" => $fileArray,
- );
- //print_r($fileArray);
- if(!$el->Update($obElem['ID'], $arLoadProductArray))
- $arLog[$obElem['ID']] = $el->LAST_ERROR;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- print_r($arLog);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement