<?
define('STOP_STATISTICS', true);
define('NO_KEEP_STATISTIC', 'Y');
define('NO_AGENT_STATISTIC', 'Y');
define('DisableEventsCheck', true);
define('BX_SECURITY_SHOW_MESSAGE', true);
define('NOT_CHECK_PERMISSIONS', true);

$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__, 1);
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php'); 
CModule::IncludeModule('iblock');

$car_search_res = CIBlockElement::GetList( [ "ID" => "ASC" ], [ "IBLOCK_ID" => IBLOCK_ID_CATALOG_CARS_NEW, ], false, [], [] );

$c = 0;
while($car_search_ob = $car_search_res->GetNextElement())
{
	$car_existed = $car_search_ob->GetFields();
	$car_existed['PROPERTIES'] = $car_search_ob->GetProperties();

	$title = $car_existed['NAME']." ".$car_existed['PROPERTIES']['MODIFICATION_YEAR']['VALUE'];
	$code = CUtil::translit( str_replace(["&quot;", " ", "+"], ['"', "-", "-plus-"], $title), "ru", [ "max_len" => 255, "change_case" => "L", "replace_space" => "-", "replace_other" => "-", "safe_chars" => "-" ] );

	print $code."\n";

	$car_update_element = new CIBlockElement;
	$car_update_result = $car_update_element->Update($car_existed['ID'], [ "CODE" => $code ]);
	$c++;
}

print "\n\ntotal ".$c;

die();

?>