- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/sectionslist.php
- Класс: BitrixSaleTradingPlatformVkSectionsList
- Вызов: SectionsList::prepareChildsToSave
public function prepareChildsToSave($sectionId)
{
$settings = $this->currSectionSettings;
if (empty($settings))
{
return false;
}
$sections = $this->getSections();
$currParentSettings = $this->mappedSections[$sectionId]['PARAMS']['PARENT_SETTINGS'];
$iblockId = $sections[$sectionId]["IBLOCK_ID"];
$currLeftMargin = intval($sections[$sectionId]["LEFT_MARGIN"]);
$currRightMargin = intval($sections[$sectionId]["RIGHT_MARGIN"]);
$dataToSave = array();
$dataToDelete = array();
// if INHERIT changed to true - set parent settings instead settings of current section
// or if ROOT section, then not enable - delete mapping childs
$needDelete = false;
if ($settings["INHERIT"] || (!$sections[$sectionId]["IBLOCK_SECTION_ID"] && !$settings["ENABLE"]))
{
// if have not parent settings - needed delete childs
if (!$currParentSettings)
{
$needDelete = true;
}
else
{
$settings = $currParentSettings;
}
}
foreach ($sections as $section)
{
// find CHILDS
if (
intval($section["LEFT_MARGIN"]) > $currLeftMargin &&
intval($section["RIGHT_MARGIN"]) < $currRightMargin &&
$section["IBLOCK_ID"] == $iblockId
)
{
// only if childs inherit or empty settings
if ($this->mappedSections[$section["ID"]]["PARAMS"]["INHERIT"] !== false)
{
// get childs to delete
if ($needDelete)
{
$dataToDelete[$section["ID"]] = array(
'VALUE_EXTERNAL' => $settings["VK_CATEGORY"] ? $settings["VK_CATEGORY"] : Vk::VK_CATEGORY_TO_CHANGE,
'VALUE_INTERNAL' => $section["ID"],
);
}
// get childs to add to mapping
else
{
$dataToSave[$section["ID"]] = array(
"VALUE_EXTERNAL" => $settings["VK_CATEGORY"] ? $settings["VK_CATEGORY"] : Vk::VK_CATEGORY_TO_CHANGE,
"VALUE_INTERNAL" => $section["ID"],
"PARAMS" => array(
"INHERIT" => true,
"IBLOCK" => $iblockId,
// save parent settings for get inherit params in future
"PARENT_SETTINGS" => array(
"INHERIT" => false,
"ENABLE" => $settings["ENABLE"] ? true : false,
"TO_ALBUM" => $settings["TO_ALBUM"],
"TO_ALBUM_ALIAS" => $settings["TO_ALBUM_ALIAS"],
"VK_CATEGORY" => $settings["VK_CATEGORY"],
"INCLUDE_CHILDS" => $settings["INCLUDE_CHILDS"] ? true : false,
),
),
);
}
}
else
{
// if we catch first not inherit child - put parent setting (save other values) to them and end cycle
$dataToSave[$section["ID"]] = array(
"VALUE_EXTERNAL" => $this->mappedSections[$section["ID"]]["VK_ID"],
"VALUE_INTERNAL" => $this->mappedSections[$section["ID"]]["BX_ID"],
"PARAMS" => $this->mappedSections[$section["ID"]]["PARAMS"],
);
// add parent settings to child params if parent section not deleted
if (!$needDelete)
{
$dataToSave[$section["ID"]]["PARAMS"]["PARENT_SETTINGS"] = array(
"INHERIT" => false,
"ENABLE" => $settings["ENABLE"] ? true : false,
"TO_ALBUM" => $settings["TO_ALBUM"],
"TO_ALBUM_ALIAS" => $settings["TO_ALBUM_ALIAS"],
"VK_CATEGORY" => $settings["VK_CATEGORY"],
"INCLUDE_CHILDS" => $settings["INCLUDE_CHILDS"] ? true : false,
);
}
else
{
unset($dataToSave[$section["ID"]]["PARAMS"]["PARENT_SETTINGS"]);
}
}
}
}
$result = array();
if (!empty($dataToSave))
{
$result['TO_SAVE'] = $dataToSave;
}
if (!empty($dataToDelete))
{
$result['TO_DELETE'] = $dataToDelete;
}
return $result;
}