Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created July 23, 2013 08:39
Show Gist options
  • Save stansidel/6060846 to your computer and use it in GitHub Desktop.
Save stansidel/6060846 to your computer and use it in GitHub Desktop.
Updating all the elements of an IBlock (Bitrix). To use in the code console.
<?
if (CModule::IncludeModule("iblock")) {
$res = CIBlockElement::GetList(array(), array('IBLOCK_ID'=>23, 'ACTIVE'=>'Y'), false, false, array('NAME', 'ID', 'IBLOCK_ID', 'PROPERTY_FLAT_NUMBER'));
//$arElement = $res->Fetch();
//echo '<pre>'; var_dump($arElement); echo '</pre>';
while($arElement = $res->GetNext()) {
preg_match('(\d+)', ($arElement['NAME']), $matches);
$flatNumber = null;
if(count($matches) > 0) {
$flatNumber = intval($matches[0]);
CIBlockElement::SetPropertyValues($arElement['ID'], $arElement['IBLOCK_ID'], $flatNumber, 'FLAT_NUMBER');
} else {
$flatNumber = "!!! Не обновлено";
}
echo "{$arElement['NAME']} ({$arElement['ID']}) => {$flatNumber}<br/>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment