while ($arElement = $rsElements->getNextElement()){
$arItem = $arElement->getFields();
$arItem['PROPERTIES'] = $arElement->getProperties();
$arItem['PRICE'] = CPrice::GetBasePrice($arItem['ID']);
foreach ($arItem['PROPERTIES'] as $code => $arProp){
$arItem['PROPERTY_VALUES'][$code][0] = array("VALUE" => array("TYPE"=>"LIST", "XML_ID"=>$arProp['VALUE_XML_ID']));
}
unset($arItem['IBLOCK_ID']);
unset($arItem['SECTION_ID']);
debug($arItem['PROPERTIES']);
debug($arItem['PROPERTY_VALUES']);
global $USER;
$insert = array(
"MODIFIED_BY" => $USER->GetID(), // элемент изменен текущим пользователем
"IBLOCK_SECTION_ID" => false, // элемент лежит в корне раздела
"IBLOCK_ID" => $iblock_id,
"PROPERTY_VALUES"=> $arItem['PROPERTY_VALUES'],
"NAME" => $arItem['NAME'],
"ACTIVE" => "Y", // активен
"PREVIEW_TEXT" => array('VALUE' => $arItem['PREVIEW_TEXT'], 'TYPE' => $arItem['PREVIEW_TEXT_TYPE']),
"DETAIL_TEXT" => array('VALUE' => $arItem['DETAIL_TEXT'], 'TYPE' => $arItem['DETAIL_TEXT_TYPE']),
"PREVIEW_PICTURE" => CFile::MakeFileArray($arItem['PREVIEW_PICTURE']),
"DETAIL_PICTURE" => CFile::MakeFileArray($arItem['DETAIL_PICTURE'])
);
$el = new CIBlockElement;
if($new_id = $new_id = $el->Add($insert)){
debug("New ID: ".$new_id);
CPrice::SetBasePrice($new_id, $arItem['PRICE']['PRICE'], $arItem['PRICE']['CURRENCY']);
}
else
debug("Error: ".$el->LAST_ERROR);
debug($new_id);
} |