/*****************************************************************************************************************/ /* /* IBLOCK_ID = 11 - Каталог (Импорт) /* IBLOCK_ID = 27 - Каталог Плит /* /*****************************************************************************************************************/ AddEventHandler("iblock", "OnAfterIBlockElementAdd", array("onAfterElementCat", "OnAfterIBlockElementAddHandler")); AddEventHandler("iblock", "OnAfterIBlockElementAdd", array("onAfterElementCat", "onAfterImportExcel")); AddEventHandler("iblock", "OnAfterIBlockElementUpdate", array("onAfterElementCat", "onUpdateElemOnSoapLoad")); class onAfterElementCat { function onUpdateElemOnSoapLoad(&$arFields) { //AddMessage2Log("onUpdateElemOnSoapLoad ".print_r($arFields['XML_ID'],true)); // запись результата в файл - отладка // Diag\Debug::writeToFile($arFields['XML_ID'], Diag\Debug::writeToFile($arFields, $varName = "onUpdateElemOnSoapLoad", $fileName = "--onUpdateElemOnSoapLoad--.txt" ); // при добавлении/изменении в "Каталоге плит" if ($arFields['IBLOCK_ID'] == 11) { CModule::IncludeModule("iblock"); CModule::IncludeModule("catalog"); $arSelect = array("ID", "NAME", "PROPERTY_ARTNUMBER"); $arFilter = array("IBLOCK_ID" => 27, "PROPERTY_EDGE_ID" => $arFields['ID'] ); $res = CIBlockElement::GetList(array(), $arFilter, false, array(), $arSelect ); while ($obs = $res->fetch()) { $el = new CIBlockElement; global $USER; $elem_donor['ID'] = $arFields['ID']; $db_price = CPrice::GetList(array(), array("PRODUCT_ID" => $elem_donor['ID'], ) ); while ($ar_price = $db_price->Fetch()) { $arField['PRICE'][] = $ar_price; } foreach ($arField['PRICE'] as $price) { $arPrice = array("PRODUCT_ID" => $obs['ID'], "CATALOG_GROUP_ID" => $price['CATALOG_GROUP_ID'], "PRICE" => $price['PRICE'], "CURRENCY" => $price['CURRENCY'], "BASE" => $price['BASE'] ); $resCurPrice = CPrice::GetList(array(), array("PRODUCT_ID" => $obs['ID'], "CATALOG_GROUP_ID" => $price['CATALOG_GROUP_ID'] ) ); if ($arCurPrice = $resCurPrice->Fetch()) { $ressPrice = CPrice::Update($arCurPrice["ID"], $arPrice); } else { $ressPrice = CPrice::Add($arPrice); } // CPrice::Update($price["ID"], $arPrice); } } } } // создаем обработчик события "OnAfterIBlockElementAdd" function OnAfterIBlockElementAddHandler(&$arFields) { //AddMessage2Log("OnAfterIBlockElementAddHandler ".print_r($arFields,true)); Diag\Debug::writeToFile($arFields, $varName = "onAddElemOnSoapLoad", $fileName = "--onAddElemOnSoapLoad--.txt" ); if ($arFields['IBLOCK_ID'] == 11) { CModule::IncludeModule("iblock"); $arSelect = array("ID", "NAME", "PREVIEW_PICTURE", "PROPERTY_CODE_DEKORA"); $arFilter = array("IBLOCK_ID" => 11, "ID" => $arFields['ID']); $restsa = CIBlockElement::GetList(array(), $arFilter, false, array(), $arSelect); while ($obss = $restsa->fetch()) { $arerest['PREVIEW_PICTURE']=$obss['PREVIEW_PICTURE']; $arerest['PROPERTY_CODE_DEKORA']=$obss['PROPERTY_CODE_DEKORA'][0]; } if (empty($arerest['PREVIEW_PICTURE']) && !empty( $arerest['PROPERTY_CODE_DEKORA'])) { $dir = $_SERVER['DOCUMENT_ROOT'] . '/upload/img_to_load'; $files = scandir($dir, 1); $file = array(); $file2 = array(); foreach ($files as $val) { $value = explode(' ', $val, 2); $strlen = strlen($value[0]); if ($strlen < 3 || $strlen > 4) { continue; } $value1[0] = str_replace("К", "K", "$value[0]"); $value1[0] = str_replace("K", "K", "$value1[0]"); $file[$value1[0]] = $val; $value2[0] = str_replace("K", "К", "$value[0]"); $value2[0] = str_replace("К", "К", "$value2[0]"); $file2[$value2[0]] = $val; } $addPhoto = false; foreach ($file as $key => $val) { if (stristr($arerest['PROPERTY_CODE_DEKORA'], $key) === FALSE) { } else { $addPhoto = true; $path = $val; } } if ($addPhoto == false) { foreach ($file2 as $keys => $vals) { if (stristr($arerest['PROPERTY_CODE_DEKORA'], $keys) === FALSE) { } else { $path = $vals; } } } $arWaterMark = array(array("name" => "watermark", "position" => "bottomright", "type" => "image", "size" => "real", "file" => $_SERVER["DOCUMENT_ROOT"] . "/41efe0f8-1de9-40cc-8456-e42b0fa57089.png", "fill" => "exact", ) ); $sizeimg = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . '/upload/img_to_load/' . $path); $arFile = array("HEIGHT" => $sizeimg[0], "WIDTH" => $sizeimg[1], "SUBDIR" => "img_to_load", "FILE_NAME" => $path, ); $arResizeFile = CFile::ResizeImageGet($arFile, array("width" => $sizeimg[0], 'height' => $sizeimg[1] ), BX_RESIZE_IMAGE_PROPORTIONAL, true, $arWaterMark ); $el = new CIBlockElement; $arLoadProductArray = array("PREVIEW_PICTURE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"].'/'.$arResizeFile['src']), "DETAIL_PICTURE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"].'/'.$arResizeFile['src']), ); $rest = $el->Update($arFields['ID'], $arLoadProductArray); unset($arerest); } } } function onAfterImportExcel(&$arFields) { //AddMessage2Log("onAfterImportExcel ".print_r($arFields,true)); Diag\Debug::writeToFile($arFields, $varName = "onAfterImportExcel", $fileName = "--onAfterImportExcel--.txt" ); $obs['PROPERTY_ARTNUMBER_VALUE'] = explode('.', $arFields['PREVIEW_TEXT']); if ($arFields['IBLOCK_ID'] == 27) { CModule::IncludeModule("iblock"); CModule::IncludeModule("catalog"); $el = new CIBlockElement; global $USER; $arSelect = array("ID", "IBLOCK_ID", "NAME", "PREVIEW_PICTURE", "DETAIL_PICTURE", "DATE_ACTIVE_FROM", "PROPERTY_COLLECTION", "PROPERTY_CODE_DEKORA", "PROPERTY_THICKNESS", "PROPERTY_NAME_DEKOR", "PROPERTY_WIDTH", "PROPERTY_ARTNUMBER" ); $arFilter = array("PROPERTY_ARTNUMBER" => $obs['PROPERTY_ARTNUMBER_VALUE'], "IBLOCK_ID" => 11 ); $res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect ); while ($ob = $res->fetch()) { $elem_donor = $ob; } //PRICE $db_price = CPrice::GetList(array(), array("PRODUCT_ID" => $elem_donor['ID'],) ); while ($ar_price = $db_price->Fetch()) { $arFields['PRICE'][] = $ar_price; } $arLoadProductArray = array("MODIFIED_BY" => $USER->GetID(), // элемент изменен текущим пользователем "IBLOCK_SECTION" => false, // элемент лежит в корне раздела "TYPE" => "TYPE_PRODUCT", ); if (!empty($elem_donor['ID'])) $arLoadProductArray["PROPERTY_VALUES"][216] = $elem_donor['ID']; if (!empty($elem_donor['PROPERTY_COLLECTION_VALUE'])) $arLoadProductArray["PROPERTY_VALUES"][217] = $elem_donor['PROPERTY_COLLECTION_VALUE']; if (!empty($elem_donor['PROPERTY_CODE_DEKORA_VALUE'])) $arLoadProductArray["PROPERTY_VALUES"][218] = $elem_donor['PROPERTY_CODE_DEKORA_VALUE']; if (!empty($elem_donor['PROPERTY_THICKNESS_VALUE']) && !empty($elem_donor['PROPERTY_WIDTH_VALUE'])) $arLoadProductArray["PROPERTY_VALUES"][219] = $elem_donor['PROPERTY_THICKNESS_VALUE'] . 'x' . $elem_donor['PROPERTY_WIDTH_VALUE'] . 'мм'; if (!empty($elem_donor['PROPERTY_NAME_DEKOR_VALUE'])) $arLoadProductArray["PROPERTY_VALUES"][220] = $elem_donor['PROPERTY_NAME_DEKOR_VALUE']; if (!empty($elem_donor['PREVIEW_PICTURE'])) { $arLoadProductArray["PROPERTY_VALUES"][221] = $elem_donor['PREVIEW_PICTURE']; $arLoadProductArrays = array("PREVIEW_PICTURE" => CFile::MakeFileArray($elem_donor['PREVIEW_PICTURE']), "DETAIL_PICTURE" => CFile::MakeFileArray($elem_donor['PREVIEW_PICTURE']), "PREVIEW_TEXT" => '', ); $rest = $el->Update($arFields['ID'], $arLoadProductArrays); } CIBlockElement::SetPropertyValuesEx($arFields['ID'], false, $arLoadProductArray['PROPERTY_VALUES'] ); foreach ($arFields['PRICE'] as $price) { $arPrice = array("PRODUCT_ID" => $arFields['ID'], "CATALOG_GROUP_ID" => $price['CATALOG_GROUP_ID'], "PRICE" => $price['PRICE'], "CURRENCY" => $price['CURRENCY'], "BASE" => $price['BASE'] ); $resCurPrice = CPrice::GetList(array(), array("PRODUCT_ID" => $arFields['ID'], "CATALOG_GROUP_ID" => $price['CATALOG_GROUP_ID'] ) ); if ($arCurPrice = $resCurPrice->Fetch()) { $ressPrice = CPrice::Update($arCurPrice["ID"], $arPrice); } else { $ressPrice = CPrice::Add($arPrice); } // CPrice::Update($price["ID"], $arPrice); } } } } /*****************************************************************************************************************/
[RuntimeException] 
Could not start session because headers have already been sent. "/home/bitrix/www/local/php_interface/include/import.php":1. (0)
/home/bitrix/www/bitrix/modules/main/lib/session/session.php:141
#0: Bitrix\Main\Session\Session->start()
	/home/bitrix/www/bitrix/modules/main/lib/session/kernelsessionproxy.php:42
#1: Bitrix\Main\Session\KernelSessionProxy->start()
	/home/bitrix/www/bitrix/modules/main/include.php:169
#2: require_once(string)
	/home/bitrix/www/bitrix/modules/main/include/prolog_before.php:14
#3: require_once(string)
	/home/bitrix/www/bitrix/modules/main/include/prolog.php:10
#4: require_once(string)
	/home/bitrix/www/bitrix/header.php:1
#5: require(string)
	/home/bitrix/www/catalog/index.php:1
#6: include_once(string)
	/home/bitrix/www/bitrix/modules/main/include/urlrewrite.php:160
#7: include_once(string)
	/home/bitrix/www/bitrix/urlrewrite.php:2
----------