• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/defaultsite.php
  • Класс: BitrixSaleLocationDefaultSiteTable
  • Вызов: DefaultSiteTable::updateMultipleForOwner
static function updateMultipleForOwner($siteId, $locationCodeList = array(), $behaviour = array('REMOVE_ABSENT' => true))
{
	$siteId = static::checkSiteId($siteId);

	if(!is_array($locationCodeList))
		throw new MainSystemException('Code list is not a valid array');

	// throw away duplicates and make index array
	$index = array();
	$locationCodeListTemp = array();
	foreach($locationCodeList as $location)
	{
		$index[$location['LOCATION_CODE']] = true;
		$locationCodeListTemp[$location['LOCATION_CODE']] = $location;
	}
	$locationCodeList = $locationCodeListTemp;

	$res = self::getList(array('filter' => array('SITE_ID' => $siteId)));
	$update = array();
	$delete = array();
	while($item = $res->Fetch())
	{
		if(!isset($index[$item['LOCATION_CODE']]))
			$delete[$item['LOCATION_CODE']] = true;
		else
		{
			unset($index[$item['LOCATION_CODE']]);
			$update[$item['LOCATION_CODE']] = true;
		}
	}

	if($behaviour['REMOVE_ABSENT'])
	{
		foreach($delete as $code => $void)
		{
			$res = self::delete(array('SITE_ID' => $siteId, 'LOCATION_CODE' => $code));
			if(!$res->isSuccess())
				throw new MainSystemException(Loc::getMessage('SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_DELETE_EXCEPTION'));
		}
	}

	foreach($update as $code => $void)
	{
		$res = self::update(array('SITE_ID' => $siteId, 'LOCATION_CODE' => $code), array('SORT' => $locationCodeList[$code]['SORT']));
		if(!$res->isSuccess())
			throw new MainSystemException(Loc::getMessage('SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_UPDATE_EXCEPTION'));
	}

	foreach($index as $code => $void)
	{
		$res = self::add(array(
			'SORT' => $locationCodeList[$code]['SORT'],
			'SITE_ID' => $siteId,
			'LOCATION_CODE' => $code
		));
		if(!$res->isSuccess())
			throw new MainSystemException(Loc::getMessage('SALE_LOCATION_DEFAULTSITE_ENTITY_CANNOT_ADD_EXCEPTION'));
	}

	$GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
}