Your IP : 18.119.117.236
<? require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php");
use Bitrix\Highloadblock\HighloadBlockTable;
use Bitrix\Main\Loader;
use Webprofy\Offersgroup\Message;
use Webprofy\Offersgroup\RelationMain;
use Webprofy\Offersgroup\Settings;
Loader::includeModule('webprofy.offersgroup');
Loader::IncludeModule('highloadblock');
Loader::includeModule('iblock');
Loader::includeModule('catalog');
$iblockID = intval($_POST['IBLOCK_ID']);
if ($iblockID) {
$arCatalog = \CCatalog::GetByID($iblockID);
if (!$arCatalog) {
return Message::sendOneMessage('save_catalog_error');
}
$offersIblockID = $arCatalog['OFFERS_IBLOCK_ID']; // ID предложений
if (!$offersIblockID) {
return Message::sendOneMessage('save_offers_error');
}
$highLoadData = [];
$code = false;
$properties = CIBlockProperty::GetList(Array("sort" => "asc", "name" => "asc"),
Array("ACTIVE" => "Y", "IBLOCK_ID" => $offersIblockID));
while ($prop_fields = $properties->GetNext()) {
//проверяем наличие свойства кода комбинации
if ($prop_fields['CODE'] == 'COMBINATION_CODE') {
$code = true;
}
if ($prop_fields['USER_TYPE'] != 'directory') {
continue;
}
$rsData = HighloadBlockTable::getList(array('filter' => array('TABLE_NAME' => $prop_fields['USER_TYPE_SETTINGS']['TABLE_NAME'])));
if ($arData = $rsData->fetch()) {
$highLoadData[$arData['ID']]['NAME'] = $prop_fields['NAME'];
$highLoadData[$arData['ID']]['CODE'] = $prop_fields['CODE'];
}
}
if (!$code) {
$arFields = Array(
"NAME" => "Код комбинации (служебное)",
"ACTIVE" => "Y",
"SORT" => "1700",
"CODE" => "COMBINATION_CODE",
"PROPERTY_TYPE" => "S",
"IBLOCK_ID" => $offersIblockID,
);
$iblockProps = new \CIBlockProperty;
$PropertyID = $iblockProps->Add($arFields);
}
}
$allRelation = RelationMain::getAllRelation();
$arProperty = [];
if (!empty($allRelation)) {
foreach ($allRelation as $item) {
if ($item['RELATION_CODE'] == 'product') {
continue;
}
$arProperty[$item['RELATION_BITRIX_ID']] = $item;
}
}
$result = false;
$arProductsInfo = RelationMain::getProductsInfo();
$productIblockID = $arProductsInfo['RELATION_BITRIX_ID'];
$arFields = array(
'RELATION_BITRIX_ID' => $iblockID,
'RELATION_NAME' => 'Товары',
'RELATION_TYPE' => 'iblock',
'RELATION_CODE' => 'product',
);
if ($productIblockID) {
if ((intval($productIblockID) != $iblockID)) {
$resDel = RelationMain::deleteRelation($arProductsInfo['ID']);
if ($resDel) {
//Добавить товар в свойства
$result = RelationMain::addRelation($arFields);
}
} else {
$result = true;
}
} else {
//Добавить товар в свойства
$result = RelationMain::addRelation($arFields);
}
if (!empty($highLoadData)) {
//Добавим новые свойства
foreach ($highLoadData as $hlID => $item) {
if ($arProperty[$hlID]) {
unset($arProperty[$hlID]);
} else {
$arFields = array(
'RELATION_BITRIX_ID' => $hlID,
'RELATION_NAME' => $item['NAME'],
'RELATION_TYPE' => 'highload',
'RELATION_CODE' => $item['CODE'],
);
RelationMain::addRelation($arFields);
}
}
}
//Если остались старые свойства, то удалим их
if (!empty($arProperty)) {
foreach ($arProperty as $item) {
RelationMain::deleteRelation($item['ID']);
}
}
if($_POST['offers_type']){
Settings::setOffersType(trim($_POST['offers_type']));
}
return Message::sendOneMessage('saveCatalog', $result);